]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/84874 (internal compiler error: in reshape_init_class, at cp...
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:44:39 +0000 (22:44 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:44:39 +0000 (22:44 +0200)
Backported from mainline
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.

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

From-SVN: r261926

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

index 78c475ddee04b85bb66a22f6e2759c5096460764..163969d74d8e90c879c899b223b90cbed722aa45 100644 (file)
@@ -1,6 +1,12 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       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 a0c634fd56668912e68905d445a766788d26bfa0..2193dd929f852e92f5fcf2b5341a8b9a573150bc 100644 (file)
@@ -5796,8 +5796,18 @@ 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 (lookup_field_1 (type, id,
+                                                      /*want_type=*/false)
+                                      == d->cur->index);
+                 field = d->cur->index;
+               }
+           }
          else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
            field = lookup_field_1 (type, d->cur->index, /*want_type=*/false);
          else
index 073c11d832a98df083991490f8d4951fcf00c411..cf5428f5de7a5ef271fb7986a92107f41ecdff68 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-03-16  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/84874
+       * g++.dg/cpp1z/desig7.C: New test.
+
        2018-03-15  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/79085
diff --git a/gcc/testsuite/g++.dg/cpp1z/desig7.C b/gcc/testsuite/g++.dg/cpp1z/desig7.C
new file mode 100644 (file)
index 0000000..8368837
--- /dev/null
@@ -0,0 +1,18 @@
+// PR c++/84874
+// { dg-do compile { target c++11 } }
+// { dg-options "" }
+
+struct A { int a, b; };
+struct B { A d; };
+
+void
+foo (B *x)
+{
+  *x = { .d = { .b = 5 } };    // { dg-message "non-trivial designated initializers not supported" }
+}
+
+void
+bar (A *x)
+{
+  *x = { .b = 6 };             // { dg-message "non-trivial designated initializers not supported" }
+}