public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/80829, ICE with constexpr copy of base
@ 2017-06-19 20:52 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2017-06-19 20:52 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 211 bytes --]

The constexpr code uses the CONSTRUCTOR_NO_IMPLICIT_ZERO flag to track
partially-initialized aggregates, but we were failing to clear it on
base subobjects.

Tested x86_64-pc-linux-gnu, applying to trunk and 7.

[-- Attachment #2: 80829.diff --]
[-- Type: text/plain, Size: 1943 bytes --]

commit 2e3142bcd6fde9f9ac22928718e55584a6255286
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Jun 19 15:15:14 2017 -0400

            PR c++/80829 - ICE with constexpr copy of base subobject.
    
            * constexpr.c (clear_no_implicit_zero): New.
            (cxx_eval_call_expression): Call it.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 569a247..5a57452 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -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
index 0000000..84700bc
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-base5.C
@@ -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);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-06-19 20:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-19 20:52 C++ PATCH for c++/80829, ICE with constexpr copy of base Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).