https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90926

            Bug ID: 90926
           Summary: member char array with string literal initializer
                    causes = {} to fail
           Product: gcc
           Version: 7.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: thomgree at cisco dot com
  Target Milestone: ---

minimal example program:

int main()
{
  struct thing
  {
    char str[100] = "foo";
    //char str[100] = {'f', 'o', 'o', '\0'}; // this is fine though
  };

  thing foo;
  foo = {}; // clang will compile this, but gcc won't
}


gcc ./test.cpp -Wall -Wextra -Wpedantic


./test.cpp: In function ‘int main()’:
./test.cpp:11:10: error: no match for ‘operator=’ (operand types are
‘main()::thing’ and ‘<brace-enclosed initializer list>’)
   foo = {}; // clang will compile this, but gcc won't
          ^
./test.cpp:4:10: note: candidate: constexpr main()::thing&
main()::thing::operator=(const main()::thing&)
   struct thing
          ^~~~~
./test.cpp:4:10: note:   no known conversion for argument 1 from
‘<brace-enclosed initializer list>’ to ‘const main()::thing&’
./test.cpp:4:10: note: candidate: constexpr main()::thing&
main()::thing::operator=(main()::thing&&)
./test.cpp:4:10: note:   no known conversion for argument 1 from
‘<brace-enclosed initializer list>’ to ‘main()::thing&&’



According to https://godbolt.org/ this happens on all versions of GCC when
-std=c++14 is used (but not -std=c++11).

Reply via email to