Home > Mobile >  Why does list-Initialized object using default constructor compile in gcc9 but not in gcc5.1?
Why does list-Initialized object using default constructor compile in gcc9 but not in gcc5.1?

Time:12-08

Why does following code compiles in gcc9 but not in gcc5.1?

struct AAA {

    int xxx  = 1;
};

int main() {
        AAA p;
        new AAA{p};                                                                                                                                                                                                             
}

Error when compiled with gcc5.1 -

/home/genstor/cpp/test.cpp:11:18: error: cannot convert 'AAA' to 'int' in initialization
         new AAA{p};
                 ^

What have I found so far?

I have seen that using list-initializer for structs where default constructor's is used have some problems compiling in 4.8.1 from here, but couldn't relate it with this as it is 5.1. Any help in understanding this more is appreciated.

CMD: g ~/cpp/test.cpp --std=c 14

Repro link - https://godbolt.org/z/hEz95dq4G

CodePudding user response:

gcc5.2 resolve an issue

which relate to a standard defect reports

I'm not sure why c 11 compiles though. the bug report seems to indicate it would not compile either.

  • Related