c++ aggregate initializer g++ bug?

  aggregate-initialization, c++, c++20

I have a problem compiling this simple aggregate named initialization with g++

struct A  {
    int a;
};
struct B {
    int b;
};
struct C {
    A a;
    B b;
};

void fun() {
    A a{0};
    B b {12} ;
    // g++ is OK with this
    C c{  .a=a , .b=b };
    // g++ is OK with this
    C cc{ 0, {12}};
    // msvc, clang accept this but g++ does not
    C ccc{.a=0, .b={12}};
}

g++ complains with error: 'A' has no non-static data member named 'b

Is this a gcc bug ?

Source: Windows Questions C++

LEAVE A COMMENT