2

Both Clang's documentation and cpp preference list that Clang has supported (most of) C++20 since Clang 10.0, and that one can enable such support with the -std=c++20 flag. However this seems to not be true, as I receive the following message:

clang++ hello_world.cpp -O2 -std=c++20 -o hello_world
error: invalid value 'c++20' in '-std=c++20'
note: use 'c++98' or 'c++03' for 'ISO C++ 1998 with amendments' standard
note: use 'gnu++98' or 'gnu++03' for 'ISO C++ 1998 with amendments and GNU extensions' standard
note: use 'c++11' for 'ISO C++ 2011 with amendments' standard
note: use 'gnu++11' for 'ISO C++ 2011 with amendments and GNU extensions' standard
note: use 'c++14' for 'ISO C++ 2014 with amendments' standard
note: use 'gnu++14' for 'ISO C++ 2014 with amendments and GNU extensions' standard
note: use 'c++17' for 'ISO C++ 2017 with amendments' standard
note: use 'gnu++17' for 'ISO C++ 2017 with amendments and GNU extensions' standard
note: use 'c++2a' for 'Working draft for ISO C++ 2020' standard
note: use 'gnu++2a' for 'Working draft for ISO C++ 2020 with GNU extensions' standard
make: *** [hello_world] Error 1

On one hand, this must clearly be a problem on my end. On the other hand, this directly contradicts the documentation: the clang I have installed is well past v 10.0, its online documentation says it supports C++20 via -std=c++20, yet the CLI message suggests there is no such support.

What am I doing wrong? How can I compile C++20 code with clang?

$ clang++ --version 
Homebrew clang version 15.0.7
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Peek
  • 23
  • 1
  • 4
  • Do you have multiple Clang installations? And did you run both commands (the compilation and the version check) from within the same directory? – Michael Mar 21 '23 at 15:30
  • No repro at my end: I'm using LLVM 15.0.7 on Windows with `clang++ test.c -std=c++20 -O2 -o test.exe` with no issues. – Dai Mar 21 '23 at 15:33
  • @Michael I do have multiple clang installations but my bash profile points to the correct one. I did run both the version check and the compilation command in the same directory, yes – Peek Mar 21 '23 at 16:13
  • Ahh, it seems to work if I enter the command directly into the terminal. I was calling Make before.... – Peek Mar 21 '23 at 16:26
  • 2
    I figured it out. I guess `makefile` does not inherit the current bash session variables. Sorry for wasting your time. – Peek Mar 21 '23 at 16:29
  • 2
    @Peek, add your own answer as a detailed answer to your own question. Others will likely have your problem too. In a few days you can then accept your own answer as the correct answer. Make it detailed enough that anyone can follow it. – Gabriel Staples Mar 21 '23 at 17:04

0 Answers0