Richard Smith | 446161b | 2014-03-03 21:12:53 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame^] | 2 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++98 %s |
| 3 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions -std=c++11 %s |
| 4 | |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 5 | class C; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 6 | class C { |
| 7 | public: |
| 8 | protected: |
| 9 | typedef int A,B; |
| 10 | static int sf(), u; |
| 11 | |
| 12 | struct S {}; |
Douglas Gregor | aa8c972 | 2010-07-13 06:24:26 +0000 | [diff] [blame] | 13 | enum {}; // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | f19ac0e | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 14 | int; // expected-warning {{declaration does not declare anything}} |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 15 | int : 1, : 2; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 16 | |
| 17 | public: |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 18 | void m0() {}; // ok, one extra ';' is permitted |
| 19 | void m1() {} |
| 20 | ; // ok, one extra ';' is permitted |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 21 | void m() { |
| 22 | int l = 2; |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 23 | };; // expected-warning{{extra ';' after member function definition}} |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 24 | |
Richard Trieu | 2f7dc46 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 25 | template<typename T> void mt(T) { } |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 26 | ; |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 27 | ; // expected-warning{{extra ';' inside a class}} |
| 28 | |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 29 | virtual int vf() const volatile = 0; |
Richard Smith | 40cdd7a | 2015-06-29 23:19:23 +0000 | [diff] [blame] | 30 | |
| 31 | virtual int vf0() = 0l; // expected-error {{does not look like a pure-specifier}} |
| 32 | virtual int vf1() = 1; // expected-error {{does not look like a pure-specifier}} |
| 33 | virtual int vf2() = 00; // expected-error {{does not look like a pure-specifier}} |
| 34 | virtual int vf3() = 0x0; // expected-error {{does not look like a pure-specifier}} |
| 35 | virtual int vf4() = 0.0; // expected-error {{does not look like a pure-specifier}} |
| 36 | virtual int vf5(){0}; // expected-error +{{}} expected-warning {{unused}} |
| 37 | virtual int vf5a(){0;}; // function definition, expected-warning {{unused}} |
| 38 | virtual int vf6()(0); // expected-error +{{}} expected-note +{{}} |
| 39 | virtual int vf7() = { 0 }; // expected-error {{does not look like a pure-specifier}} |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 40 | |
| 41 | private: |
| 42 | int x,f(),y,g(); |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 43 | inline int h(); |
| 44 | static const int sci = 10; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 45 | mutable int mi; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 46 | }; |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 47 | void glo() |
| 48 | { |
| 49 | struct local {}; |
| 50 | } |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 51 | |
| 52 | // PR3177 |
| 53 | typedef union { |
| 54 | __extension__ union { |
| 55 | int a; |
| 56 | float b; |
| 57 | } y; |
| 58 | } bug3177; |
| 59 | |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 60 | // check that we don't consume the token after the access specifier |
| 61 | // when it's not a colon |
| 62 | class D { |
| 63 | public // expected-error{{expected ':'}} |
| 64 | int i; |
| 65 | }; |
| 66 | |
| 67 | // consume the token after the access specifier if it's a semicolon |
| 68 | // that was meant to be a colon |
| 69 | class E { |
| 70 | public; // expected-error{{expected ':'}} |
| 71 | int i; |
| 72 | }; |
| 73 | |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 74 | class F { |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame^] | 75 | int F1 { return 1; } |
| 76 | #if __cplusplus <= 199711L |
| 77 | // expected-error@-2 {{function definition does not declare parameters}} |
| 78 | #else |
| 79 | // expected-error@-4 {{expected expression}} |
| 80 | // expected-error@-5 {{expected}} |
| 81 | // expected-note@-6 {{to match this '{'}} |
| 82 | // expected-error@-7 {{expected ';' after class}} |
| 83 | #endif |
| 84 | |
| 85 | void F2 {} |
| 86 | #if __cplusplus <= 199711L |
| 87 | // expected-error@-2 {{function definition does not declare parameters}} |
| 88 | #else |
| 89 | // expected-error@-4 {{variable has incomplete type 'void'}} |
| 90 | // expected-error@-5 {{expected ';' after top level declarator}} |
| 91 | #endif |
| 92 | |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 93 | typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}} |
| 94 | typedef void F4() {} // expected-error{{function definition declared 'typedef'}} |
| 95 | }; |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame^] | 96 | #if __cplusplus >= 201103L |
| 97 | // expected-error@-2 {{extraneous closing brace}} |
| 98 | #endif |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 99 | |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 100 | namespace ctor_error { |
| 101 | class Foo {}; |
| 102 | // By [class.qual]p2, this is a constructor declaration. |
| 103 | Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}} |
| 104 | |
| 105 | class Ctor { // expected-note{{not complete until the closing '}'}} |
| 106 | Ctor(f)(int); // ok |
| 107 | Ctor(g(int)); // ok |
| 108 | Ctor(x[5]); // expected-error{{incomplete type}} |
| 109 | |
| 110 | Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | 0191023 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 111 | void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | Ctor::Ctor (x) = { 0 }; // \ |
| 115 | // expected-error{{qualified reference to 'Ctor' is a constructor name}} |
| 116 | |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 117 | Ctor::Ctor(UnknownType *) {} // \ |
Richard Smith | 0191023 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 118 | // expected-error{{unknown type name 'UnknownType'}} |
| 119 | void Ctor::operator+(UnknownType*) {} // \ |
| 120 | // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 121 | } |
| 122 | |
Richard Smith | b1402ae | 2013-03-18 22:52:47 +0000 | [diff] [blame] | 123 | namespace nns_decl { |
| 124 | struct A { |
| 125 | struct B; |
| 126 | }; |
| 127 | namespace N { |
| 128 | union C; |
| 129 | } |
| 130 | struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}} |
| 131 | union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}} |
| 132 | } |
| 133 | |
Richard Smith | aa31b4b | 2012-09-06 01:37:56 +0000 | [diff] [blame] | 134 | // PR13775: Don't assert here. |
| 135 | namespace PR13775 { |
| 136 | class bar |
| 137 | { |
| 138 | public: |
| 139 | void foo (); |
| 140 | void baz (); |
| 141 | }; |
| 142 | void bar::foo () |
| 143 | { |
| 144 | baz x(); // expected-error 3{{}} |
| 145 | } |
| 146 | } |
| 147 | |
Serge Pavlov | 1de5151 | 2013-12-09 05:25:47 +0000 | [diff] [blame] | 148 | class pr16989 { |
| 149 | void tpl_mem(int *) { |
| 150 | return; |
| 151 | class C2 { |
| 152 | void f(); |
| 153 | }; |
| 154 | void C2::f() {} // expected-error{{function definition is not allowed here}} |
| 155 | }; |
| 156 | }; |
| 157 | |
Richard Smith | 446161b | 2014-03-03 21:12:53 +0000 | [diff] [blame] | 158 | namespace CtorErrors { |
| 159 | struct A { |
| 160 | A(NonExistent); // expected-error {{unknown type name 'NonExistent'}} |
| 161 | }; |
| 162 | struct B { |
| 163 | B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}} |
| 164 | int n; |
| 165 | }; |
| 166 | struct C { |
| 167 | C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}} |
| 168 | }; |
| 169 | struct D { |
| 170 | D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}} |
| 171 | }; |
| 172 | } |
| 173 | |
Richard Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 174 | namespace DtorErrors { |
Richard Smith | 64e033f | 2015-01-15 00:48:52 +0000 | [diff] [blame] | 175 | struct A { ~A(); int n; } a; |
| 176 | ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}} |
Richard Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 177 | A::~A() {} // expected-error {{redefinition}} |
| 178 | |
| 179 | struct B { ~B(); } *b; |
| 180 | DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}} |
| 181 | |
| 182 | void f() { |
| 183 | a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}} |
| 184 | b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}} |
| 185 | } |
Richard Smith | 64e033f | 2015-01-15 00:48:52 +0000 | [diff] [blame] | 186 | |
| 187 | struct C; // expected-note {{forward decl}} |
| 188 | ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}} |
| 189 | |
| 190 | struct D { struct X {}; ~D() throw(X); }; |
| 191 | ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}} |
Nico Weber | d004586 | 2015-01-30 04:05:15 +0000 | [diff] [blame] | 192 | |
| 193 | ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}} |
Benjamin Kramer | 3012e59 | 2015-03-29 14:35:39 +0000 | [diff] [blame] | 194 | ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}} |
Nico Weber | f9e37be | 2015-01-30 16:53:11 +0000 | [diff] [blame] | 195 | |
| 196 | struct S { |
| 197 | // For another struct's destructor, emit the same diagnostic like for |
| 198 | // A::~A() in addition to the "~ in the wrong place" one. |
| 199 | ~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}} |
| 200 | A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}} |
| 201 | |
| 202 | // An inline destructor with a redundant class name should also get the |
| 203 | // same diagnostic as S::~S. |
| 204 | ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}} |
| 205 | |
| 206 | // This just shouldn't crash. |
| 207 | int I; // expected-note {{declared here}} |
| 208 | ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}} |
| 209 | }; |
Nico Weber | 7f8ec52 | 2015-02-02 05:33:50 +0000 | [diff] [blame] | 210 | |
| 211 | struct T {}; |
| 212 | 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}} |
| 213 | // Emit the same diagnostic as for the previous case, plus something about ~. |
| 214 | 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 Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Richard Smith | 3d1a94c | 2014-08-12 00:22:39 +0000 | [diff] [blame] | 217 | namespace BadFriend { |
| 218 | struct A { |
| 219 | friend int : 3; // expected-error {{friends can only be classes or functions}} |
| 220 | friend void f() = 123; // expected-error {{illegal initializer}} |
| 221 | friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}} |
| 222 | friend void f() final; // expected-error {{'final' is invalid in friend declarations}} |
| 223 | friend void f() override; // expected-error {{'override' is invalid in friend declarations}} |
| 224 | }; |
| 225 | } |
| 226 | |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 227 | class PR20760_a { |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame^] | 228 | int a = ); // expected-error {{expected expression}} |
| 229 | #if __cplusplus <= 199711L |
| 230 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 231 | #endif |
| 232 | |
| 233 | int b = }; // expected-error {{expected expression}} |
| 234 | #if __cplusplus <= 199711L |
| 235 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 236 | #endif |
| 237 | |
| 238 | int c = ]; // expected-error {{expected expression}} |
| 239 | #if __cplusplus <= 199711L |
| 240 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 241 | #endif |
| 242 | |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 243 | }; |
| 244 | class PR20760_b { |
Charles Li | 1a88adb | 2016-04-14 23:47:07 +0000 | [diff] [blame^] | 245 | int d = d); // expected-error {{expected ';'}} |
| 246 | #if __cplusplus <= 199711L |
| 247 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 248 | #endif |
| 249 | |
| 250 | int e = d]; // expected-error {{expected ';'}} |
| 251 | #if __cplusplus <= 199711L |
| 252 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 253 | #endif |
| 254 | |
| 255 | int f = d // expected-error {{expected ';'}} |
| 256 | #if __cplusplus <= 199711L |
| 257 | // expected-warning@-2 {{in-class initialization of non-static data member is a C++11 extension}} |
| 258 | #endif |
| 259 | |
Richard Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 260 | }; |
| 261 | |
Nico Weber | ef03e70 | 2014-09-10 00:59:37 +0000 | [diff] [blame] | 262 | namespace PR20887 { |
| 263 | class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}} |
| 264 | class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}} |
| 265 | } |
| 266 | |
Richard Smith | b1c217e | 2015-01-13 02:24:58 +0000 | [diff] [blame] | 267 | class BadExceptionSpec { |
| 268 | void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}} |
Richard Trieu | 1d3b58e | 2015-05-12 21:36:35 +0000 | [diff] [blame] | 269 | void g() throw( |
| 270 | int( |
| 271 | ; // expected-error {{unexpected ';' before ')'}} |
Richard Smith | b1c217e | 2015-01-13 02:24:58 +0000 | [diff] [blame] | 272 | )); |
| 273 | }; |
| 274 | |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 275 | // PR11109 must appear at the end of the source file |
| 276 | class pr11109r3 { // expected-note{{to match this '{'}} |
| 277 | public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} |