GCC 4.7.2

Here wizards, magicians, sorcerers and everybody can rest a bit and talk about anything they like.

Just remember to respect the rules.

GCC 4.7.2

Postby mmix » Sep 22nd, '12, 01:23

http://gcc.gnu.org/gcc-4.7/

C family

A new built-in, __builtin_assume_aligned, has been added, through which the compiler can be hinted about pointer alignment and can use it to improve generated code.
A new -Wunused-local-typedefs warning was added for C, C++, Objective-C and Objective-C++. This warning diagnoses typedefs locally defined in a function, and otherwise not used.
A new experimental -ftrack-macro-expansion option was added for C, C++, Objective-C, Objective-C++ and Fortran. It allows the compiler to emit diagnostic about the current macro expansion stack when a compilation error occurs in a macro expansion.

Experimental support for transactional memory has been added. It includes support in the compiler, as well as a supporting runtime library called libitm. To compile code with transactional memory constructs, use the -fgnu-tm option.

Support is currently available for Alpha, ARM, PowerPC, SH, SPARC, and 32-bit/64-bit x86 platforms.

For more details on transactional memory see the GCC WiKi.

Support for atomic operations specifying the C++11/C11 memory model has been added. These new __atomic routines replace the existing __sync built-in routines.

Atomic support is also available for memory blocks. Lock-free instructions will be used if a memory block is the same size and alignment as a supported integer type. Atomic operations which do not have lock-free support are left as function calls. A set of library functions is available on the GCC atomic wiki in the "External Atomics Library" section.

For more details on the memory models and features, see the atomic wiki.
When a binary operation is performed on vector types and one of the operands is a uniform vector, it is possible to replace the vector with the generating element. For example:

typedef int v4si __attribute__ ((vector_size (16)));
v4si res, a = {1,2,3,4};
int x;

res = 2 + a; /* means {2,2,2,2} + a */
res = a - x; /* means a - {x,x,x,x} */


C

There is support for some more features from the C11 revision of the ISO C standard. GCC now accepts the options -std=c11 and -std=gnu11, in addition to the previous -std=c1x and -std=gnu1x.
Unicode strings (previously supported only with options such as -std=gnu11, now supported with -std=c11), and the predefined macros __STDC_UTF_16__ and __STDC_UTF_32__.
Nonreturning functions (_Noreturn and <stdnoreturn.h>).
Alignment support (_Alignas, _Alignof, max_align_t, <stdalign.h>).
A built-in function __builtin_complex is provided to support C library implementation of the CMPLX family of macros.

C++

G++ now accepts the -std=c++11, -std=gnu++11, and -Wc++11-compat options, which are equivalent to -std=c++0x, -std=gnu++0x, and -Wc++0x-compat, respectively.
G++ now implements C++11 extended friend syntax:

template<class W>
class Q
{
static const int I = 2;
public:
friend W;
};

struct B
{
int ar[Q<B>::I];
};

Thanks to Ville Voutilainen, G++ now implements C++11 explicit override control.

struct B {
virtual void f() const final;
virtual void f(int);
};

struct D : B {
void f() const; // error: D::f attempts to override final B::f
void f(long) override; // error: doesn't override anything
void f(int) override; // ok
};

struct E final { };
struct F: E { }; // error: deriving from final class

G++ now implements C++11 non-static data member initializers.

struct A {
int i = 42;
} a; // initializes a.i to 42

Thanks to Ed Smith-Rowland, G++ now implements C++11 user-defined literals.

// Not actually a good approximation. :)
constexpr long double operator"" _degrees (long double d) { return d * 0.0175; }
long double pi = 180.0_degrees;

G++ now implements C++11 alias-declarations.

template <class T> using Ptr = T*;
Ptr<int> ip; // decltype(ip) is int*

Thanks to Ville Voutilainen and Pedro Lamarão, G++ now implements C++11 delegating constructors.

struct A {
A(int);
A(): A(42) { } // delegate to the A(int) constructor
};

G++ now fully implements C++11 atomic classes rather than just integer derived classes.

class POD {
int a;
int b;
};
std::atomic<POD> my_atomic_POD;

G++ now sets the predefined macro __cplusplus to the correct value, 199711L for C++98/03, and 201103L for C++11.
G++ now correctly implements the two-phase lookup rules such that an unqualified name used in a template must have an appropriate declaration found either in scope at the point of definition of the template or by argument-dependent lookup at the point of instantiation. As a result, code that relies on a second unqualified lookup at the point of instantiation to find functions declared after the template or in dependent bases will be rejected. The compiler will suggest ways to fix affected code, and using the -fpermissive compiler flag will allow the code to compile with a warning.

template <class T>
void f() { g(T()); } // error, g(int) not found by argument-dependent lookup
void g(int) { } // fix by moving this declaration before the declaration of f

template <class T>
struct A: T {
// error, B::g(B) not found by argument-dependent lookup
void f() { g(T()); } // fix by using this->g or A::g
};

struct B { void g(B); };

int main()
{
f<int>();
A<B>().f();
}

G++ now properly re-uses stack space allocated for temporary objects when their lifetime ends, which can significantly lower stack consumption for some C++ functions. As a result of this, some code with undefined behavior will now break:

const int &f(const int &i) { return i; }
....
const int &x = f(1);
const int &y = f(2);

Here, x refers to the temporary allocated to hold the 1 argument, which only lives until the end of the initialization; it immediately becomes a dangling reference. So the next statement re-uses the stack slot to hold the 2 argument, and users of x get that value instead.

Note that this should not cause any change of behavior for temporaries of types with non-trivial destructors, as they are already destroyed at end of full-expression; the change is that now the storage is released as well.
A new command-line option -Wdelete-non-virtual-dtor has been added to warn when delete is used to destroy an instance of a class which has virtual functions and non-virtual destructor. It is unsafe to delete an instance of a derived class through a pointer to a base class if the base class does not have a virtual destructor. This warning is enabled by -Wall.
A new command-line option -Wzero-as-null-pointer-constant has been added to warn when a literal '0' is used as null pointer constant. It can be useful to facilitate the conversion to nullptr in C++11.
As per C++98, access-declarations are now deprecated by G++. Using-declarations are to be used instead. Furthermore, some efforts have been made to improve the support of class scope using-declarations. In particular, using-declarations referring to a dependent type now work as expected (bug c++/14258).
The ELF symbol visibility of a template instantiation is now properly constrained by the visibility of its template arguments (bug c++/35688).

mmix
 
Posts: 110
Joined: Jun 24th, '12, 05:35

Return to The Wizards Lair

Who is online

Users browsing this forum: No registered users and 1 guest

cron