re PR c++/88110 (ICE (segfault) with -std=C++2a in cxx_eval_constant_expression when...
authorJakub Jelinek <jakub@redhat.com>
Tue, 20 Nov 2018 22:23:12 +0000 (23:23 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 20 Nov 2018 22:23:12 +0000 (23:23 +0100)
PR c++/88110
* constexpr.c (cxx_eval_constant_expression) <case OBJ_TYPE_REF>: Punt
if get_base_address of ADDR_EXPR operand is not a DECL_P.

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

From-SVN: r266329

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

index f43d9c4..a5ee86e 100644 (file)
@@ -1,3 +1,9 @@
+2018-11-20  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/88110
+       * constexpr.c (cxx_eval_constant_expression) <case OBJ_TYPE_REF>: Punt
+       if get_base_address of ADDR_EXPR operand is not a DECL_P.
+
 2018-11-19  Marek Polacek  <polacek@redhat.com>
 
        PR c++/87781 - detect invalid elaborated-type-specifier.
index c9e1e0c..92fd2b2 100644 (file)
@@ -4815,7 +4815,8 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
        obj = cxx_eval_constant_expression (ctx, obj, lval, non_constant_p,
                                            overflow_p);
        /* We expect something in the form of &x.D.2103.D.2094; get x. */
-       if (TREE_CODE (obj) != ADDR_EXPR)
+       if (TREE_CODE (obj) != ADDR_EXPR
+           || !DECL_P (get_base_address (TREE_OPERAND (obj, 0))))
          {
            if (!ctx->quiet)
              error_at (cp_expr_loc_or_loc (t, input_location),
index b810f93..9f1edce 100644 (file)
@@ -1,5 +1,8 @@
 2018-11-20  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/88110
+       * g++.dg/cpp2a/constexpr-virtual13.C: New test.
+
        PR tree-optimization/87895
        * gcc.dg/gomp/pr87895-1.c: New test.
        * gcc.dg/gomp/pr87895-2.c: New test.
diff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-virtual13.C
new file mode 100644 (file)
index 0000000..921df9f
--- /dev/null
@@ -0,0 +1,20 @@
+// PR c++/88110
+// { dg-do compile }
+
+struct A {
+  virtual int foo () const = 0;
+};
+struct B {
+  virtual int bar () const = 0;
+  virtual int baz () const = 0;
+};
+struct C : public A { };
+struct D : public C { };
+struct E : public D, public B { };
+
+void
+qux (const E *x)
+{
+  if (x->baz ())
+    ;
+}