Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 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; |
| 23 | typedef int E : 1; // expected-error {{error: cannot declare 'E' to be a bit-field type}} |
| 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; |
Argyrios Kyrtzidis | 0795232 | 2008-07-01 10:37:29 +0000 | [diff] [blame] | 30 | func btm : 1; // expected-error {{error: bit-field 'btm' with non-integral type}} |
| 31 | NestedC bc : 1; // expected-error {{error: bit-field 'bc' with non-integral type}} |
| 32 | |
| 33 | enum E { en1, en2 }; |
| 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}} |
Chris Lattner | d880363 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 38 | static const int nci = vs; // expected-error {{error: initializer element is not a compile-time constant}} |
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 | |
Sebastian Redl | d93f0dd | 2008-11-06 15:59:35 +0000 | [diff] [blame] | 56 | virtual int vi; // expected-error {{error: 'virtual' can only appear on non-static member functions}} |
| 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 | |
| 85 | // Play with mutable a bit more, to make sure it doesn't crash anything. |
| 86 | mutable int gi; // expected-error {{error: 'mutable' can only be applied to member variables}} |
| 87 | mutable void gfn(); // expected-error {{illegal storage class on function}} |
| 88 | void ogfn() |
| 89 | { |
| 90 | mutable int ml; // expected-error {{error: 'mutable' can only be applied to member variables}} |
| 91 | } |