1 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
2 class C {
3 public:
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}}
7
sm()8 static void sm() {
9 sx = 0;
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}}
12 }
13
14 class NestedC {
15 public:
16 NestedC(int);
f()17 void f() {
18 sx = 0;
19 x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
20 sm();
21 m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
22 }
23 };
24
25 int b : 1, w : 2;
26 int : 1, : 2;
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}}
29 static int vs;
30
31 typedef int func();
32 func tm;
33 func *ptm;
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}}
36
37 enum E1 { en1, en2 };
38
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;
46
m()47 void m() {
48 sx = 0;
49 this->x = 0;
50 y = 0;
51 this = 0; // expected-error {{expression is not assignable}}
52 }
53
f1(int p)54 int f1(int p) {
55 A z = 6;
56 return p + x + this->y + z;
57 }
58
59 typedef int A;
60
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}}
63 virtual int vif();
64
65 private:
66 int x,y;
67 static int sx;
68
69 mutable int mi;
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}}
73
74 static const int number = 50;
75 static int arr[number];
76 };
77
78 class C2 {
f()79 void f() {
80 static int lx;
81 class LC1 {
82 int m() { return lx; }
83 };
84 class LC2 {
85 int m() { return lx; }
86 };
87 }
88 };
89
90 struct C3 {
91 int i;
92 mutable int j;
93 };
f()94 void f()
95 {
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}}
98 // but no error here
99 (void)static_cast<int*>(&c3.j);
100 }
101
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}}
ogfn()105 void ogfn()
106 {
107 mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
108
109 // PR3020: This used to crash due to double ownership of C4.
110 struct C4;
111 C4; // expected-warning {{declaration does not declare anything}}
112 }
113
114 struct C4 {
115 void f(); // expected-note{{previous declaration is here}}
116 int f; // expected-error{{duplicate member 'f'}}
117 };
118
119 // PR5415 - don't hang!
120 struct S
121 {
122 void f(); // expected-note 1 {{previous declaration}}
f()123 void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}} expected-note {{previous declaration}} expected-note {{previous definition}}
fS124 void f() {} // expected-error {{class member cannot be redeclared}} expected-error {{redefinition}}
125 };
126
127 // Don't crash on this bogus code.
128 namespace pr6629 {
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}}
135 { };
136
137 template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
138 template <typename U1, typename U2> struct bar {
139 typedef bar type;
140 static const int value = 0;
141 };
142 };
143 }
144
145 namespace PR7153 {
146 class EnclosingClass {
147 public:
148 struct A { } mutable *member;
149 };
150
f(const EnclosingClass & ec)151 void f(const EnclosingClass &ec) {
152 ec.member = 0;
153 }
154 }
155
156 namespace PR7196 {
157 struct A {
158 int a;
159
fPR7196::A160 void f() {
161 char i[sizeof(a)];
162 enum { x = sizeof(i) };
163 enum { y = sizeof(a) };
164 }
165 };
166 }
167
168 namespace rdar8066414 {
169 class C {
C()170 C() {}
171 } // expected-error{{expected ';' after class}}
172 }
173
174 namespace rdar8367341 {
175 float foo();
176
177 struct A {
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}}
180 };
181 }
182
183 namespace with_anon {
184 struct S {
185 union {
186 char c;
187 };
188 };
189
190 void f() {
191 S::c; // expected-error {{invalid use of non-static data member}}
192 }
193 }
194
195 struct PR9989 {
196 static int const PR9989_Member = sizeof PR9989_Member;
197 };
198