0

I have a piece of code that does not compile since I started compiling with [c++ language standard] stdcpp20 instead of stdcpp17 in visual studio.

I receive an error

cannot convert from 'initializer list' to 'foo'

Find below a minimal reproduceable exemple.

struct foo {
    foo(const foo&) = default; // comment this line to compile

    char a;
};


int main(int argc, char* argv[])
{
    foo{ 'a' }; // error: cannot convert from 'initializer list' to 'foo'
}

Commenting the copy constructor helps. But I don't understand why and I haven't found it on SO yet.

pepece
  • 360
  • 5
  • 17
  • 1
    @user17732522 I know the program should not compile but for some reason gcc with C++17 compiles it. [Demo](https://godbolt.org/z/84YKdb9EM) – Jason Aug 15 '22 at 12:41
  • 1
    @JasonLiam In C++17 a class with user-declared, but not user-provided, constructor was still aggregate, so the initialization was allowed. – user17732522 Aug 15 '22 at 12:42
  • @user17732522 in the real piece of code, it looks more like `someVector.push_back( {'a'} )` – pepece Aug 15 '22 at 12:43
  • 1
    @pepece Yeah, sorry about the comment. I realized after that you just took _minimal_ example very literal. That doesn't happen often here. – user17732522 Aug 15 '22 at 12:44
  • @user17732522 haha. Just trying to do my best. Thanks – pepece Aug 15 '22 at 12:45

0 Answers0