Migration to C++11
|Reported by:||Yves||Owned by:|
|Priority:||Should Have||Milestone:||Alpha 18|
Description (last modified by )
For discussions and opinions, please refer to the forum thread here.
C++ is the next version of the C++ standard after C++98 and C++03. There's already C++14, but that's currently out of scope because it's definitely too early for that. This standard introduces many new features and addresses shortcomings of the language. C++11 still supports all features of the earlier C++ standards (with very few exceptions) and if the compiler supports it, it can be enabled for existing code by passing an argument to the compiler (no code changes required).
The C++11 standard consists of many new features that have to be supported by the compiler. Some of the features are more widely supported by older compilers and others would require newer compilers. In addition to saying yes or no to C++11, we also have to define which features we want to support and, as a consequence, which compiler versions we support.
As a reference, check Mozilla's C++11 guideline (draft).
For more information about C++11 refer to:
- Bjarne Stroustrup's C++11 FAQ
- This video for a short introduction
- This video for an in depth presentation of the evolution of C++ and the "new" C++11
There's not really a decision if we want to switch to C++11 or not, it's more a decision if we want to switch now or later. As far as I know, C++11 will become mandatory at some point and it won't be possible anymore to switch it on or off. If we decide to switch now, we have to agree which subset of features we want to use and which ones not. Such a decision should probably be based on how well the features are supported by compilers and which versions of compilers we need to support.
Links for supported features
Some information on support for C++11 features in different compilers:
- Apache wiki: C++11 compiler support (different compilers)
- C++11 support for GCC
- C++11 support for Visual Studio
Pro/Contra of C++11
- Improved performance (probably 1-3% when just enabling c++11 without additional changes. Depending on compiler and measuring conditions.). Additional improvements are possible by using the new language features correctly (like move constructors, improved template functionality, constexpr and others).
- New standard was developed to improve shortcomings of C++ --> Provides better solutions in some cases (better error handling, improved maintainability, compile-time checks instead of runtime checks, style improvements etc.).
- Allows us to use libraries that require C++11.
- Requires programmers to understand the new C++ features
- Requires additional care to avoid using features that are not supported as defined in our coding guidelines --> Could break compilation on other compilers
- Although the new standard aims for improving the style of code, the mix of old code and new code and the additional possibilities could make it worse (hard to tell at this point)
- Requires us to drop support for some versions of compilers
- SpiderMonkey 31 requires C++11 support
- WxWidgets 3 requires C++11 according to #2452, but it looks like that's not confirmed
What we have to do for the migration
- Create a new Autobuilder with C++11 support. The current one uses Visual Studio 2008 and will have to be replaced at some point anyway.
- Specifying "C++11 supported features" table
- Trivial change in premake4.lua
- The ABI should be compatible in most cases and it should not be required to rebuild all Windows Binaries as far as I understand.