150
|
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s
|
|
2 // RUN: %clang_cc1 -fsyntax-only -verify -Wc++11-compat %s -std=c++98
|
|
3 class C {
|
|
4 public:
|
|
5 auto int errx; // expected-error {{storage class specified for a member declaration}}
|
|
6 #if __cplusplus <= 199711L
|
|
7 // expected-warning@-2 {{'auto' storage class specifier is redundant}}
|
|
8 #else
|
|
9 // expected-warning@-4 {{'auto' storage class specifier is not permitted in C++11, and will not be supported in future releases}}
|
|
10 #endif
|
|
11 register int erry; // expected-error {{storage class specified for a member declaration}}
|
|
12 extern int errz; // expected-error {{storage class specified for a member declaration}}
|
|
13
|
|
14 static void sm() {
|
|
15 sx = 0;
|
|
16 this->x = 0; // expected-error {{invalid use of 'this' outside of a non-static member function}}
|
|
17 x = 0; // expected-error {{invalid use of member 'x' in static member function}}
|
|
18 }
|
|
19
|
|
20 class NestedC {
|
|
21 public:
|
|
22 NestedC(int);
|
|
23 void f() {
|
|
24 sx = 0;
|
|
25 x = 0; // expected-error {{use of non-static data member 'x' of 'C' from nested type 'NestedC'}}
|
|
26 sm();
|
|
27 m(); // expected-error {{call to non-static member function 'm' of 'C' from nested type 'NestedC'}}
|
|
28 }
|
|
29 };
|
|
30
|
|
31 int b : 1, w : 2;
|
|
32 int : 1, : 2;
|
|
33 typedef int E : 1; // expected-error {{typedef member 'E' cannot be a bit-field}}
|
|
34 static int sb : 1; // expected-error {{static member 'sb' cannot be a bit-field}}
|
|
35 static int vs;
|
|
36
|
|
37 typedef int func();
|
|
38 func tm;
|
|
39 func *ptm;
|
|
40 func btm : 1; // expected-error {{bit-field 'btm' has non-integral type}}
|
|
41 NestedC bc : 1; // expected-error {{bit-field 'bc' has non-integral type}}
|
|
42
|
|
43 enum E1 { en1, en2 };
|
|
44
|
|
45 int i = 0;
|
|
46 #if __cplusplus <= 199711L
|
221
|
47 // expected-warning@-2 {{default member initializer for non-static data member is a C++11 extension}}
|
150
|
48 #endif
|
|
49 static int si = 0; // expected-error {{non-const static data member must be initialized out of line}}
|
|
50 static const NestedC ci = 0; // expected-error {{static data member of type 'const C::NestedC' must be initialized out of line}}
|
|
51 static const int nci = vs; // expected-error {{in-class initializer for static data member is not a constant expression}}
|
|
52 static const int vi = 0;
|
|
53 static const volatile int cvi = 0; // ok, illegal in C++11
|
|
54 #if __cplusplus >= 201103L
|
|
55 // expected-error@-2 {{static const volatile data member must be initialized out of line}}
|
|
56 #endif
|
|
57 static const E evi = 0;
|
|
58
|
|
59 void m() {
|
|
60 sx = 0;
|
|
61 this->x = 0;
|
|
62 y = 0;
|
|
63 this = 0; // expected-error {{expression is not assignable}}
|
|
64 }
|
|
65
|
|
66 int f1(int p) {
|
|
67 A z = 6;
|
|
68 return p + x + this->y + z;
|
|
69 }
|
|
70
|
|
71 typedef int A;
|
|
72
|
|
73 virtual int viv; // expected-error {{'virtual' can only appear on non-static member functions}}
|
|
74 virtual static int vsif(); // expected-error {{'virtual' can only appear on non-static member functions}}
|
|
75 virtual int vif();
|
|
76
|
|
77 private:
|
|
78 int x,y;
|
|
79 static int sx;
|
|
80
|
|
81 mutable int mi;
|
|
82 mutable int &mir; // expected-error {{'mutable' cannot be applied to references}}
|
|
83 mutable void mfn(); // expected-error {{'mutable' cannot be applied to functions}}
|
|
84 mutable const int mci; // expected-error {{'mutable' and 'const' cannot be mixed}}
|
|
85
|
|
86 static const int number = 50;
|
|
87 static int arr[number];
|
|
88 };
|
|
89
|
|
90 class C2 {
|
|
91 void f() {
|
|
92 static int lx;
|
|
93 class LC1 {
|
|
94 int m() { return lx; }
|
|
95 };
|
|
96 class LC2 {
|
|
97 int m() { return lx; }
|
|
98 };
|
|
99 }
|
|
100 };
|
|
101
|
|
102 struct C3 {
|
|
103 int i;
|
|
104 mutable int j;
|
|
105 };
|
|
106 void f()
|
|
107 {
|
|
108 const C3 c3 = { 1, 2 };
|
|
109 (void)static_cast<int*>(&c3.i); // expected-error {{static_cast from 'const int *' to 'int *' is not allowed}}
|
|
110 // but no error here
|
|
111 (void)static_cast<int*>(&c3.j);
|
|
112 }
|
|
113
|
|
114 // Play with mutable a bit more, to make sure it doesn't crash anything.
|
|
115 mutable int gi; // expected-error {{'mutable' can only be applied to member variables}}
|
|
116 mutable void gfn(); // expected-error {{illegal storage class on function}}
|
|
117 void ogfn()
|
|
118 {
|
|
119 mutable int ml; // expected-error {{'mutable' can only be applied to member variables}}
|
|
120
|
|
121 // PR3020: This used to crash due to double ownership of C4.
|
|
122 struct C4;
|
|
123 C4; // expected-warning {{declaration does not declare anything}}
|
|
124 }
|
|
125
|
|
126 struct C4 {
|
|
127 void f(); // expected-note{{previous declaration is here}}
|
|
128 int f; // expected-error{{duplicate member 'f'}}
|
|
129 };
|
|
130
|
|
131 // PR5415 - don't hang!
|
|
132 struct S
|
|
133 {
|
|
134 void f(); // expected-note 1 {{previous declaration}} expected-note {{previous declaration}}
|
|
135 void S::f() {} // expected-error {{extra qualification on member}} expected-error {{class member cannot be redeclared}}
|
|
136 void f() {} // expected-error {{class member cannot be redeclared}}
|
|
137 };
|
|
138
|
|
139 // Don't crash on this bogus code.
|
|
140 namespace pr6629 {
|
|
141 template<class T1, class T2> struct foo :
|
|
142 bogus<foo<T1,T2> > // expected-error {{no template named 'bogus'}}
|
|
143 { };
|
|
144
|
|
145 template<> struct foo<unknown,unknown> { // expected-error {{undeclared identifier 'unknown'}}
|
|
146 template <typename U1, typename U2> struct bar {
|
|
147 typedef bar type;
|
|
148 static const int value = 0;
|
|
149 };
|
|
150 };
|
|
151 }
|
|
152
|
|
153 namespace PR7153 {
|
|
154 class EnclosingClass {
|
|
155 public:
|
|
156 struct A { } mutable *member;
|
|
157 };
|
|
158
|
|
159 void f(const EnclosingClass &ec) {
|
|
160 ec.member = 0;
|
|
161 }
|
|
162 }
|
|
163
|
|
164 namespace PR7196 {
|
|
165 struct A {
|
|
166 int a;
|
|
167
|
|
168 void f() {
|
|
169 char i[sizeof(a)];
|
|
170 enum { x = sizeof(i) };
|
|
171 enum { y = sizeof(a) };
|
|
172 }
|
|
173 };
|
|
174 }
|
|
175
|
|
176 namespace rdar8066414 {
|
|
177 class C {
|
|
178 C() {}
|
|
179 } // expected-error{{expected ';' after class}}
|
|
180 }
|
|
181
|
|
182 namespace rdar8367341 {
|
|
183 float foo();
|
|
184 #if __cplusplus >= 201103L
|
|
185 // expected-note@-2 {{declared here}}
|
|
186 #endif
|
|
187
|
|
188 struct A {
|
|
189 #if __cplusplus <= 199711L
|
|
190 static const float x = 5.0f; // expected-warning {{in-class initializer for static data member of type 'const float' is a GNU extension}}
|
|
191 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}}
|
|
192 #else
|
|
193 static constexpr float x = 5.0f;
|
|
194 static constexpr float y = foo(); // expected-error {{constexpr variable 'y' must be initialized by a constant expression}} expected-note {{non-constexpr function 'foo' cannot be used in a constant expression}}
|
|
195 #endif
|
|
196 };
|
|
197 }
|
|
198
|
|
199 namespace with_anon {
|
|
200 struct S {
|
|
201 union {
|
|
202 char c;
|
|
203 };
|
|
204 };
|
|
205
|
|
206 void f() {
|
|
207 S::c; // expected-error {{invalid use of non-static data member}}
|
|
208 }
|
|
209 }
|
|
210
|
|
211 struct PR9989 {
|
|
212 static int const PR9989_Member = sizeof PR9989_Member;
|
|
213 };
|