re PR c++/92695 (P1064R0 - virtual constexpr fails if object taken from array)
authorJakub Jelinek <jakub@redhat.com>
Mon, 2 Dec 2019 21:33:06 +0000 (22:33 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 2 Dec 2019 21:33:06 +0000 (22:33 +0100)
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

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C [new file with mode: 0644]

index 3a6bf059a2df992d700409ba686d68d459e372d0..9ca25aea63561f651ab71f6071ca9cd82651ff66 100644 (file)
@@ -1,3 +1,9 @@
+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
index ee3ccb9691cafe20dc61e7ec9c3364a8dc71ab80..cc3ef1056f2816a743a5533acec8892398de516e 100644 (file)
@@ -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))))
index 8dd2633d6437a33aedbaaa9821c394b9a072d5e1..4ec5a264eddec50f2df5605aa10f6ee364f8a651 100644 (file)
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual15.C
new file mode 100644 (file)
index 0000000..cb55aa3
--- /dev/null
@@ -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);