Debian Codegraph @

clang/test/CXX/drs/cwg19xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 %s -verify=expected,cxx98-11,cxx98 -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify=expected,cxx98-11,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c %s -verify=expected,since-cxx14,since-cxx11 -fexceptions -fcxx-exceptions -pedantic-errors
8
9 namespace std { struct type_info; }
10
11 namespace cwg1902 { // cwg1902: 3.7
12 struct A {};
13 struct B {
14 B(A); // #cwg1902-B-A
15 B() = delete; // #cwg1902-B-ctor
16 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
17 B(const B&) = delete; // #cwg1902-B-copy-ctor
18 // cxx98-error@-1 {{deleted function definitions are a C++11 extension}}
19 operator A();
20 };
21
22 extern B b1;
23 B b2(b1);
24 // expected-error@-1 {{call to deleted constructor of 'B'}}
25 // expected-note@#cwg1902-B-copy-ctor {{'B' has been explicitly marked deleted here}}
26
27 #if __cplusplus >= 201103L
28 // This is ambiguous, even though calling the B(const B&) constructor would
29 // both directly and indirectly call a deleted function.
30 B b({});
31 // since-cxx11-error@-1 {{call to constructor of 'B' is ambiguous}}
32 // since-cxx11-note@#cwg1902-B-A {{candidate constructor}}
33 // since-cxx11-note@#cwg1902-B-copy-ctor {{candidate constructor has been explicitly deleted}}
34 #endif
35 }
36
37 namespace cwg1903 { // cwg1903: 2.7
38 namespace A {
39 struct a {};
40 int a;
41 namespace B {
42 int b;
43 }
44 using namespace B;
45 namespace {
46 int c;
47 }
48 namespace D {
49 int d;
50 }
51 using D::d;
52 }
53 namespace X {
54 using A::a;
55 using A::b;
56 using A::c;
57 using A::d;
58 struct a *p;
59 }
60 }
61
62 namespace cwg1909 { // cwg1909: 3.7
63 struct A {
64 template<typename T> struct A {};
65 // expected-error@-1 {{member 'A' has the same name as its class}}
66 };
67 struct B {
68 template<typename T> void B() {}
69 // expected-error@-1 {{constructor cannot have a return type}}
70 };
71 struct C {
72 template<typename T> static int C;
73 // expected-error@-1 {{member 'C' has the same name as its class}}
74 // cxx98-11-error@-2 {{variable templates are a C++14 extension}}
75 };
76 struct D {
77 template<typename T> using D = int;
78 // cxx98-error@-1 {{alias declarations are a C++11 extension}}
79 // expected-error@-2 {{member 'D' has the same name as its class}}
80 };
81 }
82
83 namespace cwg1918 { // cwg1918: no
84 template<typename T> struct A {
85 class B {
86 class C {};
87 };
88 };
89 class X {
90 static int x;
91 // FIXME: this is ill-formed, because A<T>::B::C does not end with a simple-template-id
92 template <typename T>
93 friend class A<T>::B::C;
94 // expected-warning@-1 {{dependent nested name specifier 'A<T>::B::' for friend class declaration is not supported; turning off access control for 'X'}}
95 };
96 template<> struct A<int> {
97 typedef struct Q B;
98 };
99 struct Q {
100 class C {
101 // FIXME: 'f' is not a friend, so 'X::x' is not accessible
102 int f() { return X::x; }
103 };
104 };
105 } // namespace cwg1918
106
107 namespace cwg1940 { // cwg1940: 3.5
108 #if __cplusplus >= 201103L
109 static union {
110 static_assert(true, ""); // ok
111 static_assert(false, "");
112 // since-cxx11-error@-1 {{static assertion failed}}
113 int not_empty;
114 };
115 #endif
116 }
117
118 namespace cwg1941 { // cwg1941: 3.9
119 #if __cplusplus >= 201402L
120 template<typename X>
121 struct base {
122 template<typename T>
123 base(T a, T b, decltype(void(*T()), 0) = 0) {
124 while (a != b) (void)*a++;
125 }
126
127 template<typename T>
128 base(T a, X x, decltype(void(T(0) * 1), 0) = 0) {
129 for (T n = 0; n != a; ++n) (void)X(x);
130 }
131 };
132
133 struct derived : base<int> {
134 using base::base;
135 };
136
137 struct iter {
138 iter operator++(int);
139 int operator*();
140 friend bool operator!=(iter, iter);
141 } it, end;
142
143 derived d1(it, end);
144 derived d2(42, 9);
145 #endif
146 }
147
148 namespace cwg1945 { // cwg1945: no
149 template<typename T> struct A {
150 class B {
151 class C {};
152 };
153 };
154 class X {
155 static int x;
156 // FIXME: this is ill-formed, because A<T>::B::C does not end with a simple-template-id
157 template <typename T>
158 friend class A<T>::B::C;
159 // expected-warning@-1 {{dependent nested name specifier 'A<T>::B::' for friend class declaration is not supported; turning off access control for 'X'}}
160 };
161 } // namespace cwg1945
162
163 namespace cwg1947 { // cwg1947: 3.5
164 #if __cplusplus >= 201402L
165 unsigned o = 0'01; // ok
166 unsigned b = 0b'01;
167 // since-cxx14-error@-1 {{invalid digit 'b' in octal constant}}
168 unsigned x = 0x'01;
169 // since-cxx14-error@-1 {{invalid suffix 'x'01' on integer constant}}
170 #endif
171 }
172
173 #if __cplusplus >= 201103L
174 // cwg1948: 3.5
175 // FIXME: This diagnostic could be improved.
176 void *operator new(__SIZE_TYPE__) noexcept { return nullptr; }
177 // since-cxx11-error@-1 {{exception specification in declaration does not match previous declaration}}
178 #endif
179
180 namespace cwg1959 { // cwg1959: 3.9
181 #if __cplusplus >= 201103L
182 struct b;
183 struct c;
184 struct a {
185 a() = default;
186 a(const a &) = delete; // #cwg1959-copy-ctor
187 a(const b &) = delete; // not inherited
188 a(c &&) = delete; // #cwg1959-move-ctor
189 template<typename T> a(T) = delete; // #cwg1959-temp-ctor
190 };
191
192 struct b : a { // #cwg1959-b
193 using a::a; // #cwg1959-using-a
194 };
195
196 a x;
197 // FIXME: As a resolution to an open DR against P0136R0, we disallow
198 // use of inherited constructors to construct from a single argument
199 // where the base class is reference-related to the argument type.
200 b y = x;
201 // since-cxx11-error@-1 {{no viable conversion from 'a' to 'b'}}
202 // since-cxx11-note@#cwg1959-move-ctor {{candidate inherited constructor not viable: no known conversion from 'a' to 'c &&' for 1st argument}}
203 // since-cxx11-note@#cwg1959-using-a {{constructor from base class 'a' inherited here}}
204 // since-cxx11-note@#cwg1959-b {{candidate constructor (the implicit copy constructor) not viable: cannot bind base class object of type 'a' to derived class reference 'const b &' for 1st argument}}
205 // since-cxx11-note@#cwg1959-temp-ctor {{candidate template ignored: instantiation would take its own class type by value}}
206 // since-cxx11-note@#cwg1959-using-a {{constructor from base class 'a' inherited here}}
207 b z = z;
208 // since-cxx11-error@-1 {{call to implicitly-deleted copy constructor of 'b'}}
209 // since-cxx11-note@#cwg1959-b {{copy constructor of 'b' is implicitly deleted because base class 'a' has a deleted copy constructor}}
210 // since-cxx11-note@#cwg1959-copy-ctor {{'a' has been explicitly marked deleted here}}
211
212 struct c : a {
213 using a::a;
214 c(const c &);
215 };
216 // FIXME: As a resolution to an open DR against P0136R0, we disallow
217 // use of inherited constructors to construct from a single argument
218 // where the base class is reference-related to the argument type.
219 c q(static_cast<c&&>(q));
220 #endif
221 }
222
223 namespace cwg1960 { // cwg1960: no
224 struct A {
225 void f() {}
226 protected:
227 void g() {}
228 };
229
230 struct B: A {
231 private:
232 using A::f;
233 using A::g;
234 };
235
236 struct C : B {
237 // FIXME: both declarations are ill-formed, because A::f and A::g
238 // are not accessible.
239 using A::f;
240 using A::g;
241 };
242 }
243
244 namespace cwg1966 { // cwg1966: 11
245 #if __cplusplus >= 201103L
246 struct A {
247 enum E : int {1};
248 // since-cxx11-error@-1 {{expected identifier}} (not bit-field)
249 };
250 auto *p1 = new enum E : int;
251 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
252 auto *p2 = new enum F : int {};
253 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
254 auto *p3 = true ? new enum G : int {};
255 // since-cxx11-error@-1 {{ISO C++ forbids forward references to 'enum' types}}
256 // since-cxx11-error@-2 {{allocation of incomplete type 'enum G'}}
257 // since-cxx11-note@-3 {{forward declaration of 'cwg1966::G'}}
258 auto h() -> enum E : int {};
259 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration}}
260
261 enum X : enum Y : int {} {};
262 // since-cxx11-error@-1 {{'cwg1966::Y' cannot be defined in a type specifier}}
263 struct Q {
264 // FIXME: can we emit something nicer than that?
265 enum X : enum Y : int {} {};
266 // since-cxx11-error@-1 {{non-defining declaration of enumeration with a fixed underlying type is only permitted as a standalone declaration; missing list of enumerators?}}
267 // since-cxx11-error@-2 {{non-integral type 'enum Y' is an invalid underlying type}}
268 // since-cxx11-error@-3 {{anonymous bit-field cannot have a default member initializer}}
269 };
270 #endif
271 }
272
273 namespace cwg1968 { // cwg1968: no
274 #if __cplusplus >= 201103L
275 // FIXME: According to CWG1968, both of these should be considered
276 // non-constant.
277 static_assert(&typeid(int) == &typeid(int), "");
278
279 constexpr const std::type_info *f() { return &typeid(int); }
280 static_assert(f() == f(), "");
281 #endif
282 }
283
284 namespace cwg1991 { // cwg1991: 3.9
285 #if __cplusplus >= 201103L
286 struct A {
287 A(int, int) = delete;
288 };
289
290 struct B : A {
291 using A::A;
292 B(int, int, int = 0);
293 };
294
295 // FIXME: As a resolution to an open DR against P0136R1, we treat derived
296 // class constructors as better than base class constructors in the presence
297 // of ambiguity.
298 B b(0, 0); // ok, calls B constructor
299 #endif
300 }
301
302 // cwg1994: dup 529