]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/92695 (P1064R0 - virtual constexpr fails if object taken from...
authorJakub Jelinek <jakub@redhat.com>
Fri, 20 Dec 2019 17:32:23 +0000 (18:32 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 20 Dec 2019 17:32:23 +0000 (18:32 +0100)
Backported from mainline
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.

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

From-SVN: r279663

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

index af8983803107ec3dff3e3de1b101cfc051639383..2e47b485d5469b0f13669789bccecdf9d0e9dc28 100644 (file)
@@ -1,6 +1,12 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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 9845416a8121ae9c03ce08702be9daf9cc2343b4..13d8a17c3e0423de70fec8e368e70262d7185bae 100644 (file)
@@ -5124,6 +5124,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 917de8fb18ac10c2a21e9902e44474e0e7dc367a..d50e9836b839b1b4aea0c4169db8125d11994c24 100644 (file)
@@ -1,6 +1,11 @@
 2019-12-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2019-12-02  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/92695
+       * g++.dg/cpp2a/constexpr-virtual15.C: New test.
+
        2019-11-29  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/60228
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);