Consider the following code:
//--------------------------------------------------------
#include <initializer_list>
struct A { int x, y; };
struct B { int x, y; std::initializer_list<int> l; };
struct Test
{
A a; B b;
constexpr Test(const A& ia): a(ia), b{0,0,{}} {}
constexpr Test(const B& ib): a{0,0}, b(ib) {}
};
constexpr B kB { 1, 2, { 1, 2, 3 } };
constexpr Test kTest1 = A { 5, 10 };
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
int main() {}
//--------------------------------------------------------
It compiles with gcc, but not with clang. The latter says:
//--------------------------------------------------------
test.cc:16:16: error: constexpr variable 'kTest2' must be initialized by a
constant expression
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cc:16:16: note: pointer to subobject of temporary is not a constant
expression
test.cc:16:36: note: temporary created here
constexpr Test kTest2 = B { 5, 10, { 1, 2, 3 } };
^
//--------------------------------------------------------
Which one is right?
--- news://
freenews.netfront.net/ - complaints:
ne...@netfront.net ---