]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Handle RANGE_EXPR index in init_subob_ctx [PR97328]
authorPatrick Palka <ppalka@redhat.com>
Thu, 22 Oct 2020 11:40:40 +0000 (07:40 -0400)
committerPatrick Palka <ppalka@redhat.com>
Thu, 22 Oct 2020 16:19:39 +0000 (12:19 -0400)
commit8094f781c35b64da68245d351b85546cca5b809b
tree606a4048f5ab8649c3d0c8951e5ec2ef3301d908
parent523e6e5bd47bcc03e9782039b52fb3f8b3276e64
c++: Handle RANGE_EXPR index in init_subob_ctx [PR97328]

In the testcase below, we're ICEing during constexpr evaluation of the
CONSTRUCTOR {.data={{}, [1 ... 7]={}}} of type 'vector'.  The interesting
thing about this CONSTRUCTOR is that it has a RANGE_EXPR index for an
element initializer which doesn't satisfy reduced_constant_expression_p
(because the field 't' is uninitialized).

This is a problem because init_subob_ctx currently punts on setting up a
sub-aggregate initialization context when given a RANGE_EXPR index, so
we later trip over the asserts in verify_ctor_sanity when recursing into
cxx_eval_bare_aggregate on this element initializer.

Fix this by making init_subob_ctx set up an appropriate initialization
context when supplied a RANGE_EXPR index.

gcc/cp/ChangeLog:

PR c++/97328
* constexpr.c (init_subob_ctx): Don't punt on RANGE_EXPR
indexes, instead build a sub-aggregate initialization context
with no subobject.

gcc/testsuite/ChangeLog:

PR c++/97328
* g++.dg/cpp2a/constexpr-init19.C: New test.
* g++.dg/cpp2a/constexpr-init20.C: New test.

(cherry picked from commit 3d423c6f6a69d87ad52ba3af75f3debd8a8b8810)
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp2a/constexpr-init19.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-init20.C [new file with mode: 0644]