blob: 9e907f1b1c12f8faa34d704bfaf4a92715d8afca [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;
Richard Smith40cdd7a2015-06-29 23:19:23 +000027
28 virtual int vf0() = 0l; // expected-error {{does not look like a pure-specifier}}
29 virtual int vf1() = 1; // expected-error {{does not look like a pure-specifier}}
30 virtual int vf2() = 00; // expected-error {{does not look like a pure-specifier}}
31 virtual int vf3() = 0x0; // expected-error {{does not look like a pure-specifier}}
32 virtual int vf4() = 0.0; // expected-error {{does not look like a pure-specifier}}
33 virtual int vf5(){0}; // expected-error +{{}} expected-warning {{unused}}
34 virtual int vf5a(){0;}; // function definition, expected-warning {{unused}}
35 virtual int vf6()(0); // expected-error +{{}} expected-note +{{}}
36 virtual int vf7() = { 0 }; // expected-error {{does not look like a pure-specifier}}
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000037
38private:
39 int x,f(),y,g();
Sebastian Redlf4485de2008-11-08 15:40:37 +000040 inline int h();
41 static const int sci = 10;
Sebastian Redlccdfaba2008-11-14 23:42:31 +000042 mutable int mi;
Argyrios Kyrtzidis7bbb20e2008-06-24 22:12:16 +000043};
Sebastian Redlf4485de2008-11-08 15:40:37 +000044void glo()
45{
46 struct local {};
47}
Chris Lattnerd19c1c02008-12-18 01:12:00 +000048
49// PR3177
50typedef union {
51 __extension__ union {
52 int a;
53 float b;
54 } y;
55} bug3177;
56
David Blaikieeba32c22011-10-13 06:08:43 +000057// check that we don't consume the token after the access specifier
58// when it's not a colon
59class D {
60public // expected-error{{expected ':'}}
61 int i;
62};
63
64// consume the token after the access specifier if it's a semicolon
65// that was meant to be a colon
66class E {
67public; // expected-error{{expected ':'}}
68 int i;
69};
70
Richard Trieu0d730542012-01-21 02:59:18 +000071class F {
72 int F1 { return 1; } // expected-error{{function definition does not declare parameters}}
73 void F2 {} // expected-error{{function definition does not declare parameters}}
74 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}}
75 typedef void F4() {} // expected-error{{function definition declared 'typedef'}}
76};
77
Richard Smithefd009d2012-03-27 00:56:56 +000078namespace ctor_error {
79 class Foo {};
80 // By [class.qual]p2, this is a constructor declaration.
81 Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}}
82
83 class Ctor { // expected-note{{not complete until the closing '}'}}
84 Ctor(f)(int); // ok
85 Ctor(g(int)); // ok
86 Ctor(x[5]); // expected-error{{incomplete type}}
87
88 Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}}
Richard Smith01910232012-03-29 01:46:00 +000089 void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +000090 };
91
92 Ctor::Ctor (x) = { 0 }; // \
93 // expected-error{{qualified reference to 'Ctor' is a constructor name}}
94
Richard Smithefd009d2012-03-27 00:56:56 +000095 Ctor::Ctor(UnknownType *) {} // \
Richard Smith01910232012-03-29 01:46:00 +000096 // expected-error{{unknown type name 'UnknownType'}}
97 void Ctor::operator+(UnknownType*) {} // \
98 // expected-error{{unknown type name 'UnknownType'}}
Richard Smithefd009d2012-03-27 00:56:56 +000099}
100
Richard Smithb1402ae2013-03-18 22:52:47 +0000101namespace nns_decl {
102 struct A {
103 struct B;
104 };
105 namespace N {
106 union C;
107 }
108 struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}}
109 union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}}
110}
111
Richard Smithaa31b4b2012-09-06 01:37:56 +0000112// PR13775: Don't assert here.
113namespace PR13775 {
114 class bar
115 {
116 public:
117 void foo ();
118 void baz ();
119 };
120 void bar::foo ()
121 {
122 baz x(); // expected-error 3{{}}
123 }
124}
125
Serge Pavlov1de51512013-12-09 05:25:47 +0000126class pr16989 {
127 void tpl_mem(int *) {
128 return;
129 class C2 {
130 void f();
131 };
132 void C2::f() {} // expected-error{{function definition is not allowed here}}
133 };
134};
135
Richard Smith446161b2014-03-03 21:12:53 +0000136namespace CtorErrors {
137 struct A {
138 A(NonExistent); // expected-error {{unknown type name 'NonExistent'}}
139 };
140 struct B {
141 B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}}
142 int n;
143 };
144 struct C {
145 C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}}
146 };
147 struct D {
148 D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}}
149 };
150}
151
Richard Smithefa6f732014-09-06 02:06:12 +0000152namespace DtorErrors {
Richard Smith64e033f2015-01-15 00:48:52 +0000153 struct A { ~A(); int n; } a;
154 ~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 +0000155 A::~A() {} // expected-error {{redefinition}}
156
157 struct B { ~B(); } *b;
158 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}}
159
160 void f() {
161 a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}}
162 b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}}
163 }
Richard Smith64e033f2015-01-15 00:48:52 +0000164
165 struct C; // expected-note {{forward decl}}
166 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}}
167
168 struct D { struct X {}; ~D() throw(X); };
169 ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberd0045862015-01-30 04:05:15 +0000170
171 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}}
Benjamin Kramer3012e592015-03-29 14:35:39 +0000172 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}}
Nico Weberf9e37be2015-01-30 16:53:11 +0000173
174 struct S {
175 // For another struct's destructor, emit the same diagnostic like for
176 // A::~A() in addition to the "~ in the wrong place" one.
177 ~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}}
178 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}}
179
180 // An inline destructor with a redundant class name should also get the
181 // same diagnostic as S::~S.
182 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}}
183
184 // This just shouldn't crash.
185 int I; // expected-note {{declared here}}
186 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}}
187 };
Nico Weber7f8ec522015-02-02 05:33:50 +0000188
189 struct T {};
190 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}}
191 // Emit the same diagnostic as for the previous case, plus something about ~.
192 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 +0000193}
194
Richard Smith3d1a94c2014-08-12 00:22:39 +0000195namespace BadFriend {
196 struct A {
197 friend int : 3; // expected-error {{friends can only be classes or functions}}
198 friend void f() = 123; // expected-error {{illegal initializer}}
199 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}}
200 friend void f() final; // expected-error {{'final' is invalid in friend declarations}}
201 friend void f() override; // expected-error {{'override' is invalid in friend declarations}}
202 };
203}
204
Richard Smith95e1fb02014-08-27 03:23:12 +0000205class PR20760_a {
206 int a = ); // expected-warning {{extension}} expected-error {{expected expression}}
207 int b = }; // expected-warning {{extension}} expected-error {{expected expression}}
208 int c = ]; // expected-warning {{extension}} expected-error {{expected expression}}
209};
210class PR20760_b {
211 int d = d); // expected-warning {{extension}} expected-error {{expected ';'}}
212 int e = d]; // expected-warning {{extension}} expected-error {{expected ';'}}
213 int f = d // expected-warning {{extension}} expected-error {{expected ';'}}
214};
215
Nico Weberef03e702014-09-10 00:59:37 +0000216namespace PR20887 {
217class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}}
218class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}}
219}
220
Richard Smithb1c217e2015-01-13 02:24:58 +0000221class BadExceptionSpec {
222 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}}
Richard Trieu1d3b58e2015-05-12 21:36:35 +0000223 void g() throw(
224 int(
225 ; // expected-error {{unexpected ';' before ')'}}
Richard Smithb1c217e2015-01-13 02:24:58 +0000226 ));
227};
228
David Blaikieeba32c22011-10-13 06:08:43 +0000229// PR11109 must appear at the end of the source file
230class pr11109r3 { // expected-note{{to match this '{'}}
231 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}}