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