Clang 3.1 and C++11 support status

天大地大妈咪最大 提交于 2019-11-28 06:51:34

By default, clang++ will not enable the C++11 features - you have to pass an additional flag during compilation.

clang++ -std=c++11 [input files...]

Or

# enables some additional C++11 extensions GCC has
clang++ -std=gnu++11 [input files...] 

Additionally, you can switch between using libstdc++ and Clang's own libc++, which are different implementations of the C++ standard library. libc++ in some cases might have a better implementation of the C++11 standard than your existing libstdc++ library.

# uses clang's C++ library in C++98 mode
clang++ -stdlib=libc++ [input] # uses clang's C++ library

# uses clang's C++ library and enables C++11 mode
clang++ -stdlib=libc++ -std=c++11 [input] 

The latter is important if you're using Clang in an environment with an outdated version of libstdc++ (like Mac OSX), but note that the two C++ libraries are not compatible with each other, so you would have to rebuild any dependencies against libc++ if you were to use that.

The page at http://clang.llvm.org/cxx_status.html is confusing at best. Currently, the released 3.1 version does not support initializer lists or lambdas (so I've switched back to GCC 4.8 for the time being).

You can always check clang support for features using the __has__feature macro, according to the instructions here:

http://clang.llvm.org/docs/LanguageExtensions.html#checking_language_features

For example, __has_feature(cxx_generalized_initializers) or __has_feature(cxx_lambdas) will return true if those features are available and enabled.

Personally, I'm expecting those features to be ready by clang 4.0, which is expected to be released with the next Xcode (likely June 2012).

-- Edited to clarify the versions I've been testing -- clearly, clang versioning is more complex than I had realized.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!