1 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
4 auto int errx; // expected-error {{storage class specified for a member declaration}} expected-warning {{'auto' storage class specifier is redundant}}
5 register int erry; // expected-error {{storage class specified for a member declaration}}
6 extern int errz; // expected-error {{storage class specified for a member declaration}}
10 this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}}
11 x = 0; // expected-error {{invalid use of member 'x' in static member function}}
19 x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
21 m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
27 typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
28 static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
34 func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
35 NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
39 int i = 0; // expected-warning {{in-class initialization of non-static data member is a C++11 extension}}
40 static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
41 static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
42 static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
43 static const int vi = 0;
44 static const volatile int cvi = 0; // ok, illegal in C++11
45 static const E evi = 0;
51 this = 0; // expected-error {{expression is not assignable}}
56 return p + x + this->y + z;
61 virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
62 virtual static int vsif(); // expected-error {{'virtual' can only appear on non-static member functions}}
70 mutable int &mir; // expected-error {{'mutable' cannot be applied to references}}
71 mutable void mfn(); // expected-error {{'mutable' cannot be applied to functions}}
72 mutable const int mci; // expected-error {{'mutable' and 'const' cannot be mixed}}
74 static const int number = 50;
75 static int arr[number];
82 int m() { return lx; }
85 int m() { return lx; }
96 const C3 c3 = { 1, 2 };
97 (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
99 (void)static_cast<int*>(&c3.j);
102 // Play with mutable a bit more, to make sure it doesn't crash anything.
103 mutable int gi; // expected-error {{'mutable' can only be applied to member variables}}
104 mutable void gfn(); // expected-error {{illegal storage class on function}}
107 mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
109 // PR3020: This used to crash due to double ownership of C4.
111 C4; // expected-warning {{declaration does not declare anything}}
115 void f(); // expected-note{{previous declaration is here}}
116 int f; // expected-error{{duplicate member 'f'}}
119 // PR5415 - don't hang!
122 void f(); // expected-note 1 {{previous declaration}}
123 void S::f() {} // expected-warning {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
124 void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
127 // Don't crash on this bogus code.
129 // TODO: most of these errors are spurious
130 template<class T1, class T2> struct foo :
131 bogus<foo<T1,T2> > // expected-error {{unknown template name 'bogus'}} \
132 // BOGUS expected-error {{expected '{' after base class list}} \
133 // BOGUS expected-error {{expected ';' after struct}} \
134 // BOGUS expected-error {{expected unqualified-id}}
137 template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
138 template <typename U1, typename U2> struct bar {
140 static const int value = 0;
146 class EnclosingClass {
148 struct A { } mutable *member;
151 void f(const EnclosingClass &ec) {
162 enum { x = sizeof(i) };
163 enum { y = sizeof(a) };
168 namespace rdar8066414 {
171 } // expected-error{{expected ';' after class}}
174 namespace rdar8367341 {
178 static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
179 static const float y = foo(); // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}} expected-error {{in-class initializer for static data member is not a constant expression}}
183 namespace with_anon {
191 S::c; // expected-error {{invalid use of non-static data member}}
196 static int const PR9989_Member = sizeof PR9989_Member;