On Fri, Mar 16, 2018 at 12:29:58AM +0100, Jakub Jelinek wrote:
> As the testcase shows, even when we've already reshaped the initializer, if
> it uses designated initializers and skips using those over others, we can
> have field != d->cur->index.  The following patch handles that case.

Just to verify we don't ICE even with anonymous aggregates, I've added
another testcase, tested on x86_64-linux, committed to trunk as obvious.

2018-03-16  Jakub Jelinek  <ja...@redhat.com>

        PR c++/84874
        * g++.dg/cpp2a/desig8.C: New test.

--- gcc/testsuite/g++.dg/cpp2a/desig8.C.jj      2018-03-16 09:42:08.585005338 
+0100
+++ gcc/testsuite/g++.dg/cpp2a/desig8.C 2018-03-16 09:41:15.100019444 +0100
@@ -0,0 +1,31 @@
+// PR c++/84874
+// { dg-do run { target c++17 } }
+// { dg-options "" }
+
+struct A { int a; struct { int 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 ();
+}


        Jakub

Reply via email to