This testcase was failing because CONSTRUCTOR_IS_DESIGNATED_INIT wasn't
getting set on the introduced CONSTRUCTOR for the anonymous union, and
build_aggr_conv uses that flag to decide whether to pay attention to the
indexes of the CONSTRUCTOR. So set the flag when we see a designator rather
than relying on copying it from another CONSTRUCTOR.
PR c++/105925
gcc/cp/ChangeLog:
* decl.cc (reshape_init_array_1): Set
CONSTRUCTOR_IS_DESIGNATED_INIT here.
(reshape_init_class): And here.
gcc/testsuite/ChangeLog:
* g++.dg/cpp2a/desig26.C: New test.
tree elt_init;
constructor_elt *old_cur = d->cur;
+ if (d->cur->index)
+ CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
check_array_designated_initializer (d->cur, index);
elt_init = reshape_init_r (elt_type, d,
/*first_initializer_p=*/NULL_TREE,
}
else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
{
+ CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
field = get_class_binding (type, d->cur->index);
direct_desig = true;
}
--- /dev/null
+// PR c++/105925
+// { dg-do compile { target c++20 } }
+
+struct V
+{
+ int i;
+ double d;
+};
+
+struct X
+{
+ union
+ {
+ int x;
+ V y;
+ };
+};
+
+X foo()
+{
+ return {.y = {0, 0.0}};
+}