c++: Don't allow designated initializers with non-aggregates [PR95369]
authorMarek Polacek <polacek@redhat.com>
Mon, 15 Jun 2020 19:31:32 +0000 (15:31 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 16 Jun 2020 17:19:44 +0000 (13:19 -0400)
commit04afaf4575ff239279cfa34aff17101345451965
treed091dc21ff9341deebe58246a414828e44ccb56d
parent2661635323bd44410f1a154683eccecd2c163b46
c++: Don't allow designated initializers with non-aggregates [PR95369]

Another part of 95369 is that we accept designated initializers with
non-aggregate types.  That seems to be wrong since they're part of
aggregate initialization.  clang/icc also reject it.

There are multiple contexts where we can use designated initializers:
function-like casts, member list initializers, NTTP, etc.  I've adjusted
add_list_candidates and implicit_conversion_error in order to to detect
this case.

gcc/cp/ChangeLog:

PR c++/95369
* call.c (add_list_candidates): Return if a designated initializer
is used with a non-aggregate.
(implicit_conversion_error): Give an error for the case above.

gcc/testsuite/ChangeLog:

PR c++/95369
* g++.dg/cpp2a/desig11.C: Adjust dg-error.
* g++.dg/cpp2a/desig16.C: New test.
gcc/cp/call.c
gcc/testsuite/g++.dg/cpp2a/desig11.C
gcc/testsuite/g++.dg/cpp2a/desig16.C [new file with mode: 0644]