1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s 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 5 class C; 6 class C { 7 public: 8 protected: 9 typedef int A,B; 10 static int sf(), u; 11 12 struct S {}; 13 enum {}; // expected-warning{{declaration does not declare anything}} 14 int; // expected-warning {{declaration does not declare anything}} 15 int : 1, : 2; 16 17 public: 18 void m0() {}; // ok, one extra ';' is permitted 19 void m1() {} 20 ; // ok, one extra ';' is permitted 21 void m() { 22 int l = 2; 23 };; // expected-warning{{extra ';' after member function definition}} 24 25 template<typename T> void mt(T) { } 26 ; 27 ; // expected-warning{{extra ';' inside a class}} 28 29 virtual int vf() const volatile = 0; 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}} 40 virtual int PR45267() = \ 41 0; // ok, despite escaped newline 42 43 private: 44 int x,f(),y,g(); 45 inline int h(); 46 static const int sci = 10; 47 mutable int mi; 48 }; 49 void glo() 50 { 51 struct local {}; 52 } 53 54 // PR3177 55 typedef union { 56 __extension__ union { 57 int a; 58 float b; 59 } y; 60 } bug3177; 61 62 // check that we don't consume the token after the access specifier 63 // when it's not a colon 64 class D { 65 public // expected-error{{expected ':'}} 66 int i; 67 }; 68 69 // consume the token after the access specifier if it's a semicolon 70 // that was meant to be a colon 71 class E { 72 public; // expected-error{{expected ':'}} 73 int i; 74 }; 75 76 class F { 77 int F1 { return 1; } 78 #if __cplusplus <= 199711L 79 // expected-error@-2 {{function definition does not declare parameters}} 80 #else 81 // expected-error@-4 {{expected expression}} 82 // expected-error@-5 {{expected}} 83 // expected-note@-6 {{to match this '{'}} 84 // expected-error@-7 {{expected ';' after class}} 85 #endif 86 87 void F2 {} 88 #if __cplusplus <= 199711L 89 // expected-error@-2 {{function definition does not declare parameters}} 90 #else 91 // expected-error@-4 {{variable has incomplete type 'void'}} 92 // expected-error@-5 {{expected ';' after top level declarator}} 93 #endif 94 95 typedef int F3() { return 0; } // expected-error{{function definition declared 'typedef'}} 96 typedef void F4() {} // expected-error{{function definition declared 'typedef'}} 97 }; 98 #if __cplusplus >= 201103L 99 // expected-error@-2 {{extraneous closing brace}} 100 #endif 101 102 namespace ctor_error { 103 class Foo {}; 104 // By [class.qual]p2, this is a constructor declaration. 105 Foo::Foo (F) = F(); // expected-error{{does not match any declaration in 'ctor_error::Foo'}} 106 107 class Ctor { // expected-note{{not complete until the closing '}'}} 108 Ctor(f)(int); // ok 109 Ctor(g(int)); // ok 110 Ctor(x[5]); // expected-error{{incomplete type}} 111 112 Ctor(UnknownType *); // expected-error{{unknown type name 'UnknownType'}} 113 void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}} 114 }; 115 116 Ctor::Ctor (x) = { 0 }; // \ 117 // expected-error{{qualified reference to 'Ctor' is a constructor name}} 118 119 Ctor::Ctor(UnknownType *) {} // \ 120 // expected-error{{unknown type name 'UnknownType'}} 121 void Ctor::operator+(UnknownType*) {} // \ 122 // expected-error{{unknown type name 'UnknownType'}} 123 } 124 125 namespace nns_decl { 126 struct A { 127 struct B; 128 }; 129 namespace N { 130 union C; 131 } 132 struct A::B; // expected-error {{forward declaration of struct cannot have a nested name specifier}} 133 union N::C; // expected-error {{forward declaration of union cannot have a nested name specifier}} 134 } 135 136 // PR13775: Don't assert here. 137 namespace PR13775 { 138 class bar 139 { 140 public: 141 void foo (); 142 void baz (); 143 }; 144 void bar::foo () 145 { 146 baz x(); // expected-error 3{{}} 147 } 148 } 149 150 class pr16989 { 151 void tpl_mem(int *) { 152 return; 153 class C2 { 154 void f(); 155 }; 156 void C2::f() {} // expected-error{{function definition is not allowed here}} 157 }; 158 }; 159 160 namespace CtorErrors { 161 struct A { 162 A(NonExistent); // expected-error {{unknown type name 'NonExistent'}} 163 }; 164 struct B { 165 B(NonExistent) : n(0) {} // expected-error {{unknown type name 'NonExistent'}} 166 int n; 167 }; 168 struct C { 169 C(NonExistent) try {} catch (...) {} // expected-error {{unknown type name 'NonExistent'}} 170 }; 171 struct D { 172 D(NonExistent) {} // expected-error {{unknown type name 'NonExistent'}} 173 }; 174 } 175 176 namespace DtorErrors { 177 struct A { ~A(); int n; } a; 178 ~A::A() { n = 0; } // expected-error {{'~' in destructor name should be after nested name specifier}} expected-note {{previous}} 179 A::~A() {} // expected-error {{redefinition}} 180 181 struct B { ~B(); } *b; 182 DtorErrors::~B::B() {} // expected-error {{'~' in destructor name should be after nested name specifier}} 183 184 void f() { 185 a.~A::A(); // expected-error {{'~' in destructor name should be after nested name specifier}} 186 b->~DtorErrors::~B::B(); // expected-error {{'~' in destructor name should be after nested name specifier}} 187 } 188 189 struct C; // expected-note {{forward decl}} 190 ~C::C() {} // expected-error {{incomplete}} expected-error {{'~' in destructor name should be after nested name specifier}} 191 192 struct D { struct X {}; ~D() throw(X); }; 193 ~D::D() throw(X) {} // expected-error {{'~' in destructor name should be after nested name specifier}} 194 195 ~Undeclared::Undeclared() {} // expected-error {{use of undeclared identifier 'Undeclared'}} expected-error {{'~' in destructor name should be after nested name specifier}} 196 ~Undeclared:: {} // expected-error {{expected identifier}} expected-error {{'~' in destructor name should be after nested name specifier}} 197 198 struct S { 199 // For another struct's destructor, emit the same diagnostic like for 200 // A::~A() in addition to the "~ in the wrong place" one. 201 ~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}} 202 A::~A() {} // expected-error {{non-friend class member '~A' cannot have a qualified name}} 203 204 // An inline destructor with a redundant class name should also get the 205 // same diagnostic as S::~S. 206 ~S::S() {} // expected-error {{'~' in destructor name should be after nested name specifier}} expected-error {{extra qualification on member '~S'}} 207 208 // This just shouldn't crash. 209 int I; // expected-note {{declared here}} 210 ~I::I() {} // expected-error {{'I' is not a class, namespace, or enumeration}} expected-error {{'~' in destructor name should be after nested name specifier}} 211 }; 212 213 struct T {}; 214 T t1 = t1.T::~T<int>; // expected-error {{destructor name 'T' does not refer to a template}} 215 // Emit the same diagnostic as for the previous case, plus something about ~. 216 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}} 217 } 218 219 namespace BadFriend { 220 struct A { 221 friend int : 3; // expected-error {{friends can only be classes or functions}} 222 friend void f() = 123; // expected-error {{illegal initializer}} 223 friend virtual void f(); // expected-error {{'virtual' is invalid in friend declarations}} 224 friend void f() final; // expected-error {{'final' is invalid in friend declarations}} 225 friend void f() override; // expected-error {{'override' is invalid in friend declarations}} 226 }; 227 } 228 229 class PR20760_a { 230 int a = ); // expected-error {{expected expression}} 231 #if __cplusplus <= 199711L 232 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 233 #endif 234 235 int b = }; // expected-error {{expected expression}} 236 #if __cplusplus <= 199711L 237 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 238 #endif 239 240 int c = ]; // expected-error {{expected expression}} 241 #if __cplusplus <= 199711L 242 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 243 #endif 244 245 }; 246 class PR20760_b { 247 int d = d); // expected-error {{expected ';'}} 248 #if __cplusplus <= 199711L 249 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 250 #endif 251 252 int e = d]; // expected-error {{expected ';'}} 253 #if __cplusplus <= 199711L 254 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 255 #endif 256 257 int f = d // expected-error {{expected ';'}} 258 #if __cplusplus <= 199711L 259 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}} 260 #endif 261 262 }; 263 264 namespace PR20887 { 265 class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}} 266 class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}} 267 } 268 269 class BadExceptionSpec { 270 void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}} 271 void g() throw( 272 int( 273 ; // expected-error {{unexpected ';' before ')'}} 274 )); 275 }; 276 277 namespace PR41192 { 278 extern struct A a; 279 struct A {} ::PR41192::a; // ok, no missing ';' here expected-warning {{extra qualification}} 280 281 #if __cplusplus >= 201103L 282 struct C; 283 struct D { static C c; }; 284 struct C {} decltype(D())::c; // expected-error {{'decltype' cannot be used to name a declaration}} 285 #endif 286 } 287 288 namespace ArrayMemberAccess { 289 struct A { 290 int x; 291 template<typename T> int f() const; 292 }; 293 void f(const A (&a)[]) { 294 // OK: not a template-id. 295 bool cond = a->x < 10 && a->x > 0; 296 // OK: a template-id. 297 a->f<int>(); 298 } 299 } 300 301 namespace UndeclaredBaseTemplate { 302 template<class> struct imp; 303 template<class T> struct is_member_function_pointer : undeclared<imp<T>::member> {}; // expected-error {{unknown template name 'undeclared'}} 304 } 305 306 // PR11109 must appear at the end of the source file 307 class pr11109r3 { // expected-note{{to match this '{'}} 308 public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} 309