xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/struct-class-redecl.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
2f4a2713aSLionel Sambuc // RUN: not %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
3f4a2713aSLionel Sambuc class X; // expected-note 2{{here}}
4f4a2713aSLionel Sambuc typedef struct X * X_t; // expected-warning{{previously declared}}
5f4a2713aSLionel Sambuc union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc template<typename T> struct Y; // expected-note{{did you mean class here?}}
8f4a2713aSLionel Sambuc template<class U> class Y { }; // expected-warning{{previously declared}}
9f4a2713aSLionel Sambuc 
10*0a6a1f1dSLionel Sambuc template <typename>
11*0a6a1f1dSLionel Sambuc struct Z {   // expected-note{{previous definition is here}}
12*0a6a1f1dSLionel Sambuc   struct Z { // expected-error{{nested redefinition of 'Z'}}
13*0a6a1f1dSLionel Sambuc   };
14*0a6a1f1dSLionel Sambuc };
15*0a6a1f1dSLionel Sambuc 
16f4a2713aSLionel Sambuc class A;
17f4a2713aSLionel Sambuc class A;  // expected-note{{previous use is here}}
18f4a2713aSLionel Sambuc struct A;  // expected-warning{{struct 'A' was previously declared as a class}}
19f4a2713aSLionel Sambuc 
20f4a2713aSLionel Sambuc class B;  // expected-note{{did you mean struct here?}}
21f4a2713aSLionel Sambuc class B;  // expected-note{{previous use is here}}\
22f4a2713aSLionel Sambuc           // expected-note{{did you mean struct here?}}
23f4a2713aSLionel Sambuc struct B;  // expected-warning{{struct 'B' was previously declared as a class}}
24f4a2713aSLionel Sambuc struct B {};  // expected-warning{{'B' defined as a struct here but previously declared as a class}}
25f4a2713aSLionel Sambuc 
26f4a2713aSLionel Sambuc class C;  // expected-note{{previous use is here}}
27f4a2713aSLionel Sambuc struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
28f4a2713aSLionel Sambuc            // expected-note{{previous use is here}}\
29f4a2713aSLionel Sambuc            // expected-note{{did you mean class here?}}
30f4a2713aSLionel Sambuc class C;  // expected-warning{{class 'C' was previously declared as a struct}}\
31f4a2713aSLionel Sambuc           // expected-note{{previous use is here}}
32f4a2713aSLionel Sambuc struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
33f4a2713aSLionel Sambuc            // expected-note{{did you mean class here?}}
34f4a2713aSLionel Sambuc class C {};  // expected-warning{{'C' defined as a class here but previously declared as a struct}}
35f4a2713aSLionel Sambuc 
36f4a2713aSLionel Sambuc struct D {};  // expected-note{{previous definition is here}}\
37f4a2713aSLionel Sambuc               // expected-note{{previous use is here}}
38f4a2713aSLionel Sambuc class D {};  // expected-error{{redefinition of 'D'}}
39f4a2713aSLionel Sambuc struct D;
40f4a2713aSLionel Sambuc class D;  // expected-warning{{class 'D' was previously declared as a struct}}\
41f4a2713aSLionel Sambuc           // expected-note{{did you mean struct here?}}
42f4a2713aSLionel Sambuc 
43f4a2713aSLionel Sambuc class E;
44f4a2713aSLionel Sambuc class E;
45f4a2713aSLionel Sambuc class E {};
46f4a2713aSLionel Sambuc class E;
47f4a2713aSLionel Sambuc 
48f4a2713aSLionel Sambuc struct F;
49f4a2713aSLionel Sambuc struct F;
50f4a2713aSLionel Sambuc struct F {};
51f4a2713aSLionel Sambuc struct F;
52f4a2713aSLionel Sambuc 
53f4a2713aSLionel Sambuc template<class U> class G;  // expected-note{{previous use is here}}\
54f4a2713aSLionel Sambuc                             // expected-note{{did you mean struct here?}}
55f4a2713aSLionel Sambuc template<class U> struct G;  // expected-warning{{struct template 'G' was previously declared as a class template}}
56f4a2713aSLionel Sambuc template<class U> struct G {};  // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc /*
59f4a2713aSLionel Sambuc *** 'X' messages ***
60f4a2713aSLionel Sambuc CHECK: warning: struct 'X' was previously declared as a class
61f4a2713aSLionel Sambuc CHECK: {{^}}typedef struct X * X_t;
62f4a2713aSLionel Sambuc CHECK: {{^}}        ^{{$}}
63f4a2713aSLionel Sambuc CHECK: note: previous use is here
64f4a2713aSLionel Sambuc CHECK: {{^}}class X;
65f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
66f4a2713aSLionel Sambuc CHECK: error: use of 'X' with tag type that does not match previous declaration
67f4a2713aSLionel Sambuc CHECK: {{^}}union X { int x; float y; };
68f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~{{$}}
69f4a2713aSLionel Sambuc CHECK: {{^}}class{{$}}
70f4a2713aSLionel Sambuc CHECK: note: previous use is here
71f4a2713aSLionel Sambuc CHECK: {{^}}class X;
72f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
73f4a2713aSLionel Sambuc *** 'Y' messages ***
74f4a2713aSLionel Sambuc CHECK: warning: 'Y' defined as a class template here but
75f4a2713aSLionel Sambuc       previously declared as a struct template
76f4a2713aSLionel Sambuc CHECK: {{^}}template<class U> class Y { };
77f4a2713aSLionel Sambuc CHECK: {{^}}                  ^{{$}}
78f4a2713aSLionel Sambuc CHECK: note: did you mean class here?
79f4a2713aSLionel Sambuc CHECK: {{^}}template<typename T> struct Y;
80f4a2713aSLionel Sambuc CHECK: {{^}}                     ^~~~~~{{$}}
81f4a2713aSLionel Sambuc CHECK: {{^}}                     class{{$}}
82f4a2713aSLionel Sambuc *** 'A' messages ***
83f4a2713aSLionel Sambuc CHECK: warning: struct 'A' was previously declared as a class
84f4a2713aSLionel Sambuc CHECK: {{^}}struct A;
85f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
86f4a2713aSLionel Sambuc CHECK: note: previous use is here
87f4a2713aSLionel Sambuc CHECK: {{^}}class A;
88f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
89f4a2713aSLionel Sambuc *** 'B' messages ***
90f4a2713aSLionel Sambuc CHECK: warning: struct 'B' was previously declared as a class
91f4a2713aSLionel Sambuc CHECK: {{^}}struct B;
92f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
93f4a2713aSLionel Sambuc CHECK: note: previous use is here
94f4a2713aSLionel Sambuc CHECK: {{^}}class B;
95f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
96f4a2713aSLionel Sambuc CHECK: 'B' defined as a struct here but previously declared as a class
97f4a2713aSLionel Sambuc CHECK: {{^}}struct B {};
98f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
99f4a2713aSLionel Sambuc CHECK: note: did you mean struct here?
100f4a2713aSLionel Sambuc CHECK: {{^}}class B;
101f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~{{$}}
102f4a2713aSLionel Sambuc CHECK: {{^}}struct{{$}}
103f4a2713aSLionel Sambuc CHECK: note: did you mean struct here?
104f4a2713aSLionel Sambuc CHECK: {{^}}class B;
105f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~{{$}}
106f4a2713aSLionel Sambuc CHECK: {{^}}struct{{$}}
107f4a2713aSLionel Sambuc *** 'C' messages ***
108f4a2713aSLionel Sambuc CHECK: warning: struct 'C' was previously declared as a class
109f4a2713aSLionel Sambuc CHECK: {{^}}struct C;
110f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
111f4a2713aSLionel Sambuc CHECK: note: previous use is here
112f4a2713aSLionel Sambuc CHECK: {{^}}class C;
113f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
114f4a2713aSLionel Sambuc CHECK: warning: class 'C' was previously declared as a struct
115f4a2713aSLionel Sambuc CHECK: {{^}}class C;
116f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
117f4a2713aSLionel Sambuc CHECK: note: previous use is here
118f4a2713aSLionel Sambuc CHECK: {{^}}struct C;
119f4a2713aSLionel Sambuc CHECK: {{^}}       ^{{$}}
120f4a2713aSLionel Sambuc CHECK: warning: struct 'C' was previously declared as a class
121f4a2713aSLionel Sambuc CHECK: {{^}}struct C;
122f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
123f4a2713aSLionel Sambuc CHECK: note: previous use is here
124f4a2713aSLionel Sambuc CHECK: {{^}}class C;
125f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
126f4a2713aSLionel Sambuc CHECK: warning: 'C' defined as a class here but previously declared as a struct
127f4a2713aSLionel Sambuc CHECK: {{^}}class C {};
128f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
129f4a2713aSLionel Sambuc CHECK: note: did you mean class here?
130f4a2713aSLionel Sambuc CHECK: {{^}}struct C;
131f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~~{{$}}
132f4a2713aSLionel Sambuc CHECK: {{^}}class{{$}}
133f4a2713aSLionel Sambuc CHECK: note: did you mean class here?
134f4a2713aSLionel Sambuc CHECK: {{^}}struct C;
135f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~~{{$}}
136f4a2713aSLionel Sambuc CHECK: {{^}}class{{$}}
137f4a2713aSLionel Sambuc *** 'D' messages ***
138f4a2713aSLionel Sambuc CHECK: error: redefinition of 'D'
139f4a2713aSLionel Sambuc CHECK: {{^}}class D {};
140f4a2713aSLionel Sambuc CHECK: {{^}}      ^{{$}}
141f4a2713aSLionel Sambuc CHECK: note: previous definition is here
142f4a2713aSLionel Sambuc CHECK: {{^}}struct D {};
143f4a2713aSLionel Sambuc CHECK: {{^}}       ^{{$}}
144f4a2713aSLionel Sambuc CHECK: warning: class 'D' was previously declared as a struct
145f4a2713aSLionel Sambuc CHECK: {{^}}class D;
146f4a2713aSLionel Sambuc CHECK: {{^}}^{{$}}
147f4a2713aSLionel Sambuc CHECK: note: previous use is here
148f4a2713aSLionel Sambuc CHECK: {{^}}struct D {};
149f4a2713aSLionel Sambuc CHECK: {{^}}       ^{{$}}
150f4a2713aSLionel Sambuc CHECK: note: did you mean struct here?
151f4a2713aSLionel Sambuc CHECK: {{^}}class D;
152f4a2713aSLionel Sambuc CHECK: {{^}}^~~~~{{$}}
153f4a2713aSLionel Sambuc CHECK: {{^}}struct{{$}}
154f4a2713aSLionel Sambuc *** 'E' messages ***
155f4a2713aSLionel Sambuc *** 'F' messages ***
156f4a2713aSLionel Sambuc *** 'G' messages ***
157f4a2713aSLionel Sambuc CHECK: warning: struct template 'G' was previously declared as a class template
158f4a2713aSLionel Sambuc CHECK: {{^}}template<class U> struct G;
159f4a2713aSLionel Sambuc CHECK: {{^}}                  ^{{$}}
160f4a2713aSLionel Sambuc CHECK: note: previous use is here
161f4a2713aSLionel Sambuc CHECK: {{^}}template<class U> class G;
162f4a2713aSLionel Sambuc CHECK: {{^}}                        ^{{$}}
163f4a2713aSLionel Sambuc CHECK: warning: 'G' defined as a struct template here but previously declared as a class template
164f4a2713aSLionel Sambuc CHECK: {{^}}template<class U> struct G {};
165f4a2713aSLionel Sambuc CHECK: {{^}}                  ^{{$}}
166f4a2713aSLionel Sambuc CHECK: note: did you mean struct here?
167f4a2713aSLionel Sambuc CHECK: {{^}}template<class U> class G;
168f4a2713aSLionel Sambuc CHECK: {{^}}                  ^~~~~
169f4a2713aSLionel Sambuc CHECK: {{^}}                  struct
170f4a2713aSLionel Sambuc */
171