https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55227
Will Wray <wjwray at gmail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |wjwray at gmail dot com --- Comment #6 from Will Wray <wjwray at gmail dot com> --- Hit this in implementing P1997 array copy semantics (which generalizes the char-array <- string-literal case to array <- array initialization). Compiler Explorer link https://godbolt.org/z/vednE3bYz The reshape_init_r code that ensadc points to is one problem. The code effectively special-cases the C rule that allows optional braces around a string-literal initializer: A brace-enclosed string-literal initializer has its braces stripped, but then the code does not account at all for nested designators (as a recursive call to reshape_init would or should do). This can be seen in the way that bogus nested designators are ignored: struct C {char a[2];} C y = {{.bogus="y"}}; // Invalid, g++ accepts C z = {{[0]="z"}}; // Invalid, g++ accepts (pedantic warning GNU [0]) (so the 'solution' of adding braces is misleading, non-standard, non-portable). Then, in placing the designator correctly outside the braces, it is not matched with the brace-enclosed initializer (haven't tracked down why yet): C w = {.a={"w"}}; // Valid, g++ rejects designated braced // (gcc C accepts) (other C++ compilers accept) A second problem is that the 'matching' of designator to initializer is brittle even without optional braces; only the exactly-matching char-array type (i.e. and extent) is accepted in an unbraced string literal: C u = {.a="u"}; // Valid, designated char[2] literal for char[2] field C r = {.a=""}; // Valid, g++ rejects designated char[1] for char[2] A workaround is to match the size of the char array by padding with zeros: C r = {.a="\0"}; I've spent over a day trying to isolate the 'matching' issue - could do with assist from a designated-initializer mechanic.