Mercurial > hg > CbC > CbC_gcc
comparison gcc/testsuite/g++.dg/warn/Wmismatched-tags.C @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 /* PR c++/61339 - add mismatch between struct and class | |
2 Test to verify that -Wmismatched-tags is issued for declarations | |
3 of the same class using different class-ids. | |
4 { dg-do compile } | |
5 { dg-options "-Wmismatched-tags" } */ | |
6 | |
7 namespace Classes | |
8 { | |
9 class A; | |
10 class A; | |
11 | |
12 struct B; | |
13 struct B; | |
14 | |
15 union C; | |
16 union C; | |
17 | |
18 struct D; // { dg-warning "Classes::D' declared with a mismatched class-key 'struct'" } | |
19 class D { }; // { dg-message "Classes::D' defined as 'class' here" } | |
20 | |
21 class E; // { dg-warning "Classes::E' declared with a mismatched class-key 'class'" } | |
22 struct E { }; // { dg-message "Classes::E' defined as 'struct' here" } | |
23 | |
24 class D; | |
25 struct E; | |
26 | |
27 class D; | |
28 struct E; | |
29 | |
30 struct D; // { dg-warning "Classes::D' declared with a mismatched class-key" } | |
31 | |
32 class E; // { dg-warning "Classes::E' declared with a mismatched class-key" } | |
33 | |
34 class F; // { dg-message "Classes::F' first declared as 'class' here" } | |
35 class F; | |
36 | |
37 struct G { }; // { dg-message "Classes::G' defined as 'struct' here" } | |
38 } // namespace Classes | |
39 | |
40 | |
41 namespace Classes | |
42 { | |
43 class A; | |
44 struct B; | |
45 union C; | |
46 class D; | |
47 struct E; | |
48 | |
49 struct F; // { dg-warning "Classes::F' declared with a mismatched class-key" } | |
50 | |
51 struct G; | |
52 } | |
53 | |
54 // Verify that the correct hint is provided, one to remove the class-key | |
55 // when it's redundant, and one to (only) replace it with the correct one | |
56 // when it's needed to disambiguate the reference to the class type. | |
57 namespace RemoveOrReplace | |
58 { | |
59 struct Func; | |
60 class Func; // { dg-warning "RemoveOrReplace::Func' declared with a mismatched class-key 'class'" } | |
61 // { dg-message "replace the class-key with 'struct'" "hint to remove" { target *-*-* } .-1 } | |
62 | |
63 void Func (); | |
64 | |
65 class Func; // { dg-warning "RemoveOrReplace::Func' declared with a mismatched class-key 'class'" } | |
66 // { dg-message "replace the class-key with 'struct'" "hint to replace" { target *-*-* } .-1 } | |
67 | |
68 class Var; | |
69 struct Var; // { dg-warning "RemoveOrReplace::Var' declared with a mismatched class-key 'struct'" } | |
70 // { dg-message "replace the class-key with 'class'" "hint to remove" { target *-*-* } .-1 } | |
71 void f (struct Var*); // { dg-warning "RemoveOrReplace::Var' declared with a mismatched class-key 'struct'" } | |
72 // { dg-message "remove the class-key or replace it with 'class'" "hint to remove" { target *-*-* } .-1 } | |
73 | |
74 int Var; | |
75 | |
76 struct Var; // { dg-warning "RemoveOrReplace::Var' declared with a mismatched class-key 'struct'" } | |
77 // { dg-message "replace the class-key with 'class'" "hint to replace" { target *-*-* } .-1 } | |
78 } | |
79 | |
80 namespace GlobalObjects | |
81 { | |
82 class A; // { dg-message "'GlobalObjects::A' first declared as 'class' here" } | |
83 struct B; // { dg-message "'GlobalObjects::B' first declared as 'struct' here" } | |
84 class C { }; // { dg-message "'GlobalObjects::C' defined as 'class' here" } | |
85 | |
86 extern A a0; | |
87 extern class A a1; | |
88 extern class A a2; | |
89 | |
90 extern B b0; | |
91 extern struct B b1; | |
92 extern struct B b2; | |
93 | |
94 extern struct A a3; // { dg-warning "GlobalObjects::A' declared with a mismatched class-key" } | |
95 extern class A a4; | |
96 | |
97 extern class B b3; // { dg-warning "GlobalObjects::B' declared with a mismatched class-key" } | |
98 extern struct B b4; | |
99 | |
100 extern struct C c[]; // { dg-warning "GlobalObjects::C' declared with a mismatched class-key" } | |
101 // { dg-message "remove the class-key or replace it with 'class'" "hint to remove" { target *-*-* } .-1 } | |
102 | |
103 extern char | |
104 arr[sizeof (struct C)]; // { dg-warning "GlobalObjects::C' declared with a mismatched class-key" } | |
105 // { dg-message "remove the class-key or replace it with 'class'" "hint to remove" { target *-*-* } .-1 } | |
106 } // namespace GlobalObjects | |
107 | |
108 | |
109 namespace LocalObjects | |
110 { | |
111 class A; // { dg-message "LocalObjects::A' first declared as 'class' here" } | |
112 struct B; // { dg-message "LocalObjects::B' first declared as 'struct' here" } | |
113 | |
114 void f (A*, B&) | |
115 { | |
116 class A *a1; | |
117 class A *a2; | |
118 | |
119 struct B *b1; | |
120 struct B *b2; | |
121 | |
122 struct A *a3; // { dg-warning "LocalObjects::A' declared with a mismatched class-key" } | |
123 class A *a4; | |
124 | |
125 class B *b3; // { dg-warning "LocalObjects::B' declared with a mismatched class-key" } | |
126 struct B *b4; | |
127 } | |
128 | |
129 void g (struct A*); // { dg-warning "LocalObjects::A' declared with a mismatched class-key" } | |
130 | |
131 } // namespace LocalObjects | |
132 | |
133 | |
134 namespace MemberClasses | |
135 { | |
136 struct A { struct B; }; | |
137 struct C { struct D; struct D; struct D { }; }; | |
138 struct E { class F; class F { }; class F; }; | |
139 | |
140 struct G { | |
141 struct H; // { dg-message "MemberClasses::G::H' first declared as 'struct' here" } | |
142 class H; // { dg-warning "MemberClasses::G::H' declared with a mismatched class-key" } | |
143 class I { }; // { dg-message "MemberClasses::G::I' defined as 'class' here" } | |
144 struct I; // { dg-warning "MemberClasses::G::I' declared with a mismatched class-key" } | |
145 }; | |
146 } // namespace MemberClasses | |
147 | |
148 | |
149 namespace DataMembers | |
150 { | |
151 struct A { struct B *p; }; | |
152 struct C { struct D *p; struct D *q; struct D { } d; }; | |
153 struct E { class F &r; class F { } f; class F *p; }; | |
154 | |
155 class G; // { dg-message "DataMembers::G' first declared as 'class' here" } | |
156 struct H; // { dg-message "DataMembers::H' first declared as 'struct' here" } | |
157 | |
158 struct I { | |
159 struct G *p0; // { dg-warning "DataMembers::G' declared with a mismatched class-key" } | |
160 class G *p1; | |
161 | |
162 struct H &r0; | |
163 class H &r1; // { dg-warning "DataMembers::H' declared with a mismatched class-key" } | |
164 | |
165 class J { }; // { dg-message "DataMembers::I::J' defined as 'class' here" } | |
166 struct K { }; // { dg-message "DataMembers::I::K' defined as 'struct' here" } | |
167 | |
168 class J j0; | |
169 class K k0; // { dg-warning "DataMembers::I::K' declared with a mismatched class-key" } | |
170 | |
171 struct J j1; // { dg-warning "DataMembers::I::J' declared with a mismatched class-key" } | |
172 struct K k1; | |
173 }; | |
174 } // namespace DataMembers | |
175 | |
176 | |
177 namespace Templates | |
178 { | |
179 template <int> class A; | |
180 template <int> class A; | |
181 | |
182 template <int> struct B; | |
183 template <int> struct B; | |
184 | |
185 template <int> union C; | |
186 template <int> union C; | |
187 | |
188 template <int> struct D; // { dg-warning "Templates::D\[^\n\r]*' declared with a mismatched class-key" } | |
189 template <int> | |
190 class D // { dg-message "Templates::D\[^\n\r]*' defined as 'class' here" } | |
191 { public: D (); }; | |
192 | |
193 template <int> class E; // { dg-warning "Templates::E\[^\n\r]*' declared with a mismatched class-key" } | |
194 template <int> | |
195 struct E // { dg-message "Templates::E\[^\n\r]*' defined as 'struct' here" } | |
196 { int i; }; | |
197 | |
198 template <int> class D; | |
199 template <int> struct E; | |
200 | |
201 template <int> | |
202 struct D; // { dg-warning "Templates::D\[^\n\r]*' declared with a mismatched class-key" } | |
203 // { dg-message "replace the class-key with 'class'" "hint" { target *-*-* } .-1 } | |
204 } // namespace Templates | |
205 | |
206 | |
207 namespace ExplicitSpecializations | |
208 { | |
209 template <int> class A; | |
210 template <> class A<0>; | |
211 template <> struct A<1>; | |
212 template <> struct A<1> { }; | |
213 | |
214 template <int> struct B; | |
215 template <> struct B<0>; | |
216 template <> class B<1>; | |
217 template <> class B<2> { public: B (); }; | |
218 | |
219 template <int> union C; | |
220 template <> union C<0>; | |
221 | |
222 template <int> class D; | |
223 template <> class D<0>; // { dg-warning "ExplicitSpecializations::D\[^\n\r]*' declared with a mismatched class-key " } | |
224 template <> | |
225 struct D<0> { }; // { dg-message "ExplicitSpecializations::D\[^\n\r]*' defined as 'struct' here" } | |
226 | |
227 template <int> struct E; | |
228 template <> struct E<0>; // { dg-warning "ExplicitSpecializations::E\[^\n\r]*' declared with a mismatched class-key" } | |
229 template <> | |
230 class E<0> { }; // { dg-message "ExplicitSpecializations::E\[^\n\r]*' defined as 'class' here" } | |
231 | |
232 template <int> struct F; | |
233 template <> class F<0> { }; // { dg-message "ExplicitSpecializations::F\[^\n\r]*' defined as 'class' here" } | |
234 | |
235 template <> | |
236 struct F<0>; // { dg-warning "ExplicitSpecializations::F\[^\n\r]*' declared with a mismatched class-key" } | |
237 } // namespace ExplicitSpecializations | |
238 | |
239 | |
240 namespace PartialSpecializations | |
241 { | |
242 template <class> class A; | |
243 template <class T> struct A<const T>; | |
244 template <class T> struct A<volatile T>; | |
245 | |
246 template <class> struct B; | |
247 template <class T> class B<const T>; | |
248 template <class T> class B<volatile T>; | |
249 | |
250 template <class> class C { }; | |
251 template <class T> struct C<const T> { }; | |
252 template <class T> struct C<volatile T> { }; | |
253 | |
254 template <class> struct D { }; | |
255 template <class T> class D<const T> { }; | |
256 template <class T> class D<volatile T> { }; | |
257 | |
258 template <class> class E; | |
259 template <class T> | |
260 struct E<const T>; // { dg-message "PartialSpecializations::E<const T>' first declared as 'struct' here" } | |
261 | |
262 template <class T> | |
263 class E<const T>; // { dg-warning "PartialSpecializations::E<const T>' declared with a mismatched class-key" } | |
264 | |
265 template <class> class F; | |
266 template <class T> | |
267 class F<const T>; // { dg-message "PartialSpecializations::F<const T>' first declared as 'class' here" } | |
268 template <class T> | |
269 struct F<const T>; // { dg-warning "PartialSpecializations::F<const T>' declared with a mismatched class-key" } | |
270 } // namespace PartialSpecializations | |
271 | |
272 | |
273 namespace Classes | |
274 { | |
275 struct G; | |
276 | |
277 class G; // { dg-warning "Classes::G' declared with a mismatched class-key 'class'" } | |
278 } |