c++: designated init of char array by string constant [PR55227]
authorWill Wray <wjwray@gmail.com>
Sat, 15 Jan 2022 00:28:53 +0000 (19:28 -0500)
committerJason Merrill <jason@redhat.com>
Sun, 23 Jan 2022 22:27:06 +0000 (17:27 -0500)
commit2da90ad39bf8fa9ee287e040d1f4411cb7a2e7ed
tree8fe11cd45aa5875095a1ddc94a86e8df6c4dd5c6
parentcbcf4a50fa21abd7a4a50a7ce47ada80b115febc
c++: designated init of char array by string constant [PR55227]

There are two underlying bugs in the designated initialization of char array
fields by string literals that cause:

(1) Rejection of valid cases with:
  (a) brace-enclosed string literal initializer (of any valid size), or
  (b) unbraced string literal shorter than the target char array field.

(2) Acceptance of invalid cases with designators appearing within the braces
    of a braced string literal, in which case the bogus 'designator' was
    being entirely ignored and the string literal treated as a positional
    initializer.

The fixes above allow to address a FIXME in cp_complete_array_type:

  /* FIXME: this code is duplicated from reshape_init.
     Probably we should just call reshape_init here?  */

I believe that this was obstructed by the designator bugs (see comment here
https://patchwork.ozlabs.org/project/gcc/list/?series=199783)

PR c++/55227

gcc/cp/ChangeLog:

* decl.cc (reshape_init_r): Only call has_designator_check when
first_initializer_p or for the inner constructor element.
(cp_complete_array_type): Call reshape_init on braced-init-list.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/desig21.C: New test.
gcc/cp/decl.cc
gcc/testsuite/g++.dg/cpp2a/desig21.C [new file with mode: 0644]