diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 66d62af58f1c..42c8d0b32e99 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -6503,6 +6503,8 @@ reshape_init_array_1 (tree elt_type, tree max_index, reshape_iter *d, 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, @@ -6670,6 +6672,7 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p, } 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; } diff --git a/gcc/testsuite/g++.dg/cpp2a/desig26.C b/gcc/testsuite/g++.dg/cpp2a/desig26.C new file mode 100644 index 000000000000..443fa3d089d0 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/desig26.C @@ -0,0 +1,22 @@ +// 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}}; +}