re PR c++/84874 (internal compiler error: in reshape_init_class, at cp/decl.c:5800)
authorJakub Jelinek <jakub@redhat.com>
Fri, 16 Mar 2018 08:05:06 +0000 (09:05 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 16 Mar 2018 08:05:06 +0000 (09:05 +0100)
PR c++/84874
* decl.c (reshape_init_class): Don't assert d->cur->index == field
if d->cur->index is a FIELD_DECL, instead set field to d->cur->index.

* g++.dg/cpp2a/desig7.C: New test.

From-SVN: r258585

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

index a4f845a061b008070d038706b7d32d9e15a57581..7322a76bd8648b8d670313a16a0348408d789092 100644 (file)
@@ -1,3 +1,9 @@
+2018-03-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84874
+       * decl.c (reshape_init_class): Don't assert d->cur->index == field
+       if d->cur->index is a FIELD_DECL, instead set field to d->cur->index.
+
 2018-03-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/84222
index 98f762e5253b6f8549fd004906294a8fb6c89e12..727bb04a394e413539b0739af4d73666631920de 100644 (file)
@@ -5885,8 +5885,17 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
            return error_mark_node;
 
          if (TREE_CODE (d->cur->index) == FIELD_DECL)
-           /* We already reshaped this.  */
-           gcc_assert (d->cur->index == field);
+           {
+             /* We already reshaped this.  */
+             if (field != d->cur->index)
+               {
+                 tree id = DECL_NAME (d->cur->index);
+                 gcc_assert (id);
+                 gcc_checking_assert (d->cur->index
+                                      == get_class_binding (type, id, false));
+                 field = d->cur->index;
+               }
+           }
          else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
            field = get_class_binding (type, d->cur->index, false);
          else
index 14e70af66d65c8a0ced2a146c976fc82ff604aba..dbd764002538defbcd17dc9f97087b1689719ea4 100644 (file)
@@ -1,3 +1,8 @@
+2018-03-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84874
+       * g++.dg/cpp2a/desig7.C: New test.
+
 03-16-2018  Mark Doffman  <mark.doffman@codethink.co.uk>
             Jim MacArthur  <jim.macarthur@codethink.co.uk>
 
diff --git a/gcc/testsuite/g++.dg/cpp2a/desig7.C b/gcc/testsuite/g++.dg/cpp2a/desig7.C
new file mode 100644 (file)
index 0000000..2865014
--- /dev/null
@@ -0,0 +1,31 @@
+// PR c++/84874
+// { dg-do run { target c++11 } }
+// { dg-options "" }
+
+struct A { int a, b; };
+struct B { A d; };
+
+void
+foo (B *x)
+{
+  *x = { .d = { .b = 5 } };
+}
+
+void
+bar (A *x)
+{
+  *x = { .b = 6 };
+}
+
+int
+main ()
+{
+  B b = { { 2, 3 } };
+  foo (&b);
+  if (b.d.a != 0 || b.d.b != 5)
+    __builtin_abort ();
+  b.d.a = 8;
+  bar (&b.d);
+  if (b.d.a != 0 || b.d.b != 6)
+    __builtin_abort ();
+}