Richard Smith | 446161b | 2014-03-03 21:12:53 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -fcxx-exceptions %s |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 2 | class C; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 3 | class C { |
| 4 | public: |
| 5 | protected: |
| 6 | typedef int A,B; |
| 7 | static int sf(), u; |
| 8 | |
| 9 | struct S {}; |
Douglas Gregor | aa8c972 | 2010-07-13 06:24:26 +0000 | [diff] [blame] | 10 | enum {}; // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | f19ac0e | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 11 | int; // expected-warning {{declaration does not declare anything}} |
Argyrios Kyrtzidis | f4ebe9e | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 12 | int : 1, : 2; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 13 | |
| 14 | public: |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 15 | void m0() {}; // ok, one extra ';' is permitted |
| 16 | void m1() {} |
| 17 | ; // ok, one extra ';' is permitted |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 18 | void m() { |
| 19 | int l = 2; |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 20 | };; // expected-warning{{extra ';' after member function definition}} |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 21 | |
Richard Trieu | 2f7dc46 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 22 | template<typename T> void mt(T) { } |
Richard Smith | 87f5dc5 | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 23 | ; |
Douglas Gregor | 8a4db83 | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 24 | ; // expected-warning{{extra ';' inside a class}} |
| 25 | |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 26 | virtual int vf() const volatile = 0; |
Richard Smith | 40cdd7a | 2015-06-29 23:19:23 +0000 | [diff] [blame] | 27 | |
| 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 Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 37 | |
| 38 | private: |
| 39 | int x,f(),y,g(); |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 40 | inline int h(); |
| 41 | static const int sci = 10; |
Sebastian Redl | ccdfaba | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 42 | mutable int mi; |
Argyrios Kyrtzidis | 7bbb20e | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 43 | }; |
Sebastian Redl | f4485de | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 44 | void glo() |
| 45 | { |
| 46 | struct local {}; |
| 47 | } |
Chris Lattner | d19c1c0 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 48 | |
| 49 | // PR3177 |
| 50 | typedef union { |
| 51 | __extension__ union { |
| 52 | int a; |
| 53 | float b; |
| 54 | } y; |
| 55 | } bug3177; |
| 56 | |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 57 | // check that we don't consume the token after the access specifier |
| 58 | // when it's not a colon |
| 59 | class D { |
| 60 | public // 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 |
| 66 | class E { |
| 67 | public; // expected-error{{expected ':'}} |
| 68 | int i; |
| 69 | }; |
| 70 | |
Richard Trieu | 0d73054 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 71 | class 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 Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 78 | namespace 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 Smith | 0191023 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 89 | void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | Ctor::Ctor (x) = { 0 }; // \ |
| 93 | // expected-error{{qualified reference to 'Ctor' is a constructor name}} |
| 94 | |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 95 | Ctor::Ctor(UnknownType *) {} // \ |
Richard Smith | 0191023 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 96 | // expected-error{{unknown type name 'UnknownType'}} |
| 97 | void Ctor::operator+(UnknownType*) {} // \ |
| 98 | // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | efd009d | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 99 | } |
| 100 | |
Richard Smith | b1402ae | 2013-03-18 22:52:47 +0000 | [diff] [blame] | 101 | namespace 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 Smith | aa31b4b | 2012-09-06 01:37:56 +0000 | [diff] [blame] | 112 | // PR13775: Don't assert here. |
| 113 | namespace 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 Pavlov | 1de5151 | 2013-12-09 05:25:47 +0000 | [diff] [blame] | 126 | class 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 Smith | 446161b | 2014-03-03 21:12:53 +0000 | [diff] [blame] | 136 | namespace 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 Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 152 | namespace DtorErrors { |
Richard Smith | 64e033f | 2015-01-15 00:48:52 +0000 | [diff] [blame] | 153 | 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 Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 155 | 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 Smith | 64e033f | 2015-01-15 00:48:52 +0000 | [diff] [blame] | 164 | |
| 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 Weber | d004586 | 2015-01-30 04:05:15 +0000 | [diff] [blame] | 170 | |
| 171 | ~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] | 172 | ~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] | 173 | |
| 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 Weber | 7f8ec52 | 2015-02-02 05:33:50 +0000 | [diff] [blame] | 188 | |
| 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 Smith | efa6f73 | 2014-09-06 02:06:12 +0000 | [diff] [blame] | 193 | } |
| 194 | |
Richard Smith | 3d1a94c | 2014-08-12 00:22:39 +0000 | [diff] [blame] | 195 | namespace 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 Smith | 95e1fb0 | 2014-08-27 03:23:12 +0000 | [diff] [blame] | 205 | class 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 | }; |
| 210 | class 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 Weber | ef03e70 | 2014-09-10 00:59:37 +0000 | [diff] [blame] | 216 | namespace PR20887 { |
| 217 | class X1 { a::operator=; }; // expected-error {{undeclared identifier 'a'}} |
| 218 | class X2 { a::a; }; // expected-error {{undeclared identifier 'a'}} |
| 219 | } |
| 220 | |
Richard Smith | b1c217e | 2015-01-13 02:24:58 +0000 | [diff] [blame] | 221 | class BadExceptionSpec { |
| 222 | void f() throw(int; // expected-error {{expected ')'}} expected-note {{to match}} |
Richard Trieu | 1d3b58e | 2015-05-12 21:36:35 +0000 | [diff] [blame] | 223 | void g() throw( |
| 224 | int( |
| 225 | ; // expected-error {{unexpected ';' before ')'}} |
Richard Smith | b1c217e | 2015-01-13 02:24:58 +0000 | [diff] [blame] | 226 | )); |
| 227 | }; |
| 228 | |
David Blaikie | eba32c2 | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 229 | // PR11109 must appear at the end of the source file |
| 230 | class pr11109r3 { // expected-note{{to match this '{'}} |
| 231 | public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} |