1 // RUN: %clang_cc1 -fsyntax-only -verify %s
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}}
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}}
19 x = 0; // expected-error {{invalid use of nonstatic data member 'x'}}
25 typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
26 static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
32 func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
33 NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
37 int i = 0; // expected-warning {{in-class initialization of non-static data member accepted as a C++0x extension}}
38 static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
39 static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
40 static const int nci = vs; // expected-error {{in-class initializer is not a constant expression}}
41 static const int vi = 0;
42 static const E evi = 0;
48 this = 0; // expected-error {{error: expression is not assignable}}
53 return p + x + this->y + z;
58 virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
59 virtual static int vsif(); // expected-error {{error: 'virtual' can only appear on non-static member functions}}
67 mutable int &mir; // expected-error {{error: 'mutable' cannot be applied to references}}
68 mutable void mfn(); // expected-error {{error: 'mutable' cannot be applied to functions}}
69 mutable const int mci; // expected-error {{error: 'mutable' and 'const' cannot be mixed}}
71 static const int number = 50;
72 static int arr[number];
79 int m() { return lx; }
82 int m() { return lx; }
93 const C3 c3 = { 1, 2 };
94 (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
96 (void)static_cast<int*>(&c3.j);
99 // Play with mutable a bit more, to make sure it doesn't crash anything.
100 mutable int gi; // expected-error {{error: 'mutable' can only be applied to member variables}}
101 mutable void gfn(); // expected-error {{illegal storage class on function}}
104 mutable int ml; // expected-error {{error: 'mutable' can only be applied to member variables}}
106 // PR3020: This used to crash due to double ownership of C4.
108 C4; // expected-warning {{declaration does not declare anything}}
112 void f(); // expected-note{{previous declaration is here}}
113 int f; // expected-error{{duplicate member 'f'}}
116 // PR5415 - don't hang!
119 void f(); // expected-note 1 {{previous declaration}}
120 void S::f() {} // expected-warning {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
121 void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
124 // Don't crash on this bogus code.
126 // TODO: most of these errors are spurious
127 template<class T1, class T2> struct foo :
128 bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \
129 // BOGUS expected-error {{expected '{' after base class list}} \
130 // BOGUS expected-error {{expected ';' after struct}} \
131 // BOGUS expected-error {{expected unqualified-id}} \
134 template<> struct foo<unknown,unknown> { // why isn't there an error here?
135 template <typename U1, typename U2> struct bar {
137 static const int value = 0;
143 class EnclosingClass {
145 struct A { } mutable *member;
148 void f(const EnclosingClass &ec) {
159 enum { x = sizeof(i) };
160 enum { y = sizeof(a) };
165 namespace rdar8066414 {
168 } // expected-error{{expected ';' after class}}
171 namespace rdar8367341 {
175 static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a C++0x extension}}
176 static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' is a C++0x extension}} expected-error {{in-class initializer is not a constant expression}}
180 namespace with_anon {
188 S::c; // expected-error {{invalid use of nonstatic data member}}