1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -verify -fsyntax-only -triple i386-linux -pedantic-errors -fcxx-exceptions -fexceptions %s
2f4a2713aSLionel Sambuc
3*0a6a1f1dSLionel Sambuc const char const *x10; // expected-error {{duplicate 'const' declaration specifier}}
4f4a2713aSLionel Sambuc
5f4a2713aSLionel Sambuc int x(*g); // expected-error {{use of undeclared identifier 'g'}}
6f4a2713aSLionel Sambuc
7f4a2713aSLionel Sambuc struct Type {
8f4a2713aSLionel Sambuc int Type;
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc
11f4a2713aSLionel Sambuc // rdar://8365458
12f4a2713aSLionel Sambuc // rdar://9132143
13f4a2713aSLionel Sambuc typedef char bool; // expected-error {{redeclaration of C++ built-in type 'bool'}}
14f4a2713aSLionel Sambuc
15f4a2713aSLionel Sambuc // PR4451 - We should recover well from the typo of '::' as ':' in a2.
16f4a2713aSLionel Sambuc namespace y {
17f4a2713aSLionel Sambuc struct a { };
18f4a2713aSLionel Sambuc typedef int b;
19f4a2713aSLionel Sambuc }
20f4a2713aSLionel Sambuc
21f4a2713aSLionel Sambuc y::a a1;
22f4a2713aSLionel Sambuc y:a a2; // expected-error {{unexpected ':' in nested name specifier}}
23f4a2713aSLionel Sambuc y::a a3 = a2;
24f4a2713aSLionel Sambuc
25f4a2713aSLionel Sambuc // Some valid colons:
foo()26f4a2713aSLionel Sambuc void foo() {
27f4a2713aSLionel Sambuc y: // label
28f4a2713aSLionel Sambuc y::a s;
29f4a2713aSLionel Sambuc
30f4a2713aSLionel Sambuc int a = 4;
31f4a2713aSLionel Sambuc a = a ? a : a+1;
32f4a2713aSLionel Sambuc }
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc struct b : y::a {};
35f4a2713aSLionel Sambuc
36f4a2713aSLionel Sambuc template <typename T>
37f4a2713aSLionel Sambuc class someclass {
38f4a2713aSLionel Sambuc
bar()39f4a2713aSLionel Sambuc int bar() {
40f4a2713aSLionel Sambuc T *P;
41f4a2713aSLionel Sambuc return 1 ? P->x : P->y;
42f4a2713aSLionel Sambuc }
43f4a2713aSLionel Sambuc };
44f4a2713aSLionel Sambuc
45f4a2713aSLionel Sambuc class asm_class_test {
46f4a2713aSLionel Sambuc void foo() __asm__("baz");
47f4a2713aSLionel Sambuc };
48f4a2713aSLionel Sambuc
49*0a6a1f1dSLionel Sambuc enum { fooenum = 1, }; // expected-error {{commas at the end of enumerator lists are a C++11 extension}}
50f4a2713aSLionel Sambuc
51f4a2713aSLionel Sambuc struct a {
52f4a2713aSLionel Sambuc int Type : fooenum;
53f4a2713aSLionel Sambuc };
54f4a2713aSLionel Sambuc
test(struct Type * P)55f4a2713aSLionel Sambuc void test(struct Type *P) {
56f4a2713aSLionel Sambuc int Type;
57f4a2713aSLionel Sambuc Type = 1 ? P->Type : Type;
58f4a2713aSLionel Sambuc
59f4a2713aSLionel Sambuc Type = (y:b) 4; // expected-error {{unexpected ':' in nested name specifier}}
60f4a2713aSLionel Sambuc Type = 1 ? (
61f4a2713aSLionel Sambuc (y:b) // expected-error {{unexpected ':' in nested name specifier}}
62f4a2713aSLionel Sambuc 4) : 5;
63f4a2713aSLionel Sambuc }
64f4a2713aSLionel Sambuc
65f4a2713aSLionel Sambuc struct test4 {
66f4a2713aSLionel Sambuc int x // expected-error {{expected ';' at end of declaration list}}
67f4a2713aSLionel Sambuc int y;
68f4a2713aSLionel Sambuc int z // expected-error {{expected ';' at end of declaration list}}
69f4a2713aSLionel Sambuc };
70f4a2713aSLionel Sambuc
71f4a2713aSLionel Sambuc // Make sure we know these are legitimate commas and not typos for ';'.
72f4a2713aSLionel Sambuc namespace Commas {
73f4a2713aSLionel Sambuc struct S {
74f4a2713aSLionel Sambuc static int a;
75f4a2713aSLionel Sambuc int c,
76f4a2713aSLionel Sambuc operator()();
77f4a2713aSLionel Sambuc };
78f4a2713aSLionel Sambuc
79f4a2713aSLionel Sambuc int global1,
80f4a2713aSLionel Sambuc __attribute__(()) global2,
81f4a2713aSLionel Sambuc (global5),
82f4a2713aSLionel Sambuc *global6,
83f4a2713aSLionel Sambuc &global7 = global1,
84*0a6a1f1dSLionel Sambuc &&global8 = static_cast<int&&>(global1), // expected-error 2{{rvalue reference}}
85f4a2713aSLionel Sambuc S::a,
86f4a2713aSLionel Sambuc global9,
87f4a2713aSLionel Sambuc global10 = 0,
88f4a2713aSLionel Sambuc global11 == 0, // expected-error {{did you mean '='}}
89f4a2713aSLionel Sambuc global12 __attribute__(()),
90f4a2713aSLionel Sambuc global13(0),
91f4a2713aSLionel Sambuc global14[2],
92f4a2713aSLionel Sambuc global15;
93f4a2713aSLionel Sambuc
g()94f4a2713aSLionel Sambuc void g() {
95f4a2713aSLionel Sambuc static int a,
96f4a2713aSLionel Sambuc b __asm__("ebx"), // expected-error {{expected ';' at end of declaration}}
97f4a2713aSLionel Sambuc Statics:return;
98f4a2713aSLionel Sambuc }
99f4a2713aSLionel Sambuc }
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc // PR5825
102f4a2713aSLionel Sambuc struct test5 {};
103f4a2713aSLionel Sambuc ::new(static_cast<void*>(0)) test5; // expected-error {{expected unqualified-id}}
104f4a2713aSLionel Sambuc
105f4a2713aSLionel Sambuc
106f4a2713aSLionel Sambuc // PR6782
107f4a2713aSLionel Sambuc template<class T>
108f4a2713aSLionel Sambuc class Class1;
109f4a2713aSLionel Sambuc
110f4a2713aSLionel Sambuc class Class2 {
111f4a2713aSLionel Sambuc } // expected-error {{expected ';' after class}}
112f4a2713aSLionel Sambuc
113f4a2713aSLionel Sambuc typedef Class1<Class2> Type1;
114f4a2713aSLionel Sambuc
115f4a2713aSLionel Sambuc // rdar : // 8307865
116f4a2713aSLionel Sambuc struct CodeCompleteConsumer {
117f4a2713aSLionel Sambuc };
118f4a2713aSLionel Sambuc
119f4a2713aSLionel Sambuc void CodeCompleteConsumer::() { // expected-error {{xpected unqualified-id}}
120f4a2713aSLionel Sambuc }
121f4a2713aSLionel Sambuc
122f4a2713aSLionel Sambuc ;
123f4a2713aSLionel Sambuc
124f4a2713aSLionel Sambuc // PR4111
125f4a2713aSLionel Sambuc void f(sqrgl); // expected-error {{unknown type name 'sqrgl'}}
126f4a2713aSLionel Sambuc
127f4a2713aSLionel Sambuc // PR9903
128f4a2713aSLionel Sambuc struct S {
129f4a2713aSLionel Sambuc typedef void a() { }; // expected-error {{function definition declared 'typedef'}}
130f4a2713aSLionel Sambuc typedef void c() try { } catch(...) { } // expected-error {{function definition declared 'typedef'}}
131f4a2713aSLionel Sambuc int n, m;
132f4a2713aSLionel Sambuc typedef S() : n(1), m(2) { } // expected-error {{function definition declared 'typedef'}}
133f4a2713aSLionel Sambuc };
134f4a2713aSLionel Sambuc
135f4a2713aSLionel Sambuc
136f4a2713aSLionel Sambuc namespace TestIsValidAfterTypeSpecifier {
137f4a2713aSLionel Sambuc struct s {} v;
138f4a2713aSLionel Sambuc
139f4a2713aSLionel Sambuc namespace a {
140f4a2713aSLionel Sambuc struct s operator++(struct s a)
141f4a2713aSLionel Sambuc { return a; }
142f4a2713aSLionel Sambuc }
143f4a2713aSLionel Sambuc
144f4a2713aSLionel Sambuc namespace b {
145f4a2713aSLionel Sambuc // The newline after s should make no difference.
146f4a2713aSLionel Sambuc struct s
147f4a2713aSLionel Sambuc operator++(struct s a)
148f4a2713aSLionel Sambuc { return a; }
149f4a2713aSLionel Sambuc }
150f4a2713aSLionel Sambuc
151f4a2713aSLionel Sambuc struct X {
152f4a2713aSLionel Sambuc struct s
153f4a2713aSLionel Sambuc friend f();
154f4a2713aSLionel Sambuc struct s
155f4a2713aSLionel Sambuc virtual f();
156f4a2713aSLionel Sambuc };
157f4a2713aSLionel Sambuc
158f4a2713aSLionel Sambuc struct s
159f4a2713aSLionel Sambuc &r0 = v;
160f4a2713aSLionel Sambuc struct s
161f4a2713aSLionel Sambuc bitand r2 = v;
162f4a2713aSLionel Sambuc
163f4a2713aSLionel Sambuc }
164f4a2713aSLionel Sambuc
165f4a2713aSLionel Sambuc struct DIE {
166f4a2713aSLionel Sambuc void foo() {}
167f4a2713aSLionel Sambuc };
168f4a2713aSLionel Sambuc
169f4a2713aSLionel Sambuc void test (DIE die, DIE *Die, DIE INT, DIE *FLOAT) {
170f4a2713aSLionel Sambuc DIE.foo(); // expected-error {{cannot use dot operator on a type}}
171f4a2713aSLionel Sambuc die.foo();
172f4a2713aSLionel Sambuc
173f4a2713aSLionel Sambuc DIE->foo(); // expected-error {{cannot use arrow operator on a type}}
174f4a2713aSLionel Sambuc Die->foo();
175f4a2713aSLionel Sambuc
176f4a2713aSLionel Sambuc int.foo(); // expected-error {{cannot use dot operator on a type}}
177f4a2713aSLionel Sambuc INT.foo();
178f4a2713aSLionel Sambuc
179f4a2713aSLionel Sambuc float->foo(); // expected-error {{cannot use arrow operator on a type}}
180f4a2713aSLionel Sambuc FLOAT->foo();
181f4a2713aSLionel Sambuc }
182f4a2713aSLionel Sambuc
183f4a2713aSLionel Sambuc namespace PR15017 {
184f4a2713aSLionel Sambuc template<typename T = struct X { int i; }> struct S {}; // expected-error {{'PR15017::X' cannot be defined in a type specifier}}
185f4a2713aSLionel Sambuc }
186f4a2713aSLionel Sambuc
187f4a2713aSLionel Sambuc // Ensure we produce at least some diagnostic for attributes in C++98.
188f4a2713aSLionel Sambuc [[]] struct S; // expected-error 2{{}}
189f4a2713aSLionel Sambuc
190f4a2713aSLionel Sambuc namespace test7 {
191f4a2713aSLionel Sambuc struct Foo {
192f4a2713aSLionel Sambuc void a();
193f4a2713aSLionel Sambuc void b();
194f4a2713aSLionel Sambuc };
195f4a2713aSLionel Sambuc
196f4a2713aSLionel Sambuc void Foo::
197f4a2713aSLionel Sambuc // Comment!
198f4a2713aSLionel Sambuc a() {}
199f4a2713aSLionel Sambuc
200f4a2713aSLionel Sambuc
201f4a2713aSLionel Sambuc void Foo:: // expected-error {{expected unqualified-id}}
202f4a2713aSLionel Sambuc // Comment!
203f4a2713aSLionel Sambuc }
204f4a2713aSLionel Sambuc
205f4a2713aSLionel Sambuc void test8() {
206f4a2713aSLionel Sambuc struct {} o;
207f4a2713aSLionel Sambuc // This used to crash.
208f4a2713aSLionel Sambuc (&o)->(); // expected-error{{expected unqualified-id}}
209f4a2713aSLionel Sambuc }
210f4a2713aSLionel Sambuc
211f4a2713aSLionel Sambuc namespace PR5066 {
212f4a2713aSLionel Sambuc template<typename T> struct X {};
213f4a2713aSLionel Sambuc X<int N> x; // expected-error {{type-id cannot have a name}}
214f4a2713aSLionel Sambuc
215*0a6a1f1dSLionel Sambuc using T = int (*T)(); // expected-error {{type-id cannot have a name}} expected-error {{C++11}}
216f4a2713aSLionel Sambuc }
217f4a2713aSLionel Sambuc
218f4a2713aSLionel Sambuc namespace PR17255 {
219f4a2713aSLionel Sambuc void foo() {
220f4a2713aSLionel Sambuc typename A::template B<>; // expected-error {{use of undeclared identifier 'A'}} \
221f4a2713aSLionel Sambuc // expected-error {{expected a qualified name after 'typename'}} \
222*0a6a1f1dSLionel Sambuc // expected-error {{'template' keyword outside of a template}}
223f4a2713aSLionel Sambuc }
224f4a2713aSLionel Sambuc }
225f4a2713aSLionel Sambuc
226f4a2713aSLionel Sambuc namespace PR17567 {
227f4a2713aSLionel Sambuc struct Foobar { // expected-note 2{{declared here}}
228f4a2713aSLionel Sambuc FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
229f4a2713aSLionel Sambuc ~FooBar(); // expected-error {{expected the class name after '~' to name a destructor}}
230f4a2713aSLionel Sambuc };
231f4a2713aSLionel Sambuc FooBar::FooBar() {} // expected-error {{undeclared}} expected-error {{missing return type}}
232f4a2713aSLionel Sambuc FooBar::~FooBar() {} // expected-error {{undeclared}} expected-error {{expected the class name}}
233f4a2713aSLionel Sambuc }
234f4a2713aSLionel Sambuc
235*0a6a1f1dSLionel Sambuc namespace DuplicateFriend {
236*0a6a1f1dSLionel Sambuc struct A {
237*0a6a1f1dSLionel Sambuc friend void friend f(); // expected-warning {{duplicate 'friend' declaration specifier}}
238*0a6a1f1dSLionel Sambuc friend struct B friend; // expected-warning {{duplicate 'friend' declaration specifier}}
239*0a6a1f1dSLionel Sambuc };
240*0a6a1f1dSLionel Sambuc }
241*0a6a1f1dSLionel Sambuc
242f4a2713aSLionel Sambuc // PR8380
243f4a2713aSLionel Sambuc extern "" // expected-error {{unknown linkage language}}
244f4a2713aSLionel Sambuc test6a { ;// expected-error {{C++ requires a type specifier for all declarations}} \
245f4a2713aSLionel Sambuc // expected-error {{expected ';' after top level declarator}}
246f4a2713aSLionel Sambuc
247f4a2713aSLionel Sambuc int test6b;
248