summaryrefslogtreecommitdiff
path: root/clang/test/SemaCXX/struct-class-redecl.cpp
blob: 5c59578d6eb5aa3d92e7d83b1d17c6e1b76a2617 (about) (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags -verify %s
// RUN: %clang_cc1 -fsyntax-only -Wmismatched-tags %s 2>&1 | FileCheck %s
class X; // expected-note 2{{here}}
typedef struct X * X_t; // expected-warning{{previously declared}}
union X { int x; float y; }; // expected-error{{use of 'X' with tag type that does not match previous declaration}}

template<typename T> struct Y; // expected-note{{did you mean class here?}}
template<class U> class Y { }; // expected-warning{{previously declared}}

class A;
class A;  // expected-note{{previous use is here}}
struct A;  // expected-warning{{struct 'A' was previously declared as a class}}

class B;  // expected-note{{did you mean struct here?}}
class B;  // expected-note{{previous use is here}}\
          // expected-note{{did you mean struct here?}}
struct B;  // expected-warning{{struct 'B' was previously declared as a class}}
struct B {};  // expected-warning{{'B' defined as a struct here but previously declared as a class}}

class C;  // expected-note{{previous use is here}}
struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
           // expected-note{{previous use is here}}\
           // expected-note{{did you mean class here?}}
class C;  // expected-warning{{class 'C' was previously declared as a struct}}\
          // expected-note{{previous use is here}}
struct C;  // expected-warning{{struct 'C' was previously declared as a class}}\
           // expected-note{{did you mean class here?}}
class C {};  // expected-warning{{'C' defined as a class here but previously declared as a struct}}

struct D {};  // expected-note{{previous definition is here}}\
              // expected-note{{previous use is here}}
class D {};  // expected-error{{redefinition of 'D'}}
struct D;
class D;  // expected-warning{{class 'D' was previously declared as a struct}}\
          // expected-note{{did you mean struct here?}}

class E;
class E;
class E {};
class E;

struct F;
struct F;
struct F {};
struct F;

template<class U> class G;  // expected-note{{previous use is here}}\
                            // expected-note{{did you mean struct here?}}
template<class U> struct G;  // expected-warning{{struct template 'G' was previously declared as a class template}}
template<class U> struct G {};  // expected-warning{{'G' defined as a struct template here but previously declared as a class template}}

/*
*** 'X' messages ***
CHECK: warning: struct 'X' was previously declared as a class
CHECK: {{^}}typedef struct X * X_t;
CHECK: {{^}}        ^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class X;
CHECK: {{^}}      ^{{$}}
CHECK: error: use of 'X' with tag type that does not match previous declaration
CHECK: {{^}}union X { int x; float y; };
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}class{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class X;
CHECK: {{^}}      ^{{$}}
*** 'Y' messages ***
CHECK: warning: 'Y' defined as a class template here but
      previously declared as a struct template
CHECK: {{^}}template<class U> class Y { };
CHECK: {{^}}                  ^{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}template<typename T> struct Y;
CHECK: {{^}}                     ^~~~~~{{$}}
CHECK: {{^}}                     class{{$}}
*** 'A' messages ***
CHECK: warning: struct 'A' was previously declared as a class
CHECK: {{^}}struct A;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class A;
CHECK: {{^}}      ^{{$}}
*** 'B' messages ***
CHECK: warning: struct 'B' was previously declared as a class
CHECK: {{^}}struct B;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class B;
CHECK: {{^}}      ^{{$}}
CHECK: 'B' defined as a struct here but previously declared as a class
CHECK: {{^}}struct B {};
CHECK: {{^}}^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class B;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class B;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
*** 'C' messages ***
CHECK: warning: struct 'C' was previously declared as a class
CHECK: {{^}}struct C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class C;
CHECK: {{^}}      ^{{$}}
CHECK: warning: class 'C' was previously declared as a struct
CHECK: {{^}}class C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}struct C;
CHECK: {{^}}       ^{{$}}
CHECK: warning: struct 'C' was previously declared as a class
CHECK: {{^}}struct C;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}class C;
CHECK: {{^}}      ^{{$}}
CHECK: warning: 'C' defined as a class here but previously declared as a struct
CHECK: {{^}}class C {};
CHECK: {{^}}^{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}struct C;
CHECK: {{^}}^~~~~~{{$}}
CHECK: {{^}}class{{$}}
CHECK: note: did you mean class here?
CHECK: {{^}}struct C;
CHECK: {{^}}^~~~~~{{$}}
CHECK: {{^}}class{{$}}
*** 'D' messages ***
CHECK: error: redefinition of 'D'
CHECK: {{^}}class D {};
CHECK: {{^}}      ^{{$}}
CHECK: note: previous definition is here
CHECK: {{^}}struct D {};
CHECK: {{^}}       ^{{$}}
CHECK: warning: class 'D' was previously declared as a struct
CHECK: {{^}}class D;
CHECK: {{^}}^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}struct D {};
CHECK: {{^}}       ^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}class D;
CHECK: {{^}}^~~~~{{$}}
CHECK: {{^}}struct{{$}}
*** 'E' messages ***
*** 'F' messages ***
*** 'G' messages ***
CHECK: warning: struct template 'G' was previously declared as a class template
CHECK: {{^}}template<class U> struct G;
CHECK: {{^}}                  ^{{$}}
CHECK: note: previous use is here
CHECK: {{^}}template<class U> class G;
CHECK: {{^}}                        ^{{$}}
CHECK: warning: 'G' defined as a struct template here but previously declared as a class template
CHECK: {{^}}template<class U> struct G {};
CHECK: {{^}}                  ^{{$}}
CHECK: note: did you mean struct here?
CHECK: {{^}}template<class U> class G;
CHECK: {{^}}                  ^~~~~
CHECK: {{^}}                  struct
*/