How can I use the latest C++ 11 features in Clang? What (sub)set of features is supported?
-
6I added the [tag:c++11] tag here, this question seems likely to generate enough interest in the future that having the extra visibility to C++11 experts up front seems worth it to me -- but if you guys wish to restrict the tag to strictly _language_ issues, please feel free to remove it -- and I'd be curious in knowing about it. Thanks :) – sarnold May 02 '12 at 06:40
2 Answers
You will need clang 3.3 to use the most relevant feature set from C++ 11. Read C++ Support in Clang for the complete list of up-to-date supported features. Clang 3.3 is claimed to be C++11 feature complete.
Clang's command line is gcc-compatible so you have to enable C++11 support via the followinf command-line switch
-std=c++11
There is also a bunch of post-C++11 features (like decltype(auto), member initializers and aggregates) that are supported by Clang 3.3. Use this command line switch to enable them
-std=c++1y
-
2Which makes the point that unfortunately this page is not up-to-date... I'll raise this issue on the list :x – Matthieu M. May 02 '12 at 07:02
-
3It is, but there is a problem that makes it not update cache... so just Ctrl+R and you'll get it. – Klaim May 02 '12 at 08:01
-
7If you are using clang/llvm on Mac, you will also have to add -stdlib=libc++ (besides the -std=c++11 flag) to access most features as they are not available in the old libstdc++. But beware - you will get abi-inconsistencies when passing std-objects to libraries linked with libstdc++ (for example if you use boost that you haven't manually compiled with libc++) – kamjagin Jul 03 '13 at 13:42
-
Is there an option when building clang from source, that can be used to make c++11 enabled by default? – Hossein Feb 03 '20 at 16:31
Here is the always up to date list of features supported by clang:
http://clang.llvm.org/cxx_status.html
To activate C++11, you have to add -std=c++11 in your clang calls, like for gcc. If you use an IDE that is clang-aware or gcc-aware, there is a specific project settings option available to do that.