blob: 06272504bc53e4b815226cace82e962699fa6cf3 [file] [log] [blame]
Richard Smith2603b092012-11-15 22:54:20 +00001// RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic -fcxx-exceptions -fexceptions %s
Chris Lattner869c6612009-04-12 22:23:27 +00002
Aaron Ballman3731b332012-08-28 20:55:40 +00003const char const *x10; // expected-warning {{duplicate 'const' declaration specifier}}
4
Chris Lattner869c6612009-04-12 22:23:27 +00005int x(*g); // expected-error {{use of undeclared identifier 'g'}}
Chris Lattner1c428032009-12-07 01:36:53 +00006
Chris Lattner244b96b2009-12-10 02:02:58 +00007struct Type {
8 int Type;
9};
Chris Lattner17c3b1f2009-12-10 01:59:24 +000010
Argyrios Kyrtzidis20ee5ae2010-11-16 18:18:13 +000011// rdar://8365458
Fariborz Jahanian2b059992011-04-19 21:42:37 +000012// rdar://9132143
13typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
Chris Lattner1c428032009-12-07 01:36:53 +000014
15// PR4451 - We should recover well from the typo of '::' as ':' in a2.
16namespace y {
Chris Lattner3c674cf2009-12-10 02:08:07 +000017 struct a { };
18 typedef int b;
Chris Lattner1c428032009-12-07 01:36:53 +000019}
20
21y::a a1;
22y:a a2; // expected-error {{unexpected ':' in nested name specifier}}
23y::a a3 = a2;
24
25// Some valid colons:
26void foo() {
27y: // label
28 y::a s;
29
30 int a = 4;
31 a = a ? a : a+1;
32}
33
34struct b : y::a {};
35
36template <typename T>
37class someclass {
38
39 int bar() {
40 T *P;
41 return 1 ? P->x : P->y;
42 }
43};
Chris Lattner17c3b1f2009-12-10 01:59:24 +000044
Chris Lattnerf3d3b362010-06-13 05:34:18 +000045class asm_class_test {
46 void foo() __asm__("baz");
47};
48
Richard Smith87f5dc52012-07-23 05:45:25 +000049enum { fooenum = 1, }; // expected-warning {{commas at the end of enumerator lists are a C++11 extension}}
Chris Lattner17c3b1f2009-12-10 01:59:24 +000050
51struct a {
52 int Type : fooenum;
53};
54
Chris Lattner244b96b2009-12-10 02:02:58 +000055void test(struct Type *P) {
56 int Type;
57 Type = 1 ? P->Type : Type;
Chris Lattner3c674cf2009-12-10 02:08:07 +000058
59 Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
60 Type = 1 ? (
61 (y:b) // expected-error {{unexpected ':' in nested name specifier}}
62 4) : 5;
Daniel Dunbar8fbe78f2009-12-15 20:14:24 +000063}
Chris Lattner916dbf12010-02-02 00:43:15 +000064
65struct test4 {
66 int x // expected-error {{expected ';' at end of declaration list}}
67 int y;
68 int z // expected-error {{expected ';' at end of declaration list}}
69};
John McCall8bc2a702010-03-01 18:20:46 +000070
Richard Smith09f76ee2011-10-19 21:33:05 +000071// Make sure we know these are legitimate commas and not typos for ';'.
72namespace Commas {
73 struct S {
74 static int a;
75 int c,
76 operator()();
77 };
78
79 int global1,
80 __attribute__(()) global2,
81 (global5),
82 *global6,
83 &global7 = global1,
84 &&global8 = static_cast<int&&>(global1), // expected-warning 2{{rvalue reference}}
85 S::a,
86 global9,
87 global10 = 0,
88 global11 == 0, // expected-error {{did you mean '='}}
89 global12 __attribute__(()),
90 global13(0),
91 global14[2],
92 global15;
93
94 void g() {
95 static int a,
96 b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
97 Statics:return;
98 }
99}
100
John McCall8bc2a702010-03-01 18:20:46 +0000101// PR5825
102struct test5 {};
103::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
Chris Lattner005fc1b2010-04-05 18:18:31 +0000104
105
106// PR6782
107template<class T>
108class Class1;
109
110class Class2 {
111} // no ;
112
113typedef Class1<Class2> Type1; // expected-error {{cannot combine with previous 'class' declaration specifier}}
Fariborz Jahanian055068d2010-08-16 17:58:53 +0000114
115// rdar : // 8307865
116struct CodeCompleteConsumer {
117};
118
119void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
120}
Chris Lattner07865442010-11-09 20:14:26 +0000121
122;
123
Richard Smith4f605af2012-08-18 00:55:03 +0000124// PR4111
125void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}
126
Richard Smith2603b092012-11-15 22:54:20 +0000127// PR9903
128struct S {
129 typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
130 typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
131 int n, m;
132 typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
133};
134
Nico Weber0bba2d12013-01-18 18:41:42 +0000135
136namespace TestIsValidAfterTypeSpecifier {
Richard Smith1ac67d12013-01-19 03:48:05 +0000137struct s {} v;
Nico Weber0bba2d12013-01-18 18:41:42 +0000138
139namespace a {
140struct s operator++(struct s a)
141{ return a; }
142}
143
144namespace b {
145// The newline after s should make no difference.
146struct s
147operator++(struct s a)
148{ return a; }
149}
150
Richard Smith1ac67d12013-01-19 03:48:05 +0000151struct X {
152 struct s
153 friend f();
154 struct s
155 virtual f();
156};
157
158struct s
159&r0 = v;
160struct s
161bitand r2 = v;
162
Nico Weber0bba2d12013-01-18 18:41:42 +0000163}
164
Richard Trieu9c672672013-01-26 02:31:38 +0000165struct DIE {
166 void foo() {}
167};
168
169void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
170 DIE.foo(); // expected-error {{cannot use dot operator on a type}}
171 die.foo();
172
173 DIE->foo(); // expected-error {{cannot use arrow operator on a type}}
174 Die->foo();
175
176 int.foo(); // expected-error {{cannot use dot operator on a type}}
177 INT.foo();
178
179 float->foo(); // expected-error {{cannot use arrow operator on a type}}
180 FLOAT->foo();
181}
182
Richard Smith52c5b872013-01-29 04:13:32 +0000183namespace PR15017 {
184 template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' can not be defined in a type specifier}}
185}
186
Richard Smith4cabd042013-02-22 09:15:49 +0000187// Ensure we produce at least some diagnostic for attributes in C++98.
188[[]] struct S; // expected-error 2{{}}
189
Richard Trieu2f586962013-09-05 02:31:33 +0000190namespace test7 {
191 struct Foo {
192 void a();
193 void b();
194 };
195
196 void Foo::
197 // Comment!
198 a() {}
199
200
201 void Foo:: // expected-error {{expected unqualified-id}}
202 // Comment!
203}
204
Benjamin Kramer5fc787f2013-10-10 12:24:40 +0000205void test8() {
206 struct {} o;
207 // This used to crash.
208 (&o)->(); // expected-error{{expected unqualified-id}}
209}
210
Richard Smith9ce302e2013-07-11 05:10:21 +0000211namespace PR5066 {
212 template<typename T> struct X {};
213 X<int N> x; // expected-error {{type-id cannot have a name}}
214
215 using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-warning {{C++11}}
216}
217
David Majnemera5e92552013-09-22 01:24:26 +0000218namespace PR17255 {
219void foo() {
220 typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} \
221 // expected-error {{expected a qualified name after 'typename'}} \
222 // expected-warning {{'template' keyword outside of a template}}
223}
224}
225
Richard Smithfb8b7b92013-10-15 00:00:26 +0000226namespace PR17567 {
227 struct Foobar { // expected-note 2{{declared here}}
228 FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
229 ~FooBar(); // expected-error {{expected the class name after '~' to name a destructor}}
230 };
231 FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
232 FooBar::~FooBar() {} // expected-error {{undeclared}} expected-error {{expected the class name}}
233}
234
Chris Lattner07865442010-11-09 20:14:26 +0000235// PR8380
236extern "" // expected-error {{unknown linkage language}}
237test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \
238 // expected-error {{expected ';' after top level declarator}}
239
240 int test6b;