From 3a0bd58fac55e8cdd4c2674bf10ca6998337236a Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Mon, 2 Dec 2019 22:33:06 +0100 Subject: [PATCH] re PR c++/92695 (P1064R0 - virtual constexpr fails if object taken from array) PR c++/92695 * constexpr.c (cxx_eval_constant_expression) : Use STRIP_NOPS before checking for ADDR_EXPR. * g++.dg/cpp2a/constexpr-virtual15.C: New test. From-SVN: r278912 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/constexpr.c | 1 + gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C | 7 +++++++ 4 files changed, 19 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3a6bf059a2d..9ca25aea635 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-12-02 Jakub Jelinek + + PR c++/92695 + * constexpr.c (cxx_eval_constant_expression) : Use + STRIP_NOPS before checking for ADDR_EXPR. + 2019-11-29 Jakub Jelinek PR c++/60228 diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c index ee3ccb9691c..cc3ef1056f2 100644 --- a/gcc/cp/constexpr.c +++ b/gcc/cp/constexpr.c @@ -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)))) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8dd2633d643..4ec5a264edd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-12-02 Jakub Jelinek + + PR c++/92695 + * g++.dg/cpp2a/constexpr-virtual15.C: New test. + 2019-12-02 Richard Sandiford PR middle-end/92741 diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C new file mode 100644 index 00000000000..cb55aa3bb56 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C @@ -0,0 +1,7 @@ +// 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); -- 2.30.2