mercredi 25 mars 2015

Initialization of static constexpr member array in gcc 4.8

The following code compiles and runs in gcc 4.9.1 and clang-3.6 when using -std=c++11.



struct Bar
{
int x;
};

struct Foo
{
static constexpr Bar bars[] = {1, 2, 3};
};

constexpr Bar Foo::bars[];


However, it fails in gcc 4.8.1, resulting in the error message



./cpptest.cpp:14:43: error: could not convert '1' from 'int' to 'const Bar'
static constexpr Bar bars[] = {1, 2, 3};
^
./cpptest.cpp:14:43: error: could not convert '2' from 'int' to 'const Bar'
./cpptest.cpp:14:43: error: could not convert '3' from 'int' to 'const Bar'


Incidentally, if I do the same thing but make bars a static const global array, it compiles fine in gcc 4.8 and clang. It will also compile just fine if I surround each of the integer literals in the list with an extra pair of {}.


So is this a bug in gcc 4.8? What does the standard say is the appropriate syntax for this? What part of the c++11 uniform initialization standard is being invoked when I omit the extra braces?


Aucun commentaire:

Enregistrer un commentaire