PR c++/80829 - ICE with constexpr copy of base subobject.
authorJason Merrill <jason@redhat.com>
Mon, 19 Jun 2017 20:55:21 +0000 (16:55 -0400)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 19 Jun 2017 20:55:21 +0000 (16:55 -0400)
* constexpr.c (clear_no_implicit_zero): New.
(cxx_eval_call_expression): Call it.

From-SVN: r249386

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

index b80d3738319c48cb8488b82856f636774fe68871..ff4280aebd10d4c5c1508b58389d4c9e8a1a616d 100644 (file)
@@ -1,3 +1,9 @@
+2017-06-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/80829 - ICE with constexpr copy of base subobject.
+       * constexpr.c (clear_no_implicit_zero): New.
+       (cxx_eval_call_expression): Call it.
+
 2017-06-19  Nathan Sidwell  <nathan@acm.org>
 
        PR c++/81124
index 569a247d6b0a81a41000856ebc2b0c7000730df9..5a57452486641254448a29e0a689a349e07e1cb8 100644 (file)
@@ -1394,6 +1394,21 @@ cxx_eval_internal_function (const constexpr_ctx *ctx, tree t,
   return t;
 }
 
+/* Clean CONSTRUCTOR_NO_IMPLICIT_ZERO from CTOR and its sub-aggregates.  */
+
+static void
+clear_no_implicit_zero (tree ctor)
+{
+  if (CONSTRUCTOR_NO_IMPLICIT_ZERO (ctor))
+    {
+      CONSTRUCTOR_NO_IMPLICIT_ZERO (ctor) = false;
+      tree elt; unsigned HOST_WIDE_INT idx;
+      FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (ctor), idx, elt)
+       if (TREE_CODE (elt) == CONSTRUCTOR)
+         clear_no_implicit_zero (elt);
+    }
+}
+
 /* Subroutine of cxx_eval_constant_expression.
    Evaluate the call expression tree T in the context of OLD_CALL expression
    evaluation.  */
@@ -1697,7 +1712,7 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 
   /* The result of a constexpr function must be completely initialized.  */
   if (TREE_CODE (result) == CONSTRUCTOR)
-    CONSTRUCTOR_NO_IMPLICIT_ZERO (result) = false;
+    clear_no_implicit_zero (result);
 
   pop_cx_call_context ();
   return unshare_constructor (result);
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C
new file mode 100644 (file)
index 0000000..84700bc
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/80829
+// { dg-do compile { target c++11 } }
+
+struct A {
+  constexpr A(int a) : _a(a) {}
+  int _a;
+};
+
+struct B : public A {
+  constexpr B(int a) : A(a) {}
+};
+
+int main() {
+  constexpr A a = B(10);
+}