Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -pedantic %s |
Sebastian Redl | ab963c6 | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 2 | class C; |
Argyrios Kyrtzidis | 4cc18a4 | 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 | a131d0f | 2010-07-13 06:24:26 +0000 | [diff] [blame] | 10 | enum {}; // expected-warning{{declaration does not declare anything}} |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 11 | int; // expected-warning {{declaration does not declare anything}} |
Argyrios Kyrtzidis | 3a9fdb4 | 2008-06-28 08:10:48 +0000 | [diff] [blame] | 12 | int : 1, : 2; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 13 | |
| 14 | public: |
Richard Smith | eab9d6f | 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 | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 18 | void m() { |
| 19 | int l = 2; |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 20 | };; // expected-warning{{extra ';' after member function definition}} |
Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 21 | |
Richard Trieu | 4b0e6f1 | 2012-05-16 19:04:59 +0000 | [diff] [blame] | 22 | template<typename T> void mt(T) { } |
Richard Smith | eab9d6f | 2012-07-23 05:45:25 +0000 | [diff] [blame] | 23 | ; |
Douglas Gregor | 9ea416e | 2011-01-19 16:41:58 +0000 | [diff] [blame] | 24 | ; // expected-warning{{extra ';' inside a class}} |
| 25 | |
Sebastian Redl | ab963c6 | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 26 | virtual int vf() const volatile = 0; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 27 | |
| 28 | private: |
| 29 | int x,f(),y,g(); |
Sebastian Redl | ab963c6 | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 30 | inline int h(); |
| 31 | static const int sci = 10; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 32 | mutable int mi; |
Argyrios Kyrtzidis | 4cc18a4 | 2008-06-24 22:12:16 +0000 | [diff] [blame] | 33 | }; |
Sebastian Redl | ab963c6 | 2008-11-08 15:40:37 +0000 | [diff] [blame] | 34 | void glo() |
| 35 | { |
| 36 | struct local {}; |
| 37 | } |
Chris Lattner | bc8d564 | 2008-12-18 01:12:00 +0000 | [diff] [blame] | 38 | |
| 39 | // PR3177 |
| 40 | typedef union { |
| 41 | __extension__ union { |
| 42 | int a; |
| 43 | float b; |
| 44 | } y; |
| 45 | } bug3177; |
| 46 | |
David Blaikie | 13f8daf | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 47 | // check that we don't consume the token after the access specifier |
| 48 | // when it's not a colon |
| 49 | class D { |
| 50 | public // 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 |
| 56 | class E { |
| 57 | public; // expected-error{{expected ':'}} |
| 58 | int i; |
| 59 | }; |
| 60 | |
Richard Trieu | 65ba948 | 2012-01-21 02:59:18 +0000 | [diff] [blame] | 61 | class 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 Smith | 412e0cc | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 68 | namespace 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 Smith | 52f10d5 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 79 | void operator+(UnknownType*); // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | 412e0cc | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | Ctor::Ctor (x) = { 0 }; // \ |
| 83 | // expected-error{{qualified reference to 'Ctor' is a constructor name}} |
| 84 | |
Richard Smith | 412e0cc | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 85 | Ctor::Ctor(UnknownType *) {} // \ |
Richard Smith | 52f10d5 | 2012-03-29 01:46:00 +0000 | [diff] [blame] | 86 | // expected-error{{unknown type name 'UnknownType'}} |
| 87 | void Ctor::operator+(UnknownType*) {} // \ |
| 88 | // expected-error{{unknown type name 'UnknownType'}} |
Richard Smith | 412e0cc | 2012-03-27 00:56:56 +0000 | [diff] [blame] | 89 | } |
| 90 | |
Richard Smith | c7f8116 | 2013-03-18 22:52:47 +0000 | [diff] [blame] | 91 | namespace 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 Smith | 69e4826 | 2012-09-06 01:37:56 +0000 | [diff] [blame] | 102 | // PR13775: Don't assert here. |
| 103 | namespace 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 | |
David Blaikie | 13f8daf | 2011-10-13 06:08:43 +0000 | [diff] [blame] | 116 | // PR11109 must appear at the end of the source file |
| 117 | class pr11109r3 { // expected-note{{to match this '{'}} |
| 118 | public // expected-error{{expected ':'}} expected-error{{expected '}'}} expected-error{{expected ';' after class}} |