1 // RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers -verify %s
2 // RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags -fno-diagnostics-show-line-numbers %s 2>&1 | FileCheck %s
3 class X
; // expected-note 2{{here}}
4 typedef struct X
* X_t
; // expected-warning{{previously declared}}
5 union X
{ int x
; float y
; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
7 template<typename T
> struct Y
; // expected-note{{did you mean class here?}}
8 template<class U
> class Y
{ }; // expected-warning{{previously declared}}
12 struct Z
{ // expected-error{{member 'Z' has the same name as its class}}
17 class A
; // expected-note{{previous use is here}}
18 struct A
; // expected-warning{{struct 'A' was previously declared as a class}}
20 class B
; // expected-note{{did you mean struct here?}}
21 class B
; // expected-note{{previous use is here}}\
22 // expected-note{{did you mean struct here?}}
23 struct B
; // expected-warning{{struct 'B' was previously declared as a class}}
24 struct B
{}; // expected-warning{{'B' defined as a struct here but previously declared as a class}}
26 class C
; // expected-note{{previous use is here}}
27 struct C
; // expected-warning{{struct 'C' was previously declared as a class}}\
28 // expected-note{{previous use is here}}\
29 // expected-note{{did you mean class here?}}
30 class C
; // expected-warning{{class 'C' was previously declared as a struct}}\
31 // expected-note{{previous use is here}}
32 struct C
; // expected-warning{{struct 'C' was previously declared as a class}}\
33 // expected-note{{did you mean class here?}}
34 class C
{}; // expected-warning{{'C' defined as a class here but previously declared as a struct}}
36 struct D
{}; // expected-note{{previous definition is here}}\
37 // expected-note{{previous use is here}}
38 class D
{}; // expected-error{{redefinition of 'D'}}
40 class D
; // expected-warning{{class 'D' was previously declared as a struct}}\
41 // expected-note{{did you mean struct here?}}
50 struct F
{}; // expected-note {{previous use}}
52 class F
; // expected-warning {{previously declared as a struct}} expected-note {{did you mean struct}}
54 template<class U
> class G
; // expected-note{{previous use is here}}\
55 // expected-note{{did you mean struct here?}}
56 template<class U
> struct G
; // expected-warning{{struct template 'G' was previously declared as a class template}}
57 template<class U
> struct G
{}; // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}
59 // Declarations from contexts where the warning is disabled are entirely
60 // ignored for the purpose of this warning.
62 struct K
; // expected-note {{previous use}}
64 struct M
; // expected-note {{previous use}}
66 #pragma clang diagnostic push
67 #pragma clang diagnostic ignored "-Wmismatched-tags"
74 #pragma clang diagnostic pop
76 class H
; // expected-note {{previous use}}
77 struct H
; // expected-warning {{previously declared as a class}}
79 struct I
; // expected-note {{previous use}}
80 class I
; // expected-warning {{previously declared as a struct}}
83 class K
; // expected-warning {{previously declared as a struct}}
85 class M
; // expected-warning {{previously declared as a struct}}
89 CHECK: warning: struct 'X' was previously declared as a class
90 CHECK: {{^}}typedef struct X * X_t;
92 CHECK: note: previous use is here
95 CHECK: error: use of 'X' with tag type that does not match previous declaration
96 CHECK: {{^}}union X { int x; float y; };
97 CHECK: {{^}}^~~~~{{$}}
98 CHECK: {{^}}class{{$}}
99 CHECK: note: previous use is here
103 CHECK: warning: 'Y' defined as a class template here but
104 previously declared as a struct template
105 CHECK: {{^}}template<class U> class Y { };
107 CHECK: note: did you mean class here?
108 CHECK: {{^}}template<typename T> struct Y;
109 CHECK: {{^}} ^~~~~~{{$}}
110 CHECK: {{^}} class{{$}}
112 CHECK: warning: struct 'A' was previously declared as a class
113 CHECK: {{^}}struct A;
115 CHECK: note: previous use is here
119 CHECK: warning: struct 'B' was previously declared as a class
120 CHECK: {{^}}struct B;
122 CHECK: note: previous use is here
125 CHECK: 'B' defined as a struct here but previously declared as a class
126 CHECK: {{^}}struct B {};
128 CHECK: note: did you mean struct here?
130 CHECK: {{^}}^~~~~{{$}}
131 CHECK: {{^}}struct{{$}}
132 CHECK: note: did you mean struct here?
134 CHECK: {{^}}^~~~~{{$}}
135 CHECK: {{^}}struct{{$}}
137 CHECK: warning: struct 'C' was previously declared as a class
138 CHECK: {{^}}struct C;
140 CHECK: note: previous use is here
143 CHECK: warning: class 'C' was previously declared as a struct
146 CHECK: note: previous use is here
147 CHECK: {{^}}struct C;
149 CHECK: warning: struct 'C' was previously declared as a class
150 CHECK: {{^}}struct C;
152 CHECK: note: previous use is here
155 CHECK: warning: 'C' defined as a class here but previously declared as a struct
156 CHECK: {{^}}class C {};
158 CHECK: note: did you mean class here?
159 CHECK: {{^}}struct C;
160 CHECK: {{^}}^~~~~~{{$}}
161 CHECK: {{^}}class{{$}}
162 CHECK: note: did you mean class here?
163 CHECK: {{^}}struct C;
164 CHECK: {{^}}^~~~~~{{$}}
165 CHECK: {{^}}class{{$}}
167 CHECK: error: redefinition of 'D'
168 CHECK: {{^}}class D {};
170 CHECK: note: previous definition is here
171 CHECK: {{^}}struct D {};
173 CHECK: warning: class 'D' was previously declared as a struct
176 CHECK: note: previous use is here
177 CHECK: {{^}}struct D {};
179 CHECK: note: did you mean struct here?
181 CHECK: {{^}}^~~~~{{$}}
182 CHECK: {{^}}struct{{$}}
186 CHECK: warning: struct template 'G' was previously declared as a class template
187 CHECK: {{^}}template<class U> struct G;
189 CHECK: note: previous use is here
190 CHECK: {{^}}template<class U> class G;
192 CHECK: warning: 'G' defined as a struct template here but previously declared as a class template
193 CHECK: {{^}}template<class U> struct G {};
195 CHECK: note: did you mean struct here?
196 CHECK: {{^}}template<class U> class G;