Debian Codegraph @

clang/test/CXX/drs/cwg15xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify=expected -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14 -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,cxx11-14,cxx14-17 -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify=expected,cxx11-20,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify=expected,since-cxx23,since-cxx20,since-cxx11,since-cxx17 -fexceptions -fcxx-exceptions -pedantic-errors
8
9 namespace cwg1512 { // cwg1512: 4
10 void f(char *p) {
11 if (p > 0) {}
12 // expected-error@-1 {{ordered comparison between pointer and zero ('char *' and 'int')}}
13 #if __cplusplus >= 201103L
14 if (p > nullptr) {}
15 // since-cxx11-error@-1 {{invalid operands to binary expression ('char *' and 'std::nullptr_t')}}
16 #endif
17 }
18 bool g(int **x, const int **y) {
19 return x < y;
20 }
21
22 template<typename T> T val();
23
24 template<typename A, typename B, typename C> void composite_pointer_type_is_base() {
25 typedef __typeof(true ? val<A>() : val<B>()) type;
26 typedef C type;
27
28 typedef __typeof(val<A>() == val<B>()) cmp;
29 typedef __typeof(val<A>() != val<B>()) cmp;
30 typedef bool cmp;
31 }
32
33 template<typename A, typename B, typename C> void composite_pointer_type_is_ord() {
34 composite_pointer_type_is_base<A, B, C>();
35
36 typedef __typeof(val<A>() < val<B>()) cmp; // #cwg1512-lt
37 // since-cxx17-warning@#cwg1512-lt {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}
38 // since-cxx17-note@#cwg1512-noexcept-1st {{in instantiation of function template specialization 'cwg1512::composite_pointer_type_is_ord<int (*)() noexcept, int (*)(), int (*)()>' requested here}}
39 // since-cxx17-warning@#cwg1512-lt {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}
40 // since-cxx17-note@#cwg1512-noexcept-2nd {{in instantiation of function template specialization 'cwg1512::composite_pointer_type_is_ord<int (*)(), int (*)() noexcept, int (*)()>' requested here}}
41 typedef __typeof(val<A>() <= val<B>()) cmp;
42 // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}
43 // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}
44 typedef __typeof(val<A>() > val<B>()) cmp;
45 // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}
46 // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}
47 typedef __typeof(val<A>() >= val<B>()) cmp;
48 // since-cxx17-warning@-1 {{ordered comparison of function pointers ('int (*)() noexcept' and 'int (*)()')}}
49 // since-cxx17-warning@-2 {{ordered comparison of function pointers ('int (*)()' and 'int (*)() noexcept')}}
50 typedef bool cmp;
51 }
52
53 template <typename A, typename B, typename C>
54 void composite_pointer_type_is_unord(int = 0) {
55 composite_pointer_type_is_base<A, B, C>();
56 }
57 template <typename A, typename B, typename C>
58 void composite_pointer_type_is_unord(__typeof(val<A>() < val<B>()) * = 0);
59 template <typename A, typename B, typename C>
60 void composite_pointer_type_is_unord(__typeof(val<A>() <= val<B>()) * = 0);
61 template <typename A, typename B, typename C>
62 void composite_pointer_type_is_unord(__typeof(val<A>() > val<B>()) * = 0);
63 template <typename A, typename B, typename C>
64 void composite_pointer_type_is_unord(__typeof(val<A>() >= val<B>()) * = 0);
65
66 // A call to this is ambiguous if a composite pointer type exists.
67 template<typename A, typename B>
68 void no_composite_pointer_type(__typeof((true ? val<A>() : val<B>()), void()) * = 0);
69 template<typename A, typename B> void no_composite_pointer_type(int = 0);
70
71 struct A {};
72 struct B : A {};
73 struct C {};
74
75 void test() {
76 #if __cplusplus >= 201103L
77 using nullptr_t = decltype(nullptr);
78 composite_pointer_type_is_unord<nullptr_t, nullptr_t, nullptr_t>();
79 no_composite_pointer_type<nullptr_t, int>();
80
81 composite_pointer_type_is_unord<nullptr_t, const char**, const char**>();
82 composite_pointer_type_is_unord<const char**, nullptr_t, const char**>();
83 #endif
84
85 composite_pointer_type_is_ord<const int *, volatile void *, const volatile void*>();
86 composite_pointer_type_is_ord<const void *, volatile int *, const volatile void*>();
87
88 composite_pointer_type_is_ord<const A*, volatile B*, const volatile A*>();
89 composite_pointer_type_is_ord<const B*, volatile A*, const volatile A*>();
90
91 composite_pointer_type_is_unord<const int *A::*, volatile int *B::*, const volatile int *const B::*>();
92 composite_pointer_type_is_unord<const int *B::*, volatile int *A::*, const volatile int *const B::*>();
93 no_composite_pointer_type<int (A::*)(), int (C::*)()>();
94 no_composite_pointer_type<const int (A::*)(), volatile int (C::*)()>();
95 // since-cxx20-warning@-1 {{volatile-qualified return type 'volatile int' is deprecated}}
96
97 #if __cplusplus >= 201703L
98 composite_pointer_type_is_ord<int (*)() noexcept, int (*)(), int (*)()>(); // #cwg1512-noexcept-1st
99 composite_pointer_type_is_ord<int (*)(), int (*)() noexcept, int (*)()>(); // #cwg1512-noexcept-2nd
100 composite_pointer_type_is_unord<int (A::*)() noexcept, int (A::*)(), int (A::*)()>();
101 composite_pointer_type_is_unord<int (A::*)(), int (A::*)() noexcept, int (A::*)()>();
102 // FIXME: This looks like a standard defect; these should probably all have type 'int (B::*)()'.
103 composite_pointer_type_is_unord<int (B::*)(), int (A::*)() noexcept, int (B::*)()>();
104 composite_pointer_type_is_unord<int (A::*)() noexcept, int (B::*)(), int (B::*)()>();
105 composite_pointer_type_is_unord<int (B::*)() noexcept, int (A::*)(), int (B::*)()>();
106 composite_pointer_type_is_unord<int (A::*)(), int (B::*)() noexcept, int (B::*)()>();
107
108 // FIXME: It would be reasonable to permit these, with a common type of 'int (*const *)()'.
109 no_composite_pointer_type<int (**)() noexcept, int (**)()>();
110 no_composite_pointer_type<int (**)(), int (**)() noexcept>();
111
112 // FIXME: It would be reasonable to permit these, with a common type of 'int (A::*)()'.
113 no_composite_pointer_type<int (A::*)() const, int (A::*)()>();
114 no_composite_pointer_type<int (A::*)(), int (A::*)() const>();
115
116 // FIXME: It would be reasonable to permit these, with a common type of
117 // 'int (A::*)() &' and 'int (A::*)() &&', respectively.
118 no_composite_pointer_type<int (A::*)() &, int (A::*)()>();
119 no_composite_pointer_type<int (A::*)(), int (A::*)() &>();
120 no_composite_pointer_type<int (A::*)() &&, int (A::*)()>();
121 no_composite_pointer_type<int (A::*)(), int (A::*)() &&>();
122
123 no_composite_pointer_type<int (A::*)() &&, int (A::*)() &>();
124 no_composite_pointer_type<int (A::*)() &, int (A::*)() &&>();
125
126 no_composite_pointer_type<int (C::*)(), int (A::*)() noexcept>();
127 no_composite_pointer_type<int (A::*)() noexcept, int (C::*)()>();
128 #endif
129 }
130
131 #if __cplusplus >= 201103L
132 template<typename T> struct Wrap { operator T(); }; // #cwg1512-Wrap
133 void test_overload() {
134 using nullptr_t = decltype(nullptr);
135 void(Wrap<nullptr_t>() == Wrap<nullptr_t>());
136 void(Wrap<nullptr_t>() != Wrap<nullptr_t>());
137 void(Wrap<nullptr_t>() < Wrap<nullptr_t>());
138 // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}
139 void(Wrap<nullptr_t>() > Wrap<nullptr_t>());
140 // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}
141 void(Wrap<nullptr_t>() <= Wrap<nullptr_t>());
142 // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}
143 void(Wrap<nullptr_t>() >= Wrap<nullptr_t>());
144 // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>'))}}
145
146 // Under cwg1213, this is ill-formed: we select the builtin operator<(int*, int*)
147 // but then only convert as far as 'nullptr_t', which we then can't convert to 'int*'.
148 void(Wrap<nullptr_t>() == Wrap<int*>());
149 void(Wrap<nullptr_t>() != Wrap<int*>());
150 void(Wrap<nullptr_t>() < Wrap<int*>());
151 // since-cxx11-error@-1 {{invalid operands to binary expression ('Wrap<nullptr_t>' (aka 'Wrap<std::nullptr_t>') and 'Wrap<int *>')}}
152 // since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}
153 // since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}
154 void(Wrap<nullptr_t>() > Wrap<int*>());
155 // since-cxx11-error@-1 {{invalid operands}}
156 // since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}
157 // since-cxx11-note@#cwg1512-Wrap{{second operand was implicitly converted to type 'int *'}}
158 void(Wrap<nullptr_t>() <= Wrap<int*>());
159 // since-cxx11-error@-1 {{invalid operands}}
160 // since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}
161 // since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}
162 void(Wrap<nullptr_t>() >= Wrap<int*>());
163 // since-cxx11-error@-1 {{invalid operands}}
164 // since-cxx11-note@#cwg1512-Wrap {{first operand was implicitly converted to type 'std::nullptr_t'}}
165 // since-cxx11-note@#cwg1512-Wrap {{second operand was implicitly converted to type 'int *'}}
166 }
167 #endif
168 }
169
170 namespace cwg1514 { // cwg1514: 11
171 #if __cplusplus >= 201103L
172 struct S {
173 enum E : int {}; // #cwg1514-E
174 enum E : int {};
175 // since-cxx11-error@-1 {{redefinition of 'E'}}
176 // since-cxx11-note@#cwg1514-E {{previous definition is here}}
177 };
178 S::E se; // OK, complete type, not zero-width bitfield.
179
180 // The behavior in other contexts is superseded by CWG1966.
181 #endif
182 }
183
184 namespace cwg1518 { // cwg1518: 4
185 #if __cplusplus >= 201103L
186 struct Z0 { // #cwg1518-Z0
187 explicit Z0() = default; // #cwg1518-Z0-ctor
188 };
189 struct Z { // #cwg1518-Z
190 explicit Z(); // #cwg1518-Z-ctor
191 explicit Z(int); // #cwg1518-Z-int
192 explicit Z(int, int); // #cwg1518-Z-int-int
193 };
194 template <class T> int Eat(T); // #cwg1518-Eat
195 Z0 a;
196 Z0 b{};
197 Z0 c = {};
198 // since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}
199 // since-cxx11-note@#cwg1518-Z0-ctor {{explicit constructor declared here}}
200 int i = Eat<Z0>({});
201 // since-cxx11-error@-1 {{no matching function for call to 'Eat'}}
202 // since-cxx11-note@#cwg1518-Eat {{candidate function template not viable: cannot convert initializer list argument to 'Z0'}}
203
204 Z c2 = {};
205 // since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}
206 // since-cxx11-note@#cwg1518-Z-ctor {{explicit constructor declared here}}
207 int i2 = Eat<Z>({});
208 // since-cxx11-error@-1 {{no matching function for call to 'Eat'}}
209 // since-cxx11-note@#cwg1518-Eat {{candidate function template not viable: cannot convert initializer list argument to 'Z'}}
210 Z a1 = 1;
211 // since-cxx11-error@-1 {{no viable conversion from 'int' to 'Z'}}
212 // since-cxx11-note@#cwg1518-Z {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const Z &' for 1st argument}}
213 // since-cxx11-note@#cwg1518-Z {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'Z &&' for 1st argument}}
214 // since-cxx11-note@#cwg1518-Z-int {{explicit constructor is not a candidate}}
215 Z a3 = Z(1);
216 Z a2(1);
217 Z *p = new Z(1);
218 Z a4 = (Z)1;
219 Z a5 = static_cast<Z>(1);
220 Z a6 = {4, 3};
221 // since-cxx11-error@-1 {{chosen constructor is explicit in copy-initialization}}
222 // since-cxx11-note@#cwg1518-Z-int-int {{explicit constructor declared here}}
223
224 struct UserProvidedBaseCtor { // #cwg1518-U
225 UserProvidedBaseCtor() {}
226 };
227 struct DoesntInheritCtor : UserProvidedBaseCtor { // #cwg1518-D-U
228 int x;
229 };
230 DoesntInheritCtor I{{}, 42};
231 // cxx11-14-error@-1 {{no matching constructor for initialization of 'DoesntInheritCtor'}}
232 // cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}
233 // cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}
234 // cxx11-14-note@#cwg1518-D-U {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided}}
235
236 struct BaseCtor { BaseCtor() = default; }; // #cwg1518-BC
237 struct InheritsCtor : BaseCtor { // #cwg1518-I
238 using BaseCtor::BaseCtor; // #cwg1518-I-using
239 int x;
240 };
241 InheritsCtor II = {{}, 42};
242 // since-cxx11-error@-1 {{no matching constructor for initialization of 'InheritsCtor'}}
243 // since-cxx11-note@#cwg1518-BC {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}
244 // since-cxx11-note@#cwg1518-I-using {{constructor from base class 'BaseCtor' inherited here}}
245 // since-cxx11-note@#cwg1518-BC {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}
246 // since-cxx11-note@#cwg1518-I-using {{constructor from base class 'BaseCtor' inherited here}}
247 // since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}}
248 // since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}}
249 // since-cxx11-note@#cwg1518-I {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided}}
250
251 namespace std_example {
252 struct A {
253 explicit A() = default; // #cwg1518-A
254 };
255
256 struct B : A {
257 explicit B() = default; // #cwg1518-B
258 };
259
260 struct C {
261 explicit C(); // #cwg1518-C
262 };
263
264 struct D : A {
265 C c;
266 explicit D() = default; // #cwg1518-D
267 };
268
269 template <typename T> void f() {
270 T t; // ok
271 T u{}; // ok
272 T v = {}; // #cwg1518-v
273 // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}
274 // since-cxx11-note@#cwg1518-f-A {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::A>' requested here}}
275 // since-cxx11-note@#cwg1518-A {{explicit constructor declared here}}
276 // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}
277 // since-cxx11-note@#cwg1518-f-B {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::B>' requested here}}
278 // since-cxx11-note@#cwg1518-B {{explicit constructor declared here}}
279 // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}
280 // since-cxx11-note@#cwg1518-f-C {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::C>' requested here}}
281 // since-cxx11-note@#cwg1518-C {{explicit constructor declared here}}
282 // since-cxx11-error@#cwg1518-v {{chosen constructor is explicit in copy-initialization}}
283 // since-cxx11-note@#cwg1518-f-D {{in instantiation of function template specialization 'cwg1518::std_example::f<cwg1518::std_example::D>' requested here}}
284 // since-cxx11-note@#cwg1518-D {{explicit constructor declared here}}
285 }
286 template <typename T> void g() {
287 void x(T t); // #cwg1518-x
288 x({}); // #cwg1518-x-call
289 // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}
290 // since-cxx11-note@#cwg1518-g-A {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::A>' requested here}}
291 // since-cxx11-note@#cwg1518-A {{explicit constructor declared here}}
292 // since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}
293 // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}
294 // since-cxx11-note@#cwg1518-g-B {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::B>' requested here}}
295 // since-cxx11-note@#cwg1518-B {{explicit constructor declared here}}
296 // since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}
297 // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}
298 // since-cxx11-note@#cwg1518-g-C {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::C>' requested here}}
299 // since-cxx11-note@#cwg1518-C {{explicit constructor declared here}}
300 // since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}
301 // since-cxx11-error@#cwg1518-x-call {{chosen constructor is explicit in copy-initialization}}
302 // since-cxx11-note@#cwg1518-g-D {{in instantiation of function template specialization 'cwg1518::std_example::g<cwg1518::std_example::D>' requested here}}
303 // since-cxx11-note@#cwg1518-D {{explicit constructor declared here}}
304 // since-cxx11-note@#cwg1518-x {{passing argument to parameter 't' here}}
305 }
306
307 void test() {
308 f<A>(); // #cwg1518-f-A
309 f<B>(); // #cwg1518-f-B
310 f<C>(); // #cwg1518-f-C
311 f<D>(); // #cwg1518-f-D
312 g<A>(); // #cwg1518-g-A
313 g<B>(); // #cwg1518-g-B
314 g<C>(); // #cwg1518-g-C
315 g<D>(); // #cwg1518-g-D
316 }
317 }
318 #endif // __cplusplus >= 201103L
319 }
320
321 namespace cwg1550 { // cwg1550: 3.4
322 int f(bool b, int n) {
323 return (b ? (throw 0) : n) + (b ? n : (throw 0));
324 }
325 }
326
327 namespace cwg1558 { // cwg1558: 12
328 #if __cplusplus >= 201103L
329 template<class T, class...> using first_of = T;
330 template<class T> first_of<void, typename T::type> f(int); // #cwg1558-f
331 template<class T> void f(...) = delete; // #cwg1558-f-deleted
332
333 struct X { typedef void type; };
334 void test() {
335 f<X>(0);
336 f<int>(0);
337 // since-cxx11-error@-1 {{call to deleted function 'f'}}
338 // since-cxx11-note@#cwg1558-f-deleted {{candidate function [with T = int] has been explicitly deleted}}
339 // since-cxx11-note@#cwg1558-f {{candidate template ignored: substitution failure [with T = int]: type 'int' cannot be used prior to '::' because it has no members}}
340 }
341 #endif
342 }
343
344 namespace cwg1560 { // cwg1560: 3.5
345 void f(bool b, int n) {
346 (b ? throw 0 : n) = (b ? n : throw 0) = 0;
347 }
348 class X { X(const X&); };
349 const X &get();
350 const X &x = true ? get() : throw 0;
351 }
352
353 namespace cwg1563 { // cwg1563: yes
354 #if __cplusplus >= 201103L
355 double bar(double) { return 0.0; }
356 float bar(float) { return 0.0f; }
357
358 using fun = double(double);
359 fun &foo{bar}; // ok
360 #endif
361 }
362
363 namespace cwg1567 { // cwg1567: 3.3
364 #if __cplusplus >= 201103L
365 struct B;
366 struct A {
367 A(const A&);
368 A(const B&) = delete;
369 A(A&&);
370 A(B&&) = delete;
371 A(int); // #cwg1567-A-int
372 };
373
374 struct B: A { // #cwg1567-B
375 using A::A; // #cwg1567-using-A
376 B(double); // #cwg1567-B-double
377 };
378
379 A a{0};
380 B b{1.0};
381 // Good, deleted converting ctors are not inherited as copy/move ctors
382 B b2{b};
383 B b3{B{1.0}};
384 // Good, copy/move ctors are not inherited
385 B b4{a};
386 // since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}
387 // since-cxx11-note@#cwg1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}
388 // since-cxx11-note@#cwg1567-using-A {{constructor from base class 'A' inherited here}}
389 // since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}
390 // since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}
391 // since-cxx11-note@#cwg1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}
392 B b5{A{0}};
393 // since-cxx11-error@-1 {{no matching constructor for initialization of 'B'}}
394 // since-cxx11-note@#cwg1567-A-int {{candidate inherited constructor not viable: no known conversion from 'A' to 'int' for 1st argument}}
395 // since-cxx11-note@#cwg1567-using-A {{constructor from base class 'A' inherited here}}
396 // since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'A' to 'const B' for 1st argument}}
397 // since-cxx11-note@#cwg1567-B {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'A' to 'B' for 1st argument}}
398 // since-cxx11-note@#cwg1567-B-double {{candidate constructor not viable: no known conversion from 'A' to 'double' for 1st argument}}
399 #endif
400 }
401
402 namespace cwg1573 { // cwg1573: 3.9
403 #if __cplusplus >= 201103L
404 // ellipsis is inherited (p0136r1 supersedes this part).
405 struct A { A(); A(int, char, ...); };
406 struct B : A { using A::A; };
407 B b(1, 'x', 4.0, "hello"); // ok
408
409 // inherited constructor is effectively constexpr if the user-written constructor would be
410 struct C { C(); constexpr C(int) {} }; // #cwg1573-C
411 struct D : C { using C::C; };
412 constexpr D d = D(0); // ok
413 struct E : C { using C::C; A a; }; // #cwg1573-E
414 constexpr E e = E(0);
415 // since-cxx11-error@-1 {{constexpr variable cannot have non-literal type 'const E'}}
416 // since-cxx11-note@#cwg1573-E {{'E' is not literal because it has data member 'a' of non-literal type 'A'}}
417
418 // FIXME: This diagnostic is pretty bad; we should explain that the problem
419 // is that F::c would be initialized by a non-constexpr constructor.
420 struct F : C { using C::C; C c; }; // #cwg1573-F
421 constexpr F f = F(0);
422 // since-cxx11-error@-1 {{constexpr variable 'f' must be initialized by a constant expression}}
423 // cxx11-20-note@-2 {{constructor inherited from base class 'C' cannot be used in a constant expression; derived class cannot be implicitly initialized}}
424 // since-cxx23-note@-3 {{in implicit initialization for inherited constructor of 'F'}}
425 // since-cxx23-note@#cwg1573-F {{non-constexpr constructor 'C' cannot be used in a constant expression}}
426 // cxx11-20-note@#cwg1573-F {{declared here}}
427 // since-cxx23-note@#cwg1573-C {{declared here}}
428
429 // inherited constructor is effectively deleted if the user-written constructor would be
430 struct G { G(int); };
431 struct H : G { using G::G; G g; }; // #cwg1573-H
432 H h(0);
433 // since-cxx11-error@-1 {{constructor inherited by 'H' from base class 'G' is implicitly deleted}}
434 // since-cxx11-note@#cwg1573-H {{constructor inherited by 'H' is implicitly deleted because field 'g' has no default constructor}}
435
436 // deleted definition of constructor is inherited
437 struct I { I(int) = delete; }; // #cwg1573-I
438 struct J : I { using I::I; };
439 J j(0);
440 // since-cxx11-error@-1 {{call to deleted constructor of 'J'}}
441 // since-cxx11-note@#cwg1573-I {{'I' has been explicitly marked deleted here}}
442 #endif
443 }
444
445 #if __cplusplus >= 201103L
446 namespace std {
447 typedef decltype(sizeof(int)) size_t;
448
449 // libc++'s implementation
450 template <class _E>
451 class initializer_list
452 {
453 const _E* __begin_;
454 size_t __size_;
455
456 initializer_list(const _E* __b, size_t __s)
457 : __begin_(__b), __size_(__s) {}
458
459 public:
460 typedef _E value_type;
461 typedef const _E& reference;
462 typedef const _E& const_reference;
463 typedef size_t size_type;
464
465 typedef const _E* iterator;
466 typedef const _E* const_iterator;
467
468 initializer_list() : __begin_(nullptr), __size_(0) {}
469
470 size_t size() const {return __size_;}
471 const _E* begin() const {return __begin_;}
472 const _E* end() const {return __begin_ + __size_;}
473 };
474
475 template < class _T1, class _T2 > struct pair { _T2 second; };
476
477 template<typename T> struct basic_string {
478 basic_string(const T* x) {}
479 ~basic_string() {};
480 };
481 typedef basic_string<char> string;
482
483 } // std
484 #endif
485
486 namespace cwg1579 { // cwg1579: 3.9
487 #if __cplusplus >= 201103L
488 template<class T>
489 struct GenericMoveOnly {
490 GenericMoveOnly();
491 template<class U> GenericMoveOnly(const GenericMoveOnly<U> &) = delete; // #cwg1579-deleted-U
492 GenericMoveOnly(const int &) = delete; // #cwg1579-deleted-int
493 template<class U> GenericMoveOnly(GenericMoveOnly<U> &&);
494 GenericMoveOnly(int &&);
495 };
496
497 GenericMoveOnly<float> CWG1579_Eligible(GenericMoveOnly<char> CharMO) {
498 int i;
499 GenericMoveOnly<char> GMO;
500
501 if (0)
502 return i;
503 else if (0)
504 return GMO;
505 else if (0)
506 return ((GMO));
507 else
508 return CharMO;
509 }
510
511 GenericMoveOnly<char> GlobalMO;
512
513 GenericMoveOnly<float> CWG1579_Ineligible(int &AnInt,
514 GenericMoveOnly<char> &CharMO) {
515 static GenericMoveOnly<char> StaticMove;
516 extern GenericMoveOnly<char> ExternMove;
517
518 if (0)
519 return AnInt;
520 // since-cxx11-error@-1 {{conversion function from 'int' to 'GenericMoveOnly<float>' invokes a deleted function}}
521 // since-cxx11-note@#cwg1579-deleted-int {{'GenericMoveOnly' has been explicitly marked deleted here}}
522 else if (0)
523 return GlobalMO;
524 // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}
525 // since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}
526 else if (0)
527 return StaticMove;
528 // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}
529 // since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}
530 else if (0)
531 return ExternMove;
532 // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}
533 // since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}
534 else if (0)
535 return AnInt;
536 // since-cxx11-error@-1 {{conversion function from 'int' to 'GenericMoveOnly<float>' invokes a deleted function}}
537 // since-cxx11-note@#cwg1579-deleted-int {{'GenericMoveOnly' has been explicitly marked deleted here}}
538 else
539 return CharMO;
540 // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<char>' to 'GenericMoveOnly<float>' invokes a deleted function}}
541 // since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<char>' has been explicitly marked deleted here}}
542 }
543
544 auto CWG1579_lambda_valid = [](GenericMoveOnly<float> mo) ->
545 GenericMoveOnly<char> {
546 return mo;
547 };
548
549 auto CWG1579_lambda_invalid = []() -> GenericMoveOnly<char> {
550 static GenericMoveOnly<float> mo;
551 return mo;
552 // since-cxx11-error@-1 {{conversion function from 'GenericMoveOnly<float>' to 'GenericMoveOnly<char>' invokes a deleted function}}
553 // since-cxx11-note@#cwg1579-deleted-U {{'GenericMoveOnly<float>' has been explicitly marked deleted here}}
554 };
555 #endif
556 } // end namespace cwg1579
557
558 namespace cwg1584 { // cwg1584: 7 drafting 2015-05
559 #if __cplusplus >= 201103L
560 // Deducing function types from cv-qualified types
561 template<typename T> void f(const T *); // #cwg1584-f
562 template<typename T> void g(T *, const T * = 0);
563 template<typename T> void h(T *) { T::error; }
564 // since-cxx11-error@-1 {{type 'void ()' cannot be used prior to '::' because it has no members}}
565 // since-cxx11-note@#cwg1584-h {{in instantiation of function template specialization 'cwg1584::h<void ()>' requested here}}
566 template<typename T> void h(const T *);
567 void i() {
568 f(&i);
569 // since-cxx11-error@-1 {{no matching function for call to 'f'}}
570 // since-cxx11-note@#cwg1584-f {{candidate template ignored: could not match 'const T *' against 'void (*)()'}}
571 g(&i);
572 h(&i); // #cwg1584-h
573 }
574 #endif
575 }
576
577 namespace cwg1589 { // cwg1589: 3.7 c++11
578 #if __cplusplus >= 201103L
579 // Ambiguous ranking of list-initialization sequences
580
581 void f0(long, int=0); // Would makes selection of #0 ambiguous
582 void f0(long); // #0
583 void f0(std::initializer_list<int>); // #00
584 void g0() { f0({1L}); } // chooses #00
585
586 void f1(int, int=0); // Would make selection of #1 ambiguous
587 void f1(int); // #1
588 void f1(std::initializer_list<long>); // #2
589 void g1() { f1({42}); } // chooses #2
590
591 void f2(std::pair<const char*, const char*>, int = 0); // Would makes selection of #3 ambiguous
592 void f2(std::pair<const char*, const char*>); // #3
593 void f2(std::initializer_list<std::string>); // #4
594 void g2() { f2({"foo","bar"}); } // chooses #4
595
596 namespace with_error {
597 void f0(long);
598 void f0(std::initializer_list<int>); // #cwg1589-f0-ilist
599 void f0(std::initializer_list<int>, int = 0); // #cwg1589-f0-ilist-int
600 void g0() { f0({1L}); }
601 // since-cxx11-error@-1 {{call to 'f0' is ambiguous}}
602 // since-cxx11-note@#cwg1589-f0-ilist {{candidate function}}
603 // since-cxx11-note@#cwg1589-f0-ilist-int {{candidate function}}
604
605 void f1(int);
606 void f1(std::initializer_list<long>); // #cwg1589-f1-ilist
607 void f1(std::initializer_list<long>, int = 0); // #cwg1589-f1-ilist-long
608 void g1() { f1({42}); }
609 // since-cxx11-error@-1 {{call to 'f1' is ambiguous}}
610 // since-cxx11-note@#cwg1589-f1-ilist {{candidate function}}
611 // since-cxx11-note@#cwg1589-f1-ilist-long {{candidate function}}
612
613 void f2(std::pair<const char*, const char*>);
614 void f2(std::initializer_list<std::string>); // #cwg1589-f2-ilist
615 void f2(std::initializer_list<std::string>, int = 0); // #cwg1589-f2-ilist-int
616 void g2() { f2({"foo","bar"}); }
617 // since-cxx11-error@-1 {{call to 'f2' is ambiguous}}
618 // since-cxx11-note@#cwg1589-f2-ilist {{candidate function}}
619 // since-cxx11-note@#cwg1589-f2-ilist-int {{candidate function}}
620 }
621 #endif
622 } // cwg1589
623
624 namespace cwg1591 { //cwg1591. Deducing array bound and element type from initializer list
625 #if __cplusplus >= 201103L
626 template<class T, int N> int h(T const(&)[N]);
627 int X = h({1,2,3}); // T deduced to int, N deduced to 3
628
629 template<class T> int j(T const(&)[3]);
630 int Y = j({42}); // T deduced to int, array bound not considered
631
632 struct Aggr { int i; int j; };
633 template<int N> int k(Aggr const(&)[N]); // #cwg1591-k
634 int Y0 = k({1,2,3});
635 // since-cxx11-error@-1 {{no matching function for call to 'k'}}
636 // since-cxx11-note@#cwg1591-k {{candidate function [with N = 3] not viable: no known conversion from 'int' to 'const Aggr' for 1st argument}}
637 int Z = k({{1},{2},{3}}); // OK, N deduced to 3
638
639 template<int M, int N> int m(int const(&)[M][N]);
640 int X0 = m({{1,2},{3,4}}); // M and N both deduced to 2
641
642 template<class T, int N> int n(T const(&)[N], T);
643 int X1 = n({{1},{2},{3}},Aggr()); // OK, T is Aggr, N is 3
644
645
646 namespace check_multi_dim_arrays {
647 template<class T, int N, int M, int O> int ***f(const T (&a)[N][M][O]); // #cwg1591-f-3
648 template<class T, int N, int M> int **f(const T (&a)[N][M]); // #cwg1591-f-2
649
650 template<class T, int N> int *f(const T (&a)[N]); // #cwg1591-f-1
651 int ***p3 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12} } });
652 int ***p33 = f({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12, 13} } });
653 // since-cxx11-error@-1 {{no matching function for call to 'f'}}
654 // since-cxx11-note@#cwg1591-f-2 {{candidate template ignored: couldn't infer template argument 'T'}}
655 // since-cxx11-note@#cwg1591-f-1 {{candidate template ignored: couldn't infer template argument 'T'}}
656 // since-cxx11-note@#cwg1591-f-3 {{candidate template ignored: deduced conflicting values for parameter 'O' (2 vs. 3)}}
657 int **p2 = f({ {1,2,3}, {3, 4, 5} });
658 int **p22 = f({ {1,2}, {3, 4} });
659 int *p1 = f({1, 2, 3});
660 }
661 namespace check_multi_dim_arrays_rref {
662 template<class T, int N, int M, int O> int ***g(T (&&a)[N][M][O]); // #cwg1591-g-3
663 template<class T, int N, int M> int **g(T (&&a)[N][M]); // #cwg1591-g-2
664
665 template<class T, int N> int *g(T (&&a)[N]); // #cwg1591-g-1
666 int ***p3 = g({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12} } });
667 int ***p33 = g({ { {1,2}, {3, 4} }, { {5,6}, {7, 8} }, { {9,10}, {11, 12, 13} } });
668 // since-cxx11-error@-1 {{no matching function for call to 'g'}}
669 // since-cxx11-note@#cwg1591-g-2 {{candidate template ignored: couldn't infer template argument 'T'}}
670 // since-cxx11-note@#cwg1591-g-1 {{candidate template ignored: couldn't infer template argument 'T'}}
671 // since-cxx11-note@#cwg1591-g-3 {{candidate template ignored: deduced conflicting values for parameter 'O' (2 vs. 3)}}
672 int **p2 = g({ {1,2,3}, {3, 4, 5} });
673 int **p22 = g({ {1,2}, {3, 4} });
674 int *p1 = g({1, 2, 3});
675 }
676
677 namespace check_arrays_of_init_list {
678 template<class T, int N> float *h(const std::initializer_list<T> (&)[N]);
679 template<class T, int N> double *h(const T(&)[N]);
680 double *p = h({1, 2, 3});
681 float *fp = h({{1}, {1, 2}, {1, 2, 3}});
682 }
683 namespace core_reflector_28543 {
684
685 template<class T, int N> int *i(T (&&)[N]); // #1
686 template<class T> char *i(std::initializer_list<T> &&); // #2
687 template<class T, int N, int M> int **i(T (&&)[N][M]); // #3 #cwg1591-i-2
688 template<class T, int N> char **i(std::initializer_list<T> (&&)[N]); // #4 #cwg1591-i-1
689
690 template<class T> short *i(T (&&)[2]); // #5
691
692 template<class T> using Arr = T[];
693
694 char *pc = i({1, 2, 3}); // OK prefer #2 via 13.3.3.2 [over.ics.rank]
695 char *pc2 = i({1, 2}); // #2 also
696 int *pi = i(Arr<int>{1, 2, 3}); // OK prefer #1
697
698 void *pv1 = i({ {1, 2, 3}, {4, 5, 6} }); // ambiguous btw 3 & 4
699 // since-cxx11-error@-1 {{call to 'i' is ambiguous}}
700 // since-cxx11-note@#cwg1591-i-2 {{candidate function [with T = int, N = 2, M = 3]}}
701 // since-cxx11-note@#cwg1591-i-1 {{candidate function [with T = int, N = 2]}}
702 char **pcc = i({ {1}, {2, 3} }); // OK #4
703
704 short *ps = i(Arr<int>{1, 2}); // OK #5
705 }
706 #endif
707 } // cwg1591