Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

clang++ unable to recognize 'nullptr' without flag

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Does anyone else have this issue with the latest version of clang?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading