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