summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-06-23 16:04:02 -0400
committerJason Merrill <jason@redhat.com>2022-06-23 17:38:15 -0400
commitdb29b66193407d2fd6a04a07ecbd961c8d3f7d62 (patch)
tree5038699633fc2e1f9d33657426aafdf5094c1b40
parentc++: -Waddress and value-dependent expr [PR105885] (diff)
downloadgcc-db29b66193407d2fd6a04a07ecbd961c8d3f7d62.tar.gz
gcc-db29b66193407d2fd6a04a07ecbd961c8d3f7d62.tar.bz2
gcc-db29b66193407d2fd6a04a07ecbd961c8d3f7d62.tar.xz
c++: anon union designated init [PR105925]
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.
-rw-r--r--gcc/cp/decl.cc3
-rw-r--r--gcc/testsuite/g++.dg/cpp2a/desig26.C22
2 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 66d62af58f1..42c8d0b32e9 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,
6503 tree elt_init; 6503 tree elt_init;
6504 constructor_elt *old_cur = d->cur; 6504 constructor_elt *old_cur = d->cur;
6505 6505
6506 if (d->cur->index)
6507 CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
6506 check_array_designated_initializer (d->cur, index); 6508 check_array_designated_initializer (d->cur, index);
6507 elt_init = reshape_init_r (elt_type, d, 6509 elt_init = reshape_init_r (elt_type, d,
6508 /*first_initializer_p=*/NULL_TREE, 6510 /*first_initializer_p=*/NULL_TREE,
@@ -6670,6 +6672,7 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
6670 } 6672 }
6671 else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE) 6673 else if (TREE_CODE (d->cur->index) == IDENTIFIER_NODE)
6672 { 6674 {
6675 CONSTRUCTOR_IS_DESIGNATED_INIT (new_init) = true;
6673 field = get_class_binding (type, d->cur->index); 6676 field = get_class_binding (type, d->cur->index);
6674 direct_desig = true; 6677 direct_desig = true;
6675 } 6678 }
diff --git a/gcc/testsuite/g++.dg/cpp2a/desig26.C b/gcc/testsuite/g++.dg/cpp2a/desig26.C
new file mode 100644
index 00000000000..443fa3d089d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/desig26.C
@@ -0,0 +1,22 @@
1// PR c++/105925
2// { dg-do compile { target c++20 } }
3
4struct V
5{
6 int i;
7 double d;
8};
9
10struct X
11{
12 union
13 {
14 int x;
15 V y;
16 };
17};
18
19X foo()
20{
21 return {.y = {0, 0.0}};
22}