blob: 215c941a4610fcd42ae872b2d2cc4c27bf1b6012 [file] [log] [blame]
Richard Smith446161b2014-03-03 21:12:53 +00001// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s
Sebastian Redlf4485de2008-11-08 15:40:37 +00002class C;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +00003class C {
4public:
5protected:
6 typedef int A,B;
7 static int sf(), u;
8
9 struct S {};
Douglas Gregoraa8c9722010-07-13 06:24:26 +000010 enum {}; // expected-warning{{declaration does not declare anything}}
Douglas Gregorf19ac0e2010-04-08 21:33:23 +000011 int; // expected-warning {{declaration does not declare anything}}
Argyrios Kyrtzidisf4ebe9e2008-06-28 08:10:48 +000012 int : 1, : 2;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000013
14public:
Richard Smith87f5dc52012-07-23 05:45:25 +000015 void m0() {}; // ok, one extra ';' is permitted
16 void m1() {}
17 ; // ok, one extra ';' is permitted
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000018 void m() {
19 int l = 2;
Richard Smith87f5dc52012-07-23 05:45:25 +000020 };; // expected-warning{{extra ';' after member function definition}}
Douglas Gregor8a4db832011-01-19 16:41:58 +000021
Richard Trieu2f7dc462012-05-16 19:04:59 +000022 template<typename T> void mt(T) { }
Richard Smith87f5dc52012-07-23 05:45:25 +000023 ;
Douglas Gregor8a4db832011-01-19 16:41:58 +000024 ; // expected-warning{{extra ';' inside a class}}
25
Sebastian Redlf4485de2008-11-08 15:40:37 +000026 virtual int vf() const volatile = 0;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000027
28private:
29 int x,f(),y,g();
Sebastian Redlf4485de2008-11-08 15:40:37 +000030 inline int h();
31 static const int sci = 10;
Sebastian Redlccdfaba2008-11-14 23:42:31 +000032 mutable int mi;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000033};
Sebastian Redlf4485de2008-11-08 15:40:37 +000034void glo()
35{
36 struct local {};
37}
Chris Lattnerd19c1c02008-12-18 01:12:00 +000038
39// PR3177
40typedef union {
41 __extension__ union {
42 int a;
43 float b;
44 } y;
45} bug3177;
46
David Blaikieeba32c22011-10-13 06:08:43 +000047// check that we don't consume the token after the access specifier
48// when it's not a colon
49class D {
50public // expected-error{{expected ':'}}
51 int i;
52};
53
54// consume the token after the access specifier if it's a semicolon
55// that was meant to be a colon
56class E {
57public; // expected-error{{expected ':'}}
58 int i;
59};
60
Richard Trieu0d730542012-01-21 02:59:18 +000061class F {
62 int F1 { return 1; } // expected-error{{function definition does not declare parameters}}
63 void F2 {} // expected-error{{function definition does not declare parameters}}
64 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
65 typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
66};
67
Richard Smithefd009d2012-03-27 00:56:56 +000068namespace ctor_error {
69 class Foo {};
70 // By [class.qual]p2, this is a constructor declaration.
71 Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
72
73 class Ctor { // expected-note{{not complete until the closing '}'}}
74 Ctor(f)(int); // ok
75 Ctor(g(int)); // ok
76 Ctor(x[5]); // expected-error{{incomplete type}}
77
78 Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}}
Richard Smith01910232012-03-29 01:46:00 +000079 void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +000080 };
81
82 Ctor::Ctor (x) = { 0 }; // \
83 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
84
Richard Smithefd009d2012-03-27 00:56:56 +000085 Ctor::Ctor(UnknownType *) {} // \
Richard Smith01910232012-03-29 01:46:00 +000086 // expected-error{{unknown type name 'UnknownType'}}
87 void Ctor::operator+(UnknownType*) {} // \
88 // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +000089}
90
Richard Smithb1402ae2013-03-18 22:52:47 +000091namespace nns_decl {
92 struct A {
93 struct B;
94 };
95 namespace N {
96 union C;
97 }
98 struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
99 union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}}
100}
101
Richard Smithaa31b4b2012-09-06 01:37:56 +0000102// PR13775: Don't assert here.
103namespace PR13775 {
104 class bar
105 {
106 public:
107 void foo ();
108 void baz ();
109 };
110 void bar::foo ()
111 {
112 baz x(); // expected-error 3{{}}
113 }
114}
115
Serge Pavlov1de51512013-12-09 05:25:47 +0000116class pr16989 {
117 void tpl_mem(int *) {
118 return;
119 class C2 {
120 void f();
121 };
122 void C2::f() {} // expected-error{{function definition is not allowed here}}
123 };
124};
125
Richard Smith446161b2014-03-03 21:12:53 +0000126namespace CtorErrors {
127 struct A {
128 A(NonExistent); // expected-error {{unknown type name 'NonExistent'}}
129 };
130 struct B {
131 B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
132 int n;
133 };
134 struct C {
135 C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
136 };
137 struct D {
138 D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}}
139 };
140}
141
Richard Smithefa6f732014-09-06 02:06:12 +0000142namespace DtorErrors {
Richard Smith64e033f2015-01-15 00:48:52 +0000143 struct A { ~A(); int n; } a;
144 ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}}
Richard Smithefa6f732014-09-06 02:06:12 +0000145 A::~A() {} // expected-error {{redefinition}}
146
147 struct B { ~B(); } *b;
148 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
149
150 void f() {
151 a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
152 b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
153 }
Richard Smith64e033f2015-01-15 00:48:52 +0000154
155 struct C; // expected-note {{forward decl}}
156 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
157
158 struct D { struct X {}; ~D() throw(X); };
159 ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberd0045862015-01-30 04:05:15 +0000160
161 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberf9e37be2015-01-30 16:53:11 +0000162
163 struct S {
164 // For another struct's destructor, emit the same diagnostic like for
165 // A::~A() in addition to the "~ in the wrong place" one.
166 ~A::A() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{non-friend class member '~A' cannot have a qualified name}}
167 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
168
169 // An inline destructor with a redundant class name should also get the
170 // same diagnostic as S::~S.
171 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
172
173 // This just shouldn't crash.
174 int I; // expected-note {{declared here}}
175 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
176 };
Nico Weber7f8ec522015-02-02 05:33:50 +0000177
178 struct T {};
179 T t1 = t1.T::~T<int>; // expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
180 // Emit the same diagnostic as for the previous case, plus something about ~.
181 T t2 = t2.~T::T<int>; // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{destructor name 'T' does not refer to a template}} expected-error {{expected '(' for function-style cast or type construction}} expected-error {{expected expression}}
Richard Smithefa6f732014-09-06 02:06:12 +0000182}
183
Richard Smith3d1a94c2014-08-12 00:22:39 +0000184namespace BadFriend {
185 struct A {
186 friend int : 3; // expected-error {{friends can only be classes or functions}}
187 friend void f() = 123; // expected-error {{illegal initializer}}
188 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
189 friend void f() final; // expected-error {{'final' is invalid in friend declarations}}
190 friend void f() override; // expected-error {{'override' is invalid in friend declarations}}
191 };
192}
193
Richard Smith95e1fb02014-08-27 03:23:12 +0000194class PR20760_a {
195 int a = ); // expected-warning {{extension}} expected-error {{expected expression}}
196 int b = }; // expected-warning {{extension}} expected-error {{expected expression}}
197 int c = ]; // expected-warning {{extension}} expected-error {{expected expression}}
198};
199class PR20760_b {
200 int d = d); // expected-warning {{extension}} expected-error {{expected ';'}}
201 int e = d]; // expected-warning {{extension}} expected-error {{expected ';'}}
202 int f = d // expected-warning {{extension}} expected-error {{expected ';'}}
203};
204
Nico Weberef03e702014-09-10 00:59:37 +0000205namespace PR20887 {
206class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}}
207class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}}
208}
209
Richard Smithb1c217e2015-01-13 02:24:58 +0000210class BadExceptionSpec {
211 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
212 void g() throw( // expected-note {{to match}}
213 int( // expected-note {{to match}}
214 ; // expected-error 2{{expected ')'}} expected-error {{unexpected end of exception specification}}
215 ));
216};
217
David Blaikieeba32c22011-10-13 06:08:43 +0000218// PR11109 must appear at the end of the source file
219class pr11109r3 { // expected-note{{to match this '{'}}
220 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}