Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 2 | class C { |
| 3 | public: |
| 4 | auto int errx; // expected-error {{error: storage class specified for a member declaration}} |
| 5 | register int erry; // expected-error {{error: storage class specified for a member declaration}} |
| 6 | extern int errz; // expected-error {{error: storage class specified for a member declaration}} |
| 7 | |
| 8 | static void sm() { |
| 9 | sx = 0; |
| 10 | this->x = 0; // expected-error {{error: invalid use of 'this' outside of a nonstatic member function}} |
| 11 | x = 0; // expected-error {{error: invalid use of member 'x' in static member function}} |
| 12 | } |
| 13 | |
| 14 | class NestedC { |
| 15 | void m() { |
| 16 | sx = 0; |
| 17 | x = 0; // expected-error {{error: invalid use of nonstatic data member 'x'}} |
| 18 | } |
| 19 | }; |
| 20 | |
| 21 | int b : 1, w : 2; |
| 22 | int : 1, : 2; |
Chris Lattner | 8b963ef | 2009-03-05 23:01:03 +0000 | [diff] [blame] | 23 | typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}} |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 24 | static int sb : 1; // expected-error {{error: static member 'sb' cannot be a bit-field}} |
| 25 | static int vs; |
| 26 | |
| 27 | typedef int func(); |
| 28 | func tm; |
Argyrios Kyrtzidis | d6caa9e | 2008-10-15 20:23:22 +0000 | [diff] [blame] | 29 | func *ptm; |
Douglas Gregor | 3cf538d | 2009-03-11 18:59:21 +0000 | [diff] [blame] | 30 | func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}} |
| 31 | NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}} |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 32 | |
Douglas Gregor | 6697312 | 2009-01-28 17:15:10 +0000 | [diff] [blame] | 33 | enum E1 { en1, en2 }; |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 34 | |
| 35 | int i = 0; // expected-error {{error: 'i' can only be initialized if it is a static const integral data member}} |
| 36 | static int si = 0; // expected-error {{error: 'si' can only be initialized if it is a static const integral data member}} |
| 37 | static const NestedC ci = 0; // expected-error {{error: 'ci' can only be initialized if it is a static const integral data member}} |
Douglas Gregor | 021c3b3 | 2009-03-11 23:00:04 +0000 | [diff] [blame] | 38 | static const int nci = vs; // expected-error {{in-class initializer is not an integral constant expression}} |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 39 | static const int vi = 0; |
| 40 | static const E evi = 0; |
| 41 | |
| 42 | void m() { |
| 43 | sx = 0; |
| 44 | this->x = 0; |
| 45 | y = 0; |
| 46 | this = 0; // expected-error {{error: expression is not assignable}} |
| 47 | } |
| 48 | |
| 49 | int f1(int p) { |
Sebastian Redl | d93f0dd | 2008-11-06 15:59:35 +0000 | [diff] [blame] | 50 | A z = 6; |
| 51 | return p + x + this->y + z; |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | typedef int A; |
| 55 | |
Douglas Gregor | 021c3b3 | 2009-03-11 23:00:04 +0000 | [diff] [blame] | 56 | virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}} |
Sebastian Redl | d93f0dd | 2008-11-06 15:59:35 +0000 | [diff] [blame] | 57 | virtual static int vsif(); // expected-error {{error: 'virtual' can only appear on non-static member functions}} |
| 58 | virtual int vif(); |
| 59 | |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 60 | private: |
| 61 | int x,y; |
| 62 | static int sx; |
Argyrios Kyrtzidis | de933f0 | 2008-10-08 22:20:31 +0000 | [diff] [blame] | 63 | |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 64 | mutable int mi; |
| 65 | mutable int &mir; // expected-error {{error: 'mutable' cannot be applied to references}} |
| 66 | mutable void mfn(); // expected-error {{error: 'mutable' cannot be applied to functions}} |
| 67 | mutable const int mci; // expected-error {{error: 'mutable' and 'const' cannot be mixed}} |
| 68 | |
Argyrios Kyrtzidis | de933f0 | 2008-10-08 22:20:31 +0000 | [diff] [blame] | 69 | static const int number = 50; |
| 70 | static int arr[number]; |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | class C2 { |
| 74 | void f() { |
| 75 | static int lx; |
| 76 | class LC1 { |
| 77 | int m() { return lx; } |
| 78 | }; |
| 79 | class LC2 { |
| 80 | int m() { return lx; } |
| 81 | }; |
| 82 | } |
| 83 | }; |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 84 | |
Sebastian Redl | a11f42f | 2008-11-17 23:24:37 +0000 | [diff] [blame] | 85 | struct C3 { |
| 86 | int i; |
| 87 | mutable int j; |
| 88 | }; |
| 89 | void f() |
| 90 | { |
| 91 | const C3 c3 = { 1, 2 }; |
| 92 | (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'int const *' to 'int *' is not allowed}} |
| 93 | // but no error here |
| 94 | (void)static_cast<int*>(&c3.j); |
| 95 | } |
| 96 | |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 97 | // Play with mutable a bit more, to make sure it doesn't crash anything. |
| 98 | mutable int gi; // expected-error {{error: 'mutable' can only be applied to member variables}} |
| 99 | mutable void gfn(); // expected-error {{illegal storage class on function}} |
| 100 | void ogfn() |
| 101 | { |
| 102 | mutable int ml; // expected-error {{error: 'mutable' can only be applied to member variables}} |
Sebastian Redl | a4ed0d8 | 2008-12-28 15:28:59 +0000 | [diff] [blame] | 103 | |
| 104 | // PR3020: This used to crash due to double ownership of C4. |
| 105 | struct C4; |
Douglas Gregor | cb821d0 | 2010-04-08 21:33:23 +0000 | [diff] [blame] | 106 | C4; // expected-warning {{declaration does not declare anything}} |
Sebastian Redl | 669d5d7 | 2008-11-14 23:42:31 +0000 | [diff] [blame] | 107 | } |
Douglas Gregor | 72de667 | 2009-01-08 20:45:30 +0000 | [diff] [blame] | 108 | |
| 109 | struct C4 { |
| 110 | void f(); // expected-note{{previous declaration is here}} |
| 111 | int f; // expected-error{{duplicate member 'f'}} |
| 112 | }; |
Sebastian Redl | 46408ee | 2009-11-24 17:14:34 +0000 | [diff] [blame] | 113 | |
| 114 | // PR5415 - don't hang! |
| 115 | struct S |
| 116 | { |
Sebastian Redl | d1a7846 | 2009-11-24 23:38:44 +0000 | [diff] [blame] | 117 | void f(); // expected-note 1 {{previous declaration}} |
| 118 | void S::f() {} // expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}} |
Sebastian Redl | 46408ee | 2009-11-24 17:14:34 +0000 | [diff] [blame] | 119 | void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}} |
| 120 | }; |
John McCall | 4ad287e | 2010-03-17 01:31:25 +0000 | [diff] [blame] | 121 | |
| 122 | // Don't crash on this bogus code. |
| 123 | namespace pr6629 { |
| 124 | // TODO: most of these errors are spurious |
| 125 | template<class T1, class T2> struct foo : |
| 126 | bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \ |
| 127 | // BOGUS expected-error {{expected '{' after base class list}} \ |
| 128 | // BOGUS expected-error {{expected ';' after struct}} \ |
| 129 | // BOGUS expected-error {{expected unqualified-id}} \ |
| 130 | { }; |
| 131 | |
| 132 | template<> struct foo<unknown,unknown> { // why isn't there an error here? |
| 133 | template <typename U1, typename U2> struct bar { |
| 134 | typedef bar type; |
| 135 | static const int value = 0; |
| 136 | }; |
| 137 | }; |
| 138 | } |