A comparison of C++11 language support in VS2012, g++ 4.7 and Clang 3.1
If you need an excuse for celebration, today happens to be an anniversary! The C++11 standard was approved by ISO on 12 August last year, exactly one year ago. I decided to take a look at the state of C++11 language support one year on across three compilers: the upcoming VS11 (Visual Studio 2012), g++ 4.7 and Clang 3.1.
Please note I didn’t detail the non-language concurrency changes. Generally, support for those remains limited.
Feature | VS11 | g++ 4.7 | Clang 3.1 |
---|---|---|---|
auto | Yes | Yes | Yes |
decltype | Yes | Yes | Yes |
Rvalue references and move semantics | Yes | Yes | Yes |
Lambda expressions | Yes | Yes | Yes |
nullptr | Yes | Yes | Yes |
static_assert | Yes | Yes | Yes |
Range based for loop | Yes | Yes | Yes |
Trailing return type in functions | Yes | Yes | Yes |
final method keyword | Yes | Yes | Yes |
override method keyword | Yes | Yes | Yes |
Strongly typed enums | Yes | Yes | Yes |
Forward declared enums | Yes | Yes | Yes |
extern templates | Yes | Yes | Yes |
>> for nested templates | Yes | Yes | Yes |
Local and unnamed types as template arguments | Yes | Yes | Yes |
Variadic macros | Yes | Yes | Yes |
New built-in types | Partial | Yes | Yes |
Initializer lists | No | Yes | Yes |
explicit type conversion operators | No | Yes | Yes |
Inline namespaces | No | Yes | Yes |
sizeof on non-static data members without an instance | No | Yes | Yes |
Changed restrictions on union members | No | Yes | Yes |
Raw string literals | No | Yes | Yes |
User defined literals | No | Yes | Yes |
Encoding support in literals | No | Yes | Yes |
Arbitrary expressions in template deduction contexts | No | Yes | Yes |
Defaulted methods | No | Yes | Yes |
Deleted methods | No | Yes | Yes |
Non-static data member initializers | No | Yes | Yes |
Variadic templates | No | Yes | Yes |
Default template arguments in function templates | No | Yes | Yes |
Template aliases | No | Yes | Yes |
Forwarding constructors | No | Yes | Yes |
noexcept | No | Yes | Yes |
constexpr | No | Yes | Yes |
Alignment support | Partial | No | Yes |
Rvalue references for *this | No | No | Yes |
C99 compatibility | Partial | Partial | Partial |
Thread local storage | Partial | Partial | No |
Inheriting constructors | No | No | No |
Generalized attributes | No | No | No |
Clang is leading with the most C++11 features implemented, and Visual Studio is unfortunately lagging behind. Still, there is a decent subset of features already available for cross-platform development using these three compilers.
You can use type inference, move semantics and rvalue references, nullptr, static_assert, and range-based for loop.
You can have finer control over inheritance using final and override keywords. Enums can be strongly typed and forward declared. There are several improvements to templates, including the extern keyword.
Sadly, the much requested variadic templates aren’t available in Visual Studio. Variadic macros, on the other hand, are implemented in all three compilers for C99 compatibility.
The features that aren’t implemented anywhere are inheriting constructors and generalized attributes. Thread local storage is at best partially supported (via non-standard keywords).
Overall, I think this represents good progress and shows that at least a subset of C++11 can be used today for cross-platform projects.
Keen on mastering C++11/14? I've written books focused on C++11/14 features. You can get a VS2013, Clang or a GCC edition.