GCC 4.9.0 发布,此版本是个主要版本更新,包括了 GCC 4.8.x 系列和之前的 GCC 版本都没有的新特性,新特性非常之多。
警告
移除 mudflap 运行时检查器,mudflap 选项保留,但没有任何效果.
对一些很多老的系统和一些不维护的平台的支持在 4.9 版本中声明为过世的,下一个版本将永久删除,例如 Solaris 9
更多移植到 GCC 4.9 的信息请参考 移植指南
一般优化器改进
AddressSanitizer, a fast memory error detector, is now available on ARM.
UndefinedBehaviorSanitizer (ubsan), a fast undefined behavior detector, has been added and can be enabled via -fsanitize=undefined. Various computations will be instrumented to detect undefined behavior at runtime. UndefinedBehaviorSanitizer is currently available for the C and C++ languages.
Link-time optimization (LTO) improvements:Memory usage building Firefox with debug enabled was reduced from 15GB to 3.5GB; link time from 1700 seconds to 350 seconds.
■
Type merging was rewritten. The new implementation is significantly faster and uses less memory.
■
Better partitioning algorithm resulting in less streaming during link time.
■
Early removal of virtual methods reduces the size of object files and improves link-time memory usage and compile time.
■
Function bodies are now loaded on-demand and released early improving overall memory usage at link time.
■
C++ hidden keyed methods can now be optimized out.
■
When using a linker plugin, compiling with the -flto option now generates slim objects files (.o) which only contain intermediate language representation for LTO. Use -ffat-lto-objects to create files which contain additionally the object code. To generate static libraries suitable for LTO processing, use gcc-ar and gcc-ranlib; to list symbols from a slim object file use gcc-nm. (Requires that ar, ranlib and nm have been compiled with plugin support.)
Inter-procedural optimization improvements:
■
New type inheritance analysis module improving devirtualization. Devirtualization now takes into account anonymous name-spaces and the C++11 final keyword.
■
New speculative devirtualization pass (controlled by -fdevirtualize-speculatively.
■
Calls that were speculatively made direct are turned back to indirect where direct call is not cheaper.
■
Local aliases are introduced for symbols that are known to be semantically equivalent across shared libraries improving dynamic linking times.
Feedback directed optimization improvements:
■
Profiling of programs using C++ inline functions is now more reliable.
■
New time profiling determines typical order in which functions are executed.
■
A new function reordering pass (controlled by -freorder-functions) significantly reduces startup time of large applications. Until binutils support is completed, it is effective only with link-time optimization.
■
Feedback driven indirect call removal and devirtualization now handle cross-module calls when link-time optimization is enabled.
新语言和语音特性改进
Version 4.0 of the OpenMP specification is now supported for the C and C++ compilers. The new -fopenmp-simd option can be used to enable OpenMP's SIMD directives, while ignoring other OpenMP directives. The new -fsimd-cost-model= option permits to tune the vectorization cost model for loops annotated with OpenMP and Cilk Plus simd directives; -Wopenmp-simd warns when the current costmodel overrides simd directives set by the user.
The -Wdate-time option has been added for the C, C++ and Fortran compilers, which warns when the __DATE__, __TIME__ or __TIMESTAMP__ macros are used. Those macros might prevent bit-wise-identical reproducible compilations.
Ada
GNAT switched to Ada 2012 instead of Ada 2005 by default.
C family
Support for colorizing diagnostics emitted by GCC has been added. The -fdiagnostics-color=auto will enable it when outputting to terminals, -fdiagnostics-color=always unconditionally. The GCC_COLORS environment variable can be used to customize the colors or disable coloring. If GCC_COLORS variable is present in the environment, the default is -fdiagnostics-color=auto, otherwise -fdiagnostics-color=never.
Sample diagnostics output:
$ g++ -fdiagnostics-color=always -S -Wall test.C test.C: In function ‘int foo()’: test.C:1:14: warning: no return statement in function returning non-void [-Wreturn-type]
int foo () { } ^
test.C:2:46: error: template instantiation depth exceeds maximum of 900 (use -ftemplate-depth= to increase the maximum) instantiating ‘struct X<100>’
template
struct X { static const int value = X::value; }; template struct X<1000>; ^
test.C:2:46: recursively required from ‘const int X<999>::value’ test.C:2:46: required from ‘const int X<1000>::value’ test.C:2:88: required from here test.C:2:46: error: incomplete type ‘X<100>’ used in nested name specifier
With the new #pragma GCC ivdep, the user can assert that there are no loop-carried dependencies which would prevent concurrent execution of consecutive iterations using SIMD (single instruction multiple data) instructions.
Support for Cilk Plus has been added and can be enabled with the -fcilkplus option. Cilk Plus is an extension to the C and C++ languages to support data and task parallelism. The present implementation follows ABI version 1.2; all features but _Cilk_for have been implemented.
C
ISO C11 atomics (the _Atomic type specifier and qualifier and the header) are now supported.
ISO C11 generic selections (_Generic keyword) are now supported.
ISO C11 thread-local storage (_Thread_local, similar to GNU C __thread) is now supported.
ISO C11 support is now at a similar level of completeness to ISO C99 support: substantially complete modulo bugs, extended identifiers (supported except for corner cases when -fextended-identifiers is used), floating-point issues (mainly but not entirely relating to optional C99 features from Annexes F and G) and the optional Annexes K (Bounds-checking interfaces) and L (Analyzability).
A new C extension __auto_type provides a subset of the functionality of C++11 auto in GNU C.
C++
The G++ implementation of C++1y return type deduction for normal functions has been updated to conform to N3638, the proposal accepted into the working paper. Most notably, it adds decltype(auto) for getting decltype semantics rather than the template argument deduction semantics of plain auto:
int& f();
auto i1 = f(); // int
decltype(auto) i2 = f(); // int&
G++ supports C++1y lambda capture initializers:
[x = 42]{ ... };
Actually, they have been accepted since GCC 4.5, but now the compiler doesn't warn about them with -std=c++1y, and supports parenthesized and brace-enclosed initializers as well.
G++ supports C++1y variable length arrays. G++ has supported GNU/C99-style VLAs for a long time, but now additionally supports initializers and lambda capture by reference. In C++1y mode G++ will complain about VLA uses that are not permitted by the draft standard, such as forming a pointer to VLA type or applying sizeof to a VLA variable. Note that it now appears that VLAs will not be part of C++14, but will be part of a separate document and then perhaps C++17.
void f(int n) {
int a[n] = { 1, 2, 3 }; // throws std::bad_array_length if n < 3
[&a]{ for (int i : a) { cout << i << endl; } }();
&a; // error, taking address of VLA
}
G++ supports the C++1y [[deprecated]] attribute modulo bugs in the underlying [[gnu::deprecated]] attribute. Classes and functions can be marked deprecated and a diagnostic message added:
class A;
int bar(int n);
#if __cplusplus > 201103
class [[deprecated("A is deprecated in C++14; Use B instead")]] A;
[[deprecated("bar is unsafe; use foo() instead")]]
int bar(int n);
int foo(int n);
class B;
#endif
A aa; // warning: 'A' is deprecated : A is deprecated in C++14; Use B instead
int j = bar(2); // warning: 'int bar(int)' is deprecated : bar is unsafe; use foo() instead
G++ supports C++1y digit separators. Long numeric literals can be subdivided with a single quote ' to enhance readability:
int i = 1048576;
int j = 1'048'576;
int k = 0x10'0000;
int m = 0'004'000'000;
int n = 0b0001'0000'0000'0000'0000'0000;
double x = 1.602'176'565e-19;
double y = 1.602'176'565e-1'9;
G++ supports C++1y polymorphic lambdas.
// a functional object that will increment any type
auto incr = [](auto x) { return x++; };
Runtime Library (libstdc++)
Improved support for C++11, including:
■
support for ;
■
The associative containers in