cxx-decl.cpp
7.97 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions %s
// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++98 %s
// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -Wredundant-parens -pedantic-errors -fcxx-exceptions -fexceptions -std=c++11 %s
const char const *x10; // expected-error {{duplicate 'const' declaration specifier}}
int x(*g); // expected-error {{use of undeclared identifier 'g'}}
private int cplusplus_is_not_opencl; // expected-error {{expected unqualified-id}}
struct Type {
int Type;
};
// rdar://8365458
// rdar://9132143
typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
// PR4451 - We should recover well from the typo of '::' as ':' in a2.
namespace y {
struct a { };
typedef int b;
}
y::a a1;
y:a a2; // expected-error {{unexpected ':' in nested name specifier}}
y::a a3 = a2;
// Some valid colons:
void foo() {
y: // label
y::a s;
int a = 4;
a = a ? a : a+1;
}
struct b : y::a {};
template <typename T>
class someclass {
int bar() {
T *P;
return 1 ? P->x : P->y;
}
};
class asm_class_test {
void foo() __asm__("baz");
};
enum { fooenum = 1, };
#if __cplusplus <= 199711L
// expected-error@-2 {{commas at the end of enumerator lists are a C++11 extension}}
#endif
struct a {
int Type : fooenum;
};
void test(struct Type *P) {
int Type;
Type = 1 ? P->Type : Type;
Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
Type = 1 ? (
(y:b) // expected-error {{unexpected ':' in nested name specifier}}
4) : 5;
}
struct test4 {
int x // expected-error {{expected ';' at end of declaration list}}
int y;
int z // expected-error {{expected ';' at end of declaration list}}
};
// Make sure we know these are legitimate commas and not typos for ';'.
namespace Commas {
struct S {
static int a;
int c,
operator()();
};
int global1,
__attribute__(()) global2,
(global5), // expected-warning {{redundant parentheses surrounding declarator}}
*global6,
&global7 = global1,
&&global8 = static_cast<int&&>(global1),
#if __cplusplus <= 199711L
// expected-error@-2 2{{rvalue references are a C++11 extension}}
#endif
S::a,
global9,
global10 = 0,
global11 == 0, // expected-error {{did you mean '='}}
global12 __attribute__(()),
global13(0),
global14[2],
global15;
void g() {
static int a,
b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
Statics:return;
}
}
// PR5825
struct test5 {};
::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
// PR6782
template<class T>
class Class1;
class Class2 {
} // expected-error {{expected ';' after class}}
typedef Class1<Class2> Type1;
// rdar : // 8307865
struct CodeCompleteConsumer {
};
void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
}
;
// PR4111
void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}
// PR9903
struct S {
typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
int n, m;
typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
};
namespace TestIsValidAfterTypeSpecifier {
struct s {} v;
namespace a {
struct s operator++(struct s a)
{ return a; }
}
namespace b {
// The newline after s should make no difference.
struct s
operator++(struct s a)
{ return a; }
}
struct X {
struct s
friend f();
struct s
virtual f();
};
struct s
&r0 = v;
struct s
bitand r2 = v;
}
struct DIE {
void foo() {}
};
void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
DIE.foo(); // expected-error {{cannot use dot operator on a type}}
die.foo();
DIE->foo(); // expected-error {{cannot use arrow operator on a type}}
Die->foo();
int.foo(); // expected-error {{cannot use dot operator on a type}}
INT.foo();
float->foo(); // expected-error {{cannot use arrow operator on a type}}
FLOAT->foo();
}
namespace PR15017 {
template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}
}
// Ensure we produce at least some diagnostic for attributes in C++98.
[[]] struct S;
#if __cplusplus <= 199711L
// expected-error@-2 {{expected expression}}
// expected-error@-3 {{expected unqualified-id}}
#else
// expected-error@-5 {{misplaced attributes}}
#endif
namespace test7 {
struct Foo {
void a();
void b();
};
void Foo::
// Comment!
a() {}
void Foo:: // expected-error {{expected unqualified-id}}
// Comment!
}
void test8() {
struct {} o;
// This used to crash.
(&o)->(); // expected-error{{expected unqualified-id}}
}
namespace PR5066 {
template<typename T> struct X {};
X<int N> x; // expected-error {{type-id cannot have a name}}
using T = int (*T)(); // expected-error {{type-id cannot have a name}}
#if __cplusplus <= 199711L
// expected-error@-2 {{alias declarations are a C++11 extensio}}
#endif
}
namespace PR17255 {
void foo() {
typename A::template B<> c; // expected-error {{use of undeclared identifier 'A'}}
#if __cplusplus <= 199711L
// expected-error@-2 {{'template' keyword outside of a template}}
#endif
}
}
namespace PR17567 {
struct Foobar { // expected-note 2{{declared here}}
FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
~FooBar(); // expected-error {{undeclared identifier 'FooBar' in destructor name}}
};
FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
FooBar::~FooBar() {} // expected-error 2{{undeclared}}
}
namespace DuplicateFriend {
struct A {
friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}
friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}}
#if __cplusplus >= 201103L
// expected-error@-2 {{'friend' must appear first in a non-function declaration}}
#endif
};
}
namespace NNS {
struct A {};
namespace B { extern A C1, C2, *C3, C4[], C5; }
// Do not produce a redundant parentheses warning here; removing these parens
// changes the meaning of the program.
A (::NNS::B::C1);
A (NNS::B::C2); // expected-warning {{redundant parentheses surrounding declarator}}
A (*::NNS::B::C3); // expected-warning {{redundant parentheses surrounding declarator}}
A (::NNS::B::C4[2]);
// Removing one of these sets of parentheses would be reasonable.
A ((::NNS::B::C5)); // expected-warning {{redundant parentheses surrounding declarator}}
void f() {
// FIXME: A vexing-parse warning here would be useful.
A(::NNS::B::C1); // expected-error {{definition or redeclaration}}
A(NNS::B::C1); // expected-warning {{redundant paren}} expected-error {{definition or redeclaration}}
}
}
inline namespace ParensAroundFriend { // expected-error 0-1{{C++11}}
struct A {};
struct B {
static A C();
};
namespace X {
struct B {};
struct D {
// No warning here: while this could be written as
// friend (::B::C)();
// we do need parentheses *somewhere* here.
friend A (::B::C());
};
}
}
namespace rdar37099386 {
class A typename A; // expected-error {{expected a qualified name after 'typename'}}
// expected-error@-1 {{cannot combine with previous 'class' declaration specifier}}
}
// PR8380
extern "" // expected-error {{unknown linkage language}}
test6a { ;// expected-error {{C++ requires a type specifier for all declarations}}
#if __cplusplus <= 199711L
// expected-error@-2 {{expected ';' after top level declarator}}
#else
// expected-error@-4 {{expected expression}}
// expected-note@-5 {{to match this}}
#endif
int test6b;
#if __cplusplus >= 201103L
// expected-error@+3 {{expected}}
// expected-error@-3 {{expected ';' after top level declarator}}
#endif