]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE-on-invalid with designated initializer [PR106983]
authorMarek Polacek <polacek@redhat.com>
Tue, 20 Sep 2022 18:54:57 +0000 (14:54 -0400)
committerMarek Polacek <polacek@redhat.com>
Fri, 23 Sep 2022 00:23:59 +0000 (20:23 -0400)
We ICE in the code added in r12-7117: type_build_dtor_call gets
the error_mark_node because the type of 'prev' wasn't declared.

PR c++/106983

gcc/cp/ChangeLog:

* typeck2.cc (split_nonconstant_init_1): Check TYPE_P.

gcc/testsuite/ChangeLog:

* g++.dg/other/error36.C: New test.

gcc/cp/typeck2.cc
gcc/testsuite/g++.dg/other/error36.C [new file with mode: 0644]

index 688e9c15326ad4c136595e59bc7bc16babad3b89..75fd0e2a9bf80165300d1bd71e570951cc109922 100644 (file)
@@ -597,7 +597,7 @@ split_nonconstant_init_1 (tree dest, tree init, bool last,
                    if (prev == field_index)
                      break;
                    tree ptype = TREE_TYPE (prev);
-                   if (type_build_dtor_call (ptype))
+                   if (TYPE_P (ptype) && type_build_dtor_call (ptype))
                      {
                        tree pcref = build3 (COMPONENT_REF, ptype, dest, prev,
                                             NULL_TREE);
diff --git a/gcc/testsuite/g++.dg/other/error36.C b/gcc/testsuite/g++.dg/other/error36.C
new file mode 100644 (file)
index 0000000..5562878
--- /dev/null
@@ -0,0 +1,13 @@
+// PR c++/106983
+// { dg-do compile { target c++20 } }
+
+typedef unsigned long long A;
+typedef union
+{
+  struct B s; // { dg-error "incomplete" }
+  A a;
+} U;
+void f (A x, unsigned int b)
+{
+  const U y = {.a = x};
+}