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