The following testcase ICEs since r12-7741 on the newly added gcc_assert.
We've diagnosed the designator is invalid before, but kept it as is.
The following patch changes it into error_mark_node, so that don't ICE on
it.
2025-12-02 Jakub Jelinek <jakub@redhat.com>
PR c++/122836
* decl.cc (check_array_designated_initializer): Change ce->index to
error_mark_node after emitting an error for it.
* g++.dg/ext/pr122836.C: New test.
{
error ("name %qD used in a GNU-style designated "
"initializer for an array", ce->index);
+ ce->index = error_mark_node;
return false;
}
--- /dev/null
+// PR c++/122836
+// { dg-do compile }
+// { dg-options "" }
+
+struct V { __attribute__ ((__vector_size__ (2 * sizeof (float)))) float v[2]; };
+
+V
+foo ()
+{
+ return (V) { { .v = { 0, 0 } } }; // { dg-error "name 'v' used in a GNU-style designated initializer for an array" }
+}