c++: Fix ICE during constexpr virtual call evaluation [PR93633]
authorJakub Jelinek <jakub@redhat.com>
Sun, 9 Feb 2020 11:32:22 +0000 (12:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sun, 9 Feb 2020 11:32:22 +0000 (12:32 +0100)
commit81958cd6adf402a85dc7d21b43caac56fba0af21
tree9e08c80b11eb8a78776f879ad7b0a4f3027110c5
parent9bc3b95dfefd37d860c5dc0004f8a53f6290fbb1
c++: Fix ICE during constexpr virtual call evaluation [PR93633]

The first (valid) testcase ICEs because for
  A *a = new B ();
  a->foo (); // virtual method call
we actually see &heap  and the "heap " objects don't have the class or
whatever else type was used in new expression, but an array type containing
one (or more of those for array new) and so when using TYPE_BINFO (objtype)
on it we ICE.
This patch handles this special case, and otherwise punts (as shown e.g. in
the second testcase, where because the heap object is already deleted,
we don't really want to allow it to be used.

2020-02-09  Jakub Jelinek  <jakub@redhat.com>

PR c++/93633
* constexpr.c (cxx_eval_constant_expression): If obj is heap var with
ARRAY_TYPE, use the element type.  Punt if objtype after that is not
a class type.

* g++.dg/cpp2a/constexpr-new11.C: New test.
* g++.dg/cpp2a/constexpr-new12.C: New test.
* g++.dg/cpp2a/constexpr-new13.C: New test.
gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/constexpr-new11.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-new12.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/constexpr-new13.C [new file with mode: 0644]