c++11 warning on MacOS

Viewed 303

I have clang 13.0.0 on my Mac. I'm trying to compile some .cpp files using the command

g++ file.cpp -o file

But I get this warning message:

file.cpp:23:26: warning: range-based for loop is a C++11 extension [-Wc++11-extensions]
    for (const double &e : timestamp) outFile << std::setprecision(10) << e << "\n";

On the clang documentation is said that c++11 is supported by clang 13. On my terminal running man clang I find: The default C++ language standard is gnu++14.

Typing g++ -v I get:

Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 13.0.0 (clang-1300.0.29.3)
Target: arm64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

Why am I getting this warning?

1 Answers

AppleClang defaults to c++98, whereas llvm-clang defaults to the later gnu++14; to access the c++11 implementation, you must add the flag, --std=c++11 or --std=c++14. cf. https://opensource.apple.com/source/clang/clang-703.0.29/src/tools/clang/www/cxx_status.html

If you are expecting the gnu g++, it must be installed separately, because on macOS g++ aliases to clang, which is the Apple fork of clang known as AppleClang.

If you were expecting llvm-clang, that also must be separately installed. AppleClang 13 ≠ llvm-clang 13.

Related