]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: Fix verify_ctor_sanity ICE [PR96241]
authorMarek Polacek <polacek@redhat.com>
Thu, 15 Oct 2020 20:10:45 +0000 (16:10 -0400)
committerMarek Polacek <polacek@redhat.com>
Sat, 24 Oct 2020 15:51:08 +0000 (11:51 -0400)
commitda76d98f1d547950e4e344016104a42cff2818de
tree75454eb602ddd587587a48927d42676c259f1bee
parentae1970d16110afbe063e795b8af36019aa765063
c++: Fix verify_ctor_sanity ICE [PR96241]

The code added in r10-6437 caused us to create a CONSTRUCTOR when we're
{}-initializing an aggregate.  Then we pass this new CONSTRUCTOR down to
cxx_eval_constant_expression which, if the CONSTRUCTOR isn't TREE_CONSTANT
or reduced_constant_expression_p, calls cxx_eval_bare_aggregate.  In
this case the CONSTRUCTOR wasn't reduced_constant_expression_p because
for r_c_e_p a CONST_DECL isn't good enough so it returns false.  So we
go to cxx_eval_bare_aggregate where we crash, because ctx->ctor wasn't
set up properly.  So my fix is to do so.  Since we're value-initializing,
I'm not setting CONSTRUCTOR_NO_CLEARING.  To avoid keeping a garbage
constructor around, I call free_constructor in case the evaluation did
not use it.

gcc/cp/ChangeLog:

PR c++/96241
* constexpr.c (cxx_eval_array_reference): Set up ctx->ctor if we
are initializing an aggregate.  Call free_constructor on the new
CONSTRUCTOR if it isn't returned from cxx_eval_constant_expression.

gcc/testsuite/ChangeLog:

PR c++/96241
* g++.dg/cpp0x/constexpr-96241.C: New test.
* g++.dg/cpp1y/constexpr-96241.C: New test.

(cherry picked from commit 0df73beea03f9dc124dc6e98ec4bdeacca7a2eea)
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp0x/constexpr-96241.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1y/constexpr-96241.C [new file with mode: 0644]