blob: 65f3237e42ae5e9882eb28ee87cd5ae99cfaa039 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
From b94c95fc1199bfa2c7ab577921b07ef545976cac Mon Sep 17 00:00:00 2001
From: Jason Merrill <jason@redhat.com>
Date: Fri, 18 Mar 2022 14:36:19 -0400
Subject: c++: designator and anon struct [PR101767]
We found .x in the anonymous struct, but then didn't find .y there; we
should decide that means we're done with the struct rather than that the
code is wrong.
PR c++/101767
gcc/cp/ChangeLog:
* decl.c (reshape_init_class): Back out of anon struct
if a designator doesn't match.
gcc/testsuite/ChangeLog:
* g++.dg/ext/anon-struct10.C: New test.
---
gcc/cp/decl.c | 5 +++++
gcc/testsuite/g++.dg/ext/anon-struct10.C | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/anon-struct10.C
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 41094c891fc..6d3e764fb14 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -6437,6 +6437,11 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
return error_mark_node;
}
+ if (!field && ANON_AGGR_TYPE_P (type))
+ /* Apparently the designator isn't for a member of this anonymous
+ struct, so head back to the enclosing class. */
+ break;
+
if (!field || TREE_CODE (field) != FIELD_DECL)
{
if (complain & tf_error)
diff --git a/gcc/testsuite/g++.dg/ext/anon-struct10.C b/gcc/testsuite/g++.dg/ext/anon-struct10.C
new file mode 100644
index 00000000000..9b01bf3fada
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/anon-struct10.C
@@ -0,0 +1,21 @@
+// PR c++/101767
+// { dg-do compile { target c++11 } }
+// { dg-additional-options "-Wno-pedantic" }
+
+typedef struct {
+ struct {
+ int x;
+ };
+ union {
+ int y;
+ float z;
+ };
+} S;
+
+void foo(void)
+{
+ [[maybe_unused]] S a = {
+ .x = 1,
+ .y = 0
+ };
+}
--
2.31.1
|