c++: Allow new char[4]{"foo"} [PR77841]
authorMarek Polacek <polacek@redhat.com>
Tue, 1 Sep 2020 15:44:16 +0000 (11:44 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 1 Sep 2020 21:49:20 +0000 (17:49 -0400)
commitb1c59b31ef7adc832405209e9e2a77212284abd7
tree42f54803b37d39309d4637b18e600ded4247e36b
parent10f51543bb81cc953792270b40a9c812049e8b4c
c++: Allow new char[4]{"foo"} [PR77841]

Currently, we allow new char[]{"foo"}, but not new char[4]{"foo"}.
We should accept the latter too: [dcl.init.list]p3.3 says to treat
this as [dcl.init.string].

We were rejecting this code because we never called reshape_init before
the digest_init in build_new_1.  reshape_init handles [dcl.init.string]
by unwrapping the STRING_CST from its enclosing { }, and digest_init
assumes that reshape_init has been called for aggregates anyway, and an
array is an aggregate.

gcc/cp/ChangeLog:

PR c++/77841
* init.c (build_new_1): Call reshape_init.

gcc/testsuite/ChangeLog:

PR c++/77841
* g++.dg/cpp0x/initlist-new4.C: New test.
gcc/cp/init.c
gcc/testsuite/g++.dg/cpp0x/initlist-new4.C [new file with mode: 0644]