Clang 3.1 and C++11 support status

c++, c++11, clang, llvm

Solution

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.

Problem

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?

Original source