In GCC 4.6.1, when I declare an instance of my own type that has a default constructor, and if I instantiate an object of this type and initialize it with curly braces (for example, Foo my_foo {};), the POD members in this class there will only be zero initialization unless another constructor is declared. If there is no constructor other than the default one, it will be null as expected.
But, in GCC 4.7.3, zero initialization happens anyway, this is the behavior I was expecting.
What is the difference here? Is this a compiler error? Both versions of GCC support standard C ++ 11 standard constructors.
There is no real need to stick with older versions of GCC, but I would like to understand what is going on here.
note: I do not execute the main ctor, op =. and copy ctor just to save the type that can be used with variational functions (clang requires that it classify the class as POD, although gcc allowed me to leave using the variational type even with user-defined basic game points, if you can tell me why.)
Here is an example program to illustrate, including some output below (from binaries compiled in both versions of GCC):
#include <cstdio> // pod and pod_wctor are identical except that pod_wctor defines another ctor struct pod { pod( void ) = default; pod( const pod& other ) = default; pod& operator=( const pod& other ) = default; int x,y,z; }; struct pod_wctor { pod_wctor( void ) = default; pod_wctor( const int setx, const int sety, const int setz ) : x(setx), y(sety), z(setz) { } pod_wctor( const pod_wctor& other ) = default; pod_wctor& operator=( const pod_wctor& other ) = default; int x,y,z; }; int main ( void ) { printf("the following shuold be uninitialized:\n"); pod pee; printf( " %i,%i,%i\n", pee.x, pee.y, pee.z); pod_wctor podtor; printf( " %i,%i,%i\n", podtor.x, podtor.y, podtor.z); printf("the following shuold be initialized to 0,0,0:\n"); pod peenit{}; printf( " %i,%i,%i\n", peenit.x, peenit.y, peenit.z ); pod_wctor podtornit{}; printf( " %i,%i,%i\n", podtornit.x, podtornit.y, podtornit.z ); return 0; } // compiled with: g++ m.cpp -std=gnu++0x // g++ (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1 (i386) /****************** output ******************* the following shuold be uninitialized: 10381592,134513249,134520820 134513969,134513504,0 the following shuold be initialized to 0,0,0: 0,0,0 7367877,134513945,8724468 *********************************************/ // compiled with: g++ m.cpp -std=gnu++0x // gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-2ubuntu4) (i386) /****************** output ******************* the following shuold be uninitialized: -1218358300,-1217268232,134520832 134514450,1,-1079827548 the following shuold be initialized to 0,0,0: 0,0,0 0,0,0 *********************************************/