I am running:
Apple clang version 14.0.0 (clang-1400.0.29.202)
Target: x86_64-apple-darwin22.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
when I run: clang++ *.cpp -o test
, I get:
identifier = nullptr;
^
1 error generated.
however, when I run: clang++ -std=c++11 *.cpp -o test
, I get no errors.
Does anyone else have this issue with the latest version of clang?
Whoever set the duplicate flag, this is not a duplicate. I had made the reasonable assumption that the latest version of clang wouldn't be running C++98 by default. Also, the linked post is from 10 years ago, when C++11 got released...
Apple clang++ 14.0.0 defaults to C++98.
For example with this source file:
long version = __cplusplus;
void *p = nullptr;
You can see this behavior:
$ clang++ -E nullptr.cpp | grep -v '^#'
long version = 199711L;
void *p = nullptr;
$ clang++ -c nullptr.cpp
nullptr.cpp:2:11: error: use of undeclared identifier 'nullptr'
void *p = nullptr;
^
1 error generated.
$ clang++ -c -std=c++11 nullptr.cpp
The solution is to explicitly request a language standard of C++11 or newer via -std=c++XY
, as shown above.