Clang 3.1 and C++11 support status

折月煮酒 提交于 2019-11-27 05:42:34

问题


From clang's C++11 support status website, http://clang.llvm.org/cxx_status.html , it says, "Initializer List" and "Lambda Expression" are all supported starting from version 3.1.

However, using LLVM/Clang trunk (3.2), compiling against initializer list and lambda expression will yield error messages.

Does anyone know if Clang >3.1 supports those features?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/10601545/clang-3-1-and-c11-support-status

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