1 /* Test for diagnostics for duplicate member names in anonymous
2 structures and unions. PR 4784. */
3 /* { dg-do compile } */
4 /* { dg-options "" } */
5
6 struct s1
7 {
8 int x;
9 struct
10 {
11 int x; /* { dg-error "duplicate member" } */
12 };
13 };
14
15 struct s2
16 {
17 struct
18 {
19 int a;
20 struct
21 {
22 int b;
23 };
24 };
25 struct
26 {
27 int b; /* { dg-error "duplicate member" } */
28 };
29 };
30
31 struct s3
32 {
33 struct
34 {
35 int a;
36 struct
37 {
38 int b;
39 };
40 };
41 struct
42 {
43 int b; /* { dg-error "duplicate member" } */
44 int c;
45 };
46 };
47
48 struct s4
49 {
50 int x;
51 struct
52 {
53 int x;
54 } y;
55 };
56
57 union u1
58 {
59 int x;
60 union
61 {
62 int x; /* { dg-error "duplicate member" } */
63 };
64 };
65
66 union u2
67 {
68 union
69 {
70 int a;
71 union
72 {
73 int b;
74 };
75 };
76 union
77 {
78 int b; /* { dg-error "duplicate member" } */
79 };
80 };
81
82 union u3
83 {
84 union
85 {
86 int a;
87 union
88 {
89 int b;
90 };
91 };
92 union
93 {
94 int b; /* { dg-error "duplicate member" } */
95 int c;
96 };
97 };
98
99 union u4
100 {
101 int x;
102 union
103 {
104 int x;
105 } y;
106 };
107
108 #define D10(x) int x##0; int x##1; int x##2; int x##3; int x##4; int x##5; int x##6; int x##7; int x##8; int x##9;
109 #define D100(x) D10(x##0) D10(x##1) D10(x##2) D10(x##3) D10(x##4) D10(x##5) D10(x##6) D10(x##7) D10(x##8) D10(x##9)
110
111 #define S10(x) struct { D100(x##0) }; struct { D100(x##1) }; struct { D100(x##2) }; struct { D100(x##3) }; struct { D100(x##4) }; struct { D100(x##5) }; struct { D100(x##6) }; struct { D100(x##7) }; struct { D100(x##8) }; struct { D100(x##9) };
112
113 struct sbig
114 {
115 S10(a)
116 S10(b)
117 S10(c)
118 S10(d)
119 S10(e)
120 S10(f)
121 S10(g)
122 S10(h)
123 S10(j)
124 S10(k)
125 struct
126 {
127 int a123; /* { dg-error "duplicate member" } */
128 };
129 };