Commit 3a0bd58f by Jakub Jelinek Committed by Jakub Jelinek

re PR c++/92695 (P1064R0 - virtual constexpr fails if object taken from array)

	PR c++/92695
	* constexpr.c (cxx_eval_constant_expression) <case OBJ_TYPE_REF>: Use
	STRIP_NOPS before checking for ADDR_EXPR.

	* g++.dg/cpp2a/constexpr-virtual15.C: New test.

From-SVN: r278912
parent 871a8fab
2019-12-02 Jakub Jelinek <jakub@redhat.com>
PR c++/92695
* constexpr.c (cxx_eval_constant_expression) <case OBJ_TYPE_REF>: Use
STRIP_NOPS before checking for ADDR_EXPR.
2019-11-29 Jakub Jelinek <jakub@redhat.com>
PR c++/60228
......
......@@ -5548,6 +5548,7 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
tree obj = OBJ_TYPE_REF_OBJECT (t);
obj = cxx_eval_constant_expression (ctx, obj, lval, non_constant_p,
overflow_p);
STRIP_NOPS (obj);
/* We expect something in the form of &x.D.2103.D.2094; get x. */
if (TREE_CODE (obj) != ADDR_EXPR
|| !DECL_P (get_base_address (TREE_OPERAND (obj, 0))))
......
2019-12-02 Jakub Jelinek <jakub@redhat.com>
PR c++/92695
* g++.dg/cpp2a/constexpr-virtual15.C: New test.
2019-12-02 Richard Sandiford <richard.sandiford@arm.com>
PR middle-end/92741
......
// PR c++/92695
// { dg-do compile { target c++2a } }
struct A { virtual int get() = 0; };
struct B : A { constexpr int get() override { return 10; } };
struct D { B b[2]; A* c{&(b[0])}; };
static_assert(D{}.c->get() == 10);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment