| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s %std_cxx11- |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify %s %std_cxx11- -fexperimental-new-constant-interpreter |
| 3 |
|
| 4 |
// Template argument deduction with template template parameters. |
| 5 |
template<typename T, template<T> class A> |
| 6 |
struct X0 { |
| 7 |
static const unsigned value = 0; |
| 8 |
}; |
| 9 |
|
| 10 |
template<template<int> class A> |
| 11 |
struct X0<int, A> { |
| 12 |
static const unsigned value = 1; |
| 13 |
}; |
| 14 |
|
| 15 |
template<class T> |
| 16 |
struct type_identity { |
| 17 |
using type = T; |
| 18 |
}; |
| 19 |
|
| 20 |
template<class T> |
| 21 |
using type_identity_t = typename type_identity<T>::type; |
| 22 |
|
| 23 |
template <typename... T> |
| 24 |
struct args_tag {}; |
| 25 |
|
| 26 |
template<int> struct X0i; |
| 27 |
template<long> struct X0l; |
| 28 |
int array_x0a[X0<long, X0l>::value == 0? 1 : -1]; |
| 29 |
int array_x0b[X0<int, X0i>::value == 1? 1 : -1]; |
| 30 |
|
| 31 |
template<typename T, typename U> |
| 32 |
struct is_same { |
| 33 |
static const bool value = false; |
| 34 |
}; |
| 35 |
|
| 36 |
template<typename T> |
| 37 |
struct is_same<T, T> { |
| 38 |
static const bool value = true; |
| 39 |
}; |
| 40 |
|
| 41 |
template<typename T> struct allocator { }; |
| 42 |
template<typename T, typename Alloc = allocator<T> > struct vector {}; |
| 43 |
|
| 44 |
// Fun with meta-lambdas! |
| 45 |
struct _1 {}; |
| 46 |
struct _2 {}; |
| 47 |
|
| 48 |
// Replaces all occurrences of _1 with Arg1 and _2 with Arg2 in T. |
| 49 |
template<typename T, typename Arg1, typename Arg2> |
| 50 |
struct Replace { |
| 51 |
typedef T type; |
| 52 |
}; |
| 53 |
|
| 54 |
// Replacement of the whole type. |
| 55 |
template<typename Arg1, typename Arg2> |
| 56 |
struct Replace<_1, Arg1, Arg2> { |
| 57 |
typedef Arg1 type; |
| 58 |
}; |
| 59 |
|
| 60 |
template<typename Arg1, typename Arg2> |
| 61 |
struct Replace<_2, Arg1, Arg2> { |
| 62 |
typedef Arg2 type; |
| 63 |
}; |
| 64 |
|
| 65 |
// Replacement through cv-qualifiers |
| 66 |
template<typename T, typename Arg1, typename Arg2> |
| 67 |
struct Replace<const T, Arg1, Arg2> { |
| 68 |
typedef typename Replace<T, Arg1, Arg2>::type const type; |
| 69 |
}; |
| 70 |
|
| 71 |
// Replacement of templates |
| 72 |
template<template<typename> class TT, typename T1, typename Arg1, typename Arg2> |
| 73 |
struct Replace<TT<T1>, Arg1, Arg2> { |
| 74 |
typedef TT<typename Replace<T1, Arg1, Arg2>::type> type; |
| 75 |
}; |
| 76 |
|
| 77 |
template<template<typename, typename> class TT, typename T1, typename T2, |
| 78 |
typename Arg1, typename Arg2> |
| 79 |
struct Replace<TT<T1, T2>, Arg1, Arg2> { |
| 80 |
typedef TT<typename Replace<T1, Arg1, Arg2>::type, |
| 81 |
typename Replace<T2, Arg1, Arg2>::type> type; |
| 82 |
}; |
| 83 |
|
| 84 |
// Just for kicks... |
| 85 |
template<template<typename, typename> class TT, typename T1, |
| 86 |
typename Arg1, typename Arg2> |
| 87 |
struct Replace<TT<T1, _2>, Arg1, Arg2> { |
| 88 |
typedef TT<typename Replace<T1, Arg1, Arg2>::type, Arg2> type; |
| 89 |
}; |
| 90 |
|
| 91 |
int array0[is_same<Replace<_1, int, float>::type, int>::value? 1 : -1]; |
| 92 |
int array1[is_same<Replace<const _1, int, float>::type, const int>::value? 1 : -1]; |
| 93 |
int array2[is_same<Replace<vector<_1>, int, float>::type, vector<int> >::value? 1 : -1]; |
| 94 |
int array3[is_same<Replace<vector<const _1>, int, float>::type, vector<const int> >::value? 1 : -1]; |
| 95 |
int array4[is_same<Replace<vector<int, _2>, double, float>::type, vector<int, float> >::value? 1 : -1]; |
| 96 |
|
| 97 |
// PR5911 |
| 98 |
template <typename T, int N> void f(const T (&a)[N]); |
| 99 |
int iarr[] = { 1 }; |
| 100 |
void test_PR5911() { f(iarr); } |
| 101 |
|
| 102 |
// Must not examine base classes of incomplete type during template argument |
| 103 |
// deduction. |
| 104 |
namespace PR6257 { |
| 105 |
template <typename T> struct X { |
| 106 |
template <typename U> X(const X<U>& u); |
| 107 |
}; |
| 108 |
struct A; |
| 109 |
void f(A& a); |
| 110 |
void f(const X<A>& a); |
| 111 |
void test(A& a) { (void)f(a); } |
| 112 |
} |
| 113 |
|
| 114 |
// PR7463 |
| 115 |
namespace PR7463 { |
| 116 |
const int f (); |
| 117 |
template <typename T_> void g (T_&); // expected-note{{T_ = int}} |
| 118 |
void h (void) { g(f()); } // expected-error{{no matching function for call}} |
| 119 |
} |
| 120 |
|
| 121 |
namespace test0 { |
| 122 |
template <class T> void make(const T *(*fn)()); // expected-note {{candidate template ignored: cannot deduce a type for 'T' that would make 'const T' equal 'char'}} |
| 123 |
char *char_maker(); |
| 124 |
void test() { |
| 125 |
make(char_maker); // expected-error {{no matching function for call to 'make'}} |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
namespace test1 { |
| 130 |
template<typename T> void foo(const T a[3][3]); |
| 131 |
void test() { |
| 132 |
int a[3][3]; |
| 133 |
foo(a); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
// PR7708 |
| 138 |
namespace test2 { |
| 139 |
template<typename T> struct Const { typedef void const type; }; |
| 140 |
|
| 141 |
template<typename T> void f(T, typename Const<T>::type*); |
| 142 |
template<typename T> void f(T, void const *); |
| 143 |
|
| 144 |
void test() { |
| 145 |
void *p = 0; |
| 146 |
f(0, p); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
namespace test3 { |
| 151 |
struct Foo { |
| 152 |
template <void F(char)> static inline void foo(); |
| 153 |
}; |
| 154 |
|
| 155 |
class Bar { |
| 156 |
template<typename T> static inline void wobble(T ch); |
| 157 |
|
| 158 |
public: |
| 159 |
static void madness() { |
| 160 |
Foo::foo<wobble<char> >(); |
| 161 |
} |
| 162 |
}; |
| 163 |
} |
| 164 |
|
| 165 |
namespace test4 { |
| 166 |
|
| 167 |
template <class> struct a { using b = const float; }; |
| 168 |
template <class c> using d = typename a<c>::b; |
| 169 |
|
| 170 |
template <class c> void e(d<c> *, c) {} |
| 171 |
template void e(const float *, int); |
| 172 |
|
| 173 |
} // namespace test4 |
| 174 |
|
| 175 |
namespace test5 { |
| 176 |
|
| 177 |
template <bool, int = 0> class a {}; |
| 178 |
template <class b> void c(b, b); |
| 179 |
template <bool b> void c(a<b>, a<b>); |
| 180 |
void d() { c(a<true>(), a<true>()); } |
| 181 |
|
| 182 |
} // namespace test5 |
| 183 |
|
| 184 |
namespace test6 { |
| 185 |
template <class A1> using A = A1; |
| 186 |
|
| 187 |
template <class F1, class... F2> void f(A<F1>, F1, F2...); |
| 188 |
template <class F3> void f(A<F3>, F3); |
| 189 |
|
| 190 |
void g() { f(A<int>{}, int{}); } |
| 191 |
} // namespace test6 |
| 192 |
|
| 193 |
namespace test7 { |
| 194 |
template <class T> void f(T&, T&); |
| 195 |
template <class T, unsigned long S> void f(T (&)[S], T (&)[S]); |
| 196 |
|
| 197 |
void g() { |
| 198 |
int i[3], j[3]; |
| 199 |
f(i, j); |
| 200 |
} |
| 201 |
} // namespace test7 |
| 202 |
|
| 203 |
namespace test8 { |
| 204 |
template <class T> void foo(T); |
| 205 |
void test(int a) { // expected-note {{declared here}} |
| 206 |
char n[a]; // expected-warning {{variable length arrays in C++ are a Clang extension}} \ |
| 207 |
expected-note {{function parameter 'a' with unknown value cannot be used in a constant expression}} |
| 208 |
foo(n); |
| 209 |
} |
| 210 |
} // namespace test8 |
| 211 |
|
| 212 |
// Verify that we can deduce enum-typed arguments correctly. |
| 213 |
namespace test14 { |
| 214 |
enum E { E0, E1 }; |
| 215 |
template <E> struct A {}; |
| 216 |
template <E e> void foo(const A<e> &a) {} |
| 217 |
|
| 218 |
void test() { |
| 219 |
A<E0> a; |
| 220 |
foo(a); |
| 221 |
} |
| 222 |
} |
| 223 |
|
| 224 |
namespace PR21536 { |
| 225 |
template<typename ...T> struct X; |
| 226 |
template<typename A, typename ...B> struct S { |
| 227 |
static_assert(sizeof...(B) == 1, ""); |
| 228 |
void f() { |
| 229 |
using T = A; |
| 230 |
using T = int; |
| 231 |
|
| 232 |
using U = X<B...>; |
| 233 |
using U = X<int>; |
| 234 |
} |
| 235 |
}; |
| 236 |
template<typename ...T> void f(S<T...>); |
| 237 |
void g() { f(S<int, int>()); } |
| 238 |
} |
| 239 |
|
| 240 |
namespace PR19372 { |
| 241 |
template <template<typename...> class C, typename ...Us> struct BindBack { |
| 242 |
template <typename ...Ts> using apply = C<Ts..., Us...>; |
| 243 |
}; |
| 244 |
template <typename, typename...> struct Y; |
| 245 |
template <typename ...Ts> using Z = Y<Ts...>; |
| 246 |
|
| 247 |
using T = BindBack<Z, int>::apply<>; |
| 248 |
using T = Z<int>; |
| 249 |
|
| 250 |
using U = BindBack<Z, int, int>::apply<char>; |
| 251 |
using U = Z<char, int, int>; |
| 252 |
|
| 253 |
namespace BetterReduction { |
| 254 |
template<typename ...> struct S; |
| 255 |
template<typename ...A> using X = S<A...>; // expected-note {{parameter}} |
| 256 |
template<typename ...A> using Y = X<A..., A...>; |
| 257 |
template<typename ...A> using Z = X<A..., 1, 2, 3>; // expected-error {{must be a type}} |
| 258 |
|
| 259 |
using T = Y<int>; |
| 260 |
using T = S<int, int>; |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
namespace PR18645 { |
| 265 |
template<typename F> F Quux(F &&f); |
| 266 |
auto Baz = Quux(Quux<float>); |
| 267 |
} |
| 268 |
|
| 269 |
namespace NonDeducedNestedNameSpecifier { |
| 270 |
template<typename T> struct A { |
| 271 |
template<typename U> struct B { |
| 272 |
B(int) {} |
| 273 |
}; |
| 274 |
}; |
| 275 |
|
| 276 |
template<typename T> int f(A<T>, typename A<T>::template B<T>); |
| 277 |
int k = f(A<int>(), 0); |
| 278 |
} |
| 279 |
|
| 280 |
namespace PR27601_RecursivelyInheritedBaseSpecializationsDeductionAmbiguity { |
| 281 |
namespace ns1 { |
| 282 |
|
| 283 |
template<class...> struct B { }; |
| 284 |
template<class H, class ... Ts> struct B<H, Ts...> : B<> { }; |
| 285 |
template<class ... Ts> struct D : B<Ts...> { }; |
| 286 |
|
| 287 |
template<class T, class ... Ts> void f(B<T, Ts...> &) { } |
| 288 |
|
| 289 |
int main() { |
| 290 |
D<int, char> d; |
| 291 |
f<int>(d); |
| 292 |
} |
| 293 |
} //end ns1 |
| 294 |
|
| 295 |
namespace ns2 { |
| 296 |
|
| 297 |
template <int i, typename... Es> struct tup_impl; |
| 298 |
|
| 299 |
template <int i> struct tup_impl<i> {}; // empty tail |
| 300 |
|
| 301 |
template <int i, typename Head, typename... Tail> |
| 302 |
struct tup_impl<i, Head, Tail...> : tup_impl<i + 1, Tail...> { |
| 303 |
using value_type = Head; |
| 304 |
Head head; |
| 305 |
}; |
| 306 |
|
| 307 |
template <typename... Es> struct tup : tup_impl<0, Es...> {}; |
| 308 |
|
| 309 |
template <typename Head, int i, typename... Tail> |
| 310 |
Head &get_helper(tup_impl<i, Head, Tail...> &t) { |
| 311 |
return t.head; |
| 312 |
} |
| 313 |
|
| 314 |
template <typename Head, int i, typename... Tail> |
| 315 |
Head const &get_helper(tup_impl<i, Head, Tail...> const &t) { |
| 316 |
return t.head; |
| 317 |
} |
| 318 |
|
| 319 |
int main() { |
| 320 |
tup<int, double, char> t; |
| 321 |
get_helper<double>(t); |
| 322 |
return 0; |
| 323 |
} |
| 324 |
} // end ns2 |
| 325 |
} |
| 326 |
|
| 327 |
namespace multiple_deduction_different_type { |
| 328 |
template<typename T, T v> struct X {}; |
| 329 |
template<template<typename T, T> class X, typename T, typename U, int N> |
| 330 |
void f(X<T, N>, X<U, N>) {} // expected-note 2{{values of conflicting types}} |
| 331 |
template<template<typename T, T> class X, typename T, typename U, const int *N> |
| 332 |
void g(X<T, N>, X<U, N>) {} // expected-note 0-2{{values of conflicting types}} |
| 333 |
int n; |
| 334 |
void h() { |
| 335 |
f(X<int, 1+1>(), X<unsigned int, 3-1>()); // expected-error {{no matching function}} |
| 336 |
f(X<unsigned int, 1+1>(), X<int, 3-1>()); // expected-error {{no matching function}} |
| 337 |
#if __cplusplus > 201402L |
| 338 |
g(X<const int*, &n>(), X<int*, &n + 1 - 1>()); // expected-error {{no matching function}} |
| 339 |
g(X<int*, &n>(), X<const int*, &n + 1 - 1>()); // expected-error {{no matching function}} |
| 340 |
#endif |
| 341 |
} |
| 342 |
|
| 343 |
template<template<typename T, T> class X, typename T, typename U, T N> |
| 344 |
void x(X<T, N>, int(*)[N], X<U, N>) {} // expected-note 1+{{candidate}} |
| 345 |
template<template<typename T, T> class X, typename T, typename U, T N> |
| 346 |
void x(int(*)[N], X<T, N>, X<U, N>) {} // expected-note 1+{{candidate}} |
| 347 |
int arr[3]; |
| 348 |
void y() { |
| 349 |
x(X<int, 3>(), &arr, X<int, 3>()); |
| 350 |
x(&arr, X<int, 3>(), X<int, 3>()); |
| 351 |
|
| 352 |
x(X<int, 3>(), &arr, X<char, 3>()); // expected-error {{no matching function}} |
| 353 |
x(&arr, X<int, 3>(), X<char, 3>()); // expected-error {{no matching function}} |
| 354 |
|
| 355 |
x(X<char, 3>(), &arr, X<char, 3>()); |
| 356 |
x(&arr, X<char, 3>(), X<char, 3>()); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
namespace nullptr_deduction { |
| 361 |
using nullptr_t = decltype(nullptr); |
| 362 |
|
| 363 |
template<typename T, T v> struct X {}; |
| 364 |
template<typename T, T v> void f(X<T, v>) { |
| 365 |
static_assert(!v, ""); // expected-warning 2{{implicit conversion of nullptr constant to 'bool'}} |
| 366 |
} |
| 367 |
void g() { |
| 368 |
f(X<int*, nullptr>()); // expected-note {{instantiation of}} |
| 369 |
f(X<nullptr_t, nullptr>()); // expected-note {{instantiation of}} |
| 370 |
} |
| 371 |
|
| 372 |
template<template<typename T, T> class X, typename T, int *P> |
| 373 |
void f0(X<T, P>) {} // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('std::nullptr_t' vs 'int *')}} |
| 374 |
void h0() { |
| 375 |
f0(X<int*, nullptr>()); |
| 376 |
f0(X<nullptr_t, nullptr>()); // expected-error {{no matching function}} |
| 377 |
} |
| 378 |
|
| 379 |
template<template<typename T, T> class X, typename T, typename U, int *P> |
| 380 |
void f1(X<T, P>, X<U, P>) {} // expected-note 2{{values of conflicting types}} |
| 381 |
void h() { |
| 382 |
f1(X<int*, nullptr>(), X<nullptr_t, nullptr>()); // expected-error {{no matching function}} |
| 383 |
f1(X<nullptr_t, nullptr>(), X<int*, nullptr>()); // expected-error {{no matching function}} |
| 384 |
} |
| 385 |
|
| 386 |
template<template<typename T, T> class X, typename T, typename U, nullptr_t P> |
| 387 |
void f2(X<T, P>, X<U, P>) {} // expected-note 2{{values of conflicting types}} |
| 388 |
void i() { |
| 389 |
f2(X<int*, nullptr>(), X<nullptr_t, nullptr>()); // expected-error {{no matching function}} |
| 390 |
f2(X<nullptr_t, nullptr>(), X<int*, nullptr>()); // expected-error {{no matching function}} |
| 391 |
} |
| 392 |
} |
| 393 |
|
| 394 |
namespace member_pointer { |
| 395 |
struct A { void f(int); }; |
| 396 |
template<typename T, void (A::*F)(T)> struct B; |
| 397 |
template<typename T> struct C; |
| 398 |
template<typename T, void (A::*F)(T)> struct C<B<T, F>> { |
| 399 |
C() { A a; T t; (a.*F)(t); } |
| 400 |
}; |
| 401 |
C<B<int, &A::f>> c; |
| 402 |
} |
| 403 |
|
| 404 |
namespace deduction_substitution_failure { |
| 405 |
template<typename T> struct Fail { typedef typename T::error error; }; // expected-error 2{{prior to '::'}} |
| 406 |
|
| 407 |
template<typename T, typename U> struct A {}; |
| 408 |
template<typename T> struct A<T, typename Fail<T>::error> {}; // expected-note {{instantiation of}} |
| 409 |
A<int, int> ai; // expected-note {{during template argument deduction for class template partial specialization 'A<T, typename Fail<T>::error>' [with T = int]}} expected-note {{in instantiation of template class 'deduction_substitution_failure::A<int, int>'}} |
| 410 |
|
| 411 |
template<typename T, typename U> int B; // expected-warning 0-1 {{extension}} |
| 412 |
template<typename T> int B<T, typename Fail<T>::error> {}; // expected-note {{instantiation of}} |
| 413 |
int bi = B<char, char>; // expected-note {{during template argument deduction for variable template partial specialization 'B<T, typename Fail<T>::error>' [with T = char]}} |
| 414 |
} |
| 415 |
|
| 416 |
namespace deduce_pack_from_argument { |
| 417 |
template <typename... T> |
| 418 |
void separator(args_tag<T...>, T..., int, T...) {} |
| 419 |
template <typename... T> |
| 420 |
void separator_dependent(args_tag<T...>, type_identity_t<T>..., int, type_identity_t<T>...) {} |
| 421 |
template <typename... Y, typename... T> |
| 422 |
void separator_multiple_parameters(args_tag<Y...>, args_tag<T...>, type_identity_t<T>..., int mid, type_identity_t<T>...) {} |
| 423 |
|
| 424 |
void test_separator() { |
| 425 |
separator(args_tag<int, int>{}, 4, 8, 42, 16, 25); |
| 426 |
separator(args_tag<>{}, 42); |
| 427 |
separator_dependent(args_tag<int, int>{}, 4, 8, 42, 16, 25); |
| 428 |
separator_dependent(args_tag<>{}, 42); |
| 429 |
separator_multiple_parameters(args_tag<const int, const int>{}, args_tag<int, int>{}, 8, 9, 15, 16, 23); |
| 430 |
} |
| 431 |
|
| 432 |
template <typename... Y, typename... T> void no_separator(args_tag<T...>, T..., T...) {} |
| 433 |
template <typename... Y, typename... T> |
| 434 |
void no_separator_dependent(args_tag<Y...>, args_tag<T...>, type_identity_t<T>..., type_identity_t<T>...) {} |
| 435 |
|
| 436 |
void test_no_separator() { |
| 437 |
no_separator(args_tag<int, int>{}, 1, 2, 3, 4); |
| 438 |
no_separator(args_tag<>{}); |
| 439 |
no_separator_dependent(args_tag<const int, const int>{}, args_tag<int, int>{}, 8, 9, 15, 16); |
| 440 |
no_separator_dependent(args_tag<>{}, args_tag<>{}); |
| 441 |
} |
| 442 |
} |
| 443 |
|
| 444 |
namespace deduction_after_explicit_pack { |
| 445 |
template<typename ...T, typename U> int *f(T ...t, int &r, U *u) { |
| 446 |
return u; |
| 447 |
} |
| 448 |
template<typename U, typename ...T> int *g(T ...t, int &r, U *u) { |
| 449 |
return u; |
| 450 |
} |
| 451 |
void h(float a, double b, int c) { |
| 452 |
f<float&, double&>(a, b, c, &c); // ok |
| 453 |
g<int, float&, double&>(a, b, c, &c); // ok |
| 454 |
} |
| 455 |
|
| 456 |
template<class... ExtraArgs> |
| 457 |
int test(ExtraArgs..., unsigned vla_size, const char *input); |
| 458 |
int n = test(0, ""); |
| 459 |
|
| 460 |
template <typename... T> void i(T..., int, T..., ...); // expected-note 5{{deduced packs of different lengths}} |
| 461 |
void j() { |
| 462 |
i(0); |
| 463 |
i(0, 1); // expected-error {{no match}} |
| 464 |
i(0, 1, 2); // expected-error {{no match}} |
| 465 |
i<>(0); |
| 466 |
i<>(0, 1); // expected-error {{no match}} |
| 467 |
i<>(0, 1, 2); // expected-error {{no match}} |
| 468 |
i<int, int>(0, 1, 2, 3, 4); |
| 469 |
i<int, int>(0, 1, 2, 3, 4, 5); // expected-error {{no match}} |
| 470 |
} |
| 471 |
|
| 472 |
// GCC alarmingly accepts this by deducing T={int} by matching the second |
| 473 |
// parameter against the first argument, then passing the first argument |
| 474 |
// through the first parameter. |
| 475 |
template<typename... T> struct X { X(int); operator int(); }; |
| 476 |
template<typename... T> void p(T..., X<T...>, ...); // expected-note {{deduced packs of different lengths for parameter 'T' (<> vs. <int>)}} |
| 477 |
void q() { p(X<int>(0), 0); } // expected-error {{no match}} |
| 478 |
|
| 479 |
struct A { |
| 480 |
template <typename T> void f(T, void *, int = 0); // expected-note 2{{no known conversion from 'double' to 'void *' for 2nd argument}} |
| 481 |
void f(); // expected-note 2{{requires 0}} |
| 482 |
|
| 483 |
template <typename T> static void g(T, void *, int = 0); // expected-note 2{{no known conversion from 'double' to 'void *' for 2nd argument}} |
| 484 |
void g(); // expected-note 2{{requires 0}} |
| 485 |
|
| 486 |
void h() { |
| 487 |
f(1.0, 2.0); // expected-error {{no match}} |
| 488 |
g(1.0, 2.0); // expected-error {{no match}} |
| 489 |
} |
| 490 |
}; |
| 491 |
void f(A a) { |
| 492 |
a.f(1.0, 2.0); // expected-error {{no match}} |
| 493 |
a.g(1.0, 2.0); // expected-error {{no match}} |
| 494 |
} |
| 495 |
} |
| 496 |
|
| 497 |
namespace overload_vs_pack { |
| 498 |
void f(int); |
| 499 |
void f(float); |
| 500 |
void g(double); |
| 501 |
|
| 502 |
template<typename ...T> struct X {}; |
| 503 |
template<typename ...T> void x(T...); |
| 504 |
|
| 505 |
template<typename ...T> struct Y { typedef int type(typename T::error...); }; |
| 506 |
template<> struct Y<int, float, double> { typedef int type; }; |
| 507 |
|
| 508 |
template<typename ...T> typename Y<T...>::type g1(X<T...>, void (*...fns)(T)); // expected-note {{deduced conflicting types for parameter 'T' (<int, float> vs. <(no value), double>)}} |
| 509 |
template<typename ...T> typename Y<T...>::type g2(void(*)(T...), void (*...fns)(T)); // expected-note {{deduced conflicting types for parameter 'T' (<int, float> vs. <(no value), double>)}} |
| 510 |
|
| 511 |
template<typename T> int &h1(decltype(g1(X<int, float, T>(), f, f, g)) *p); |
| 512 |
template<typename T> float &h1(...); |
| 513 |
|
| 514 |
template<typename T> int &h2(decltype(g2(x<int, float, T>, f, f, g)) *p); |
| 515 |
template<typename T> float &h2(...); |
| 516 |
|
| 517 |
int n1 = g1(X<int, float>(), f, g); // expected-error {{no matching function}} |
| 518 |
int n2 = g2(x<int, float>, f, g); // expected-error {{no matching function}} |
| 519 |
|
| 520 |
int &a1 = h1<double>(0); // ok, skip deduction for 'f's, deduce matching value from 'g' |
| 521 |
int &a2 = h2<double>(0); |
| 522 |
|
| 523 |
float &b1 = h1<float>(0); // deduce mismatching value from 'g', so we do not trigger instantiation of Y |
| 524 |
float &b2 = h2<float>(0); |
| 525 |
|
| 526 |
template<typename ...T> int partial_deduction(void (*...f)(T)); // expected-note {{deduced incomplete pack <(no value), double> for template parameter 'T'}} |
| 527 |
int pd1 = partial_deduction(f, g); // expected-error {{no matching function}} |
| 528 |
|
| 529 |
template<typename ...T> int partial_deduction_2(void (*...f)(T), ...); // expected-note {{deduced incomplete pack <(no value), double> for template parameter 'T'}} |
| 530 |
int pd2 = partial_deduction_2(f, g); // expected-error {{no matching function}} |
| 531 |
|
| 532 |
namespace cwg_example { |
| 533 |
void f(char, char); |
| 534 |
void f(int, int); |
| 535 |
void x(int, char); |
| 536 |
|
| 537 |
template<typename T, typename ...U> void j(void(*)(U...), void (*...fns)(T, U)); |
| 538 |
void test() { j(x, f, x); } |
| 539 |
} |
| 540 |
} |
| 541 |
|
| 542 |
namespace b29946541 { |
| 543 |
template<typename> class A {}; |
| 544 |
template<typename T, typename U, template<typename, typename> class C> |
| 545 |
void f(C<T, U>); // expected-note {{failed template argument deduction}} |
| 546 |
void g(A<int> a) { f(a); } // expected-error {{no match}} |
| 547 |
} |
| 548 |
|
| 549 |
namespace deduction_from_empty_list { |
| 550 |
template<int M, int N = 5> void f(int (&&)[N], int (&&)[N]) { // expected-note {{1 vs. 2}} |
| 551 |
static_assert(M == N, ""); |
| 552 |
} |
| 553 |
|
| 554 |
void test() { |
| 555 |
f<5>({}, {}); |
| 556 |
f<1>({}, {0}); |
| 557 |
f<1>({0}, {}); |
| 558 |
f<1>({0}, {0}); |
| 559 |
f<1>({0}, {0, 1}); // expected-error {{no matching}} |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
namespace check_extended_pack { |
| 564 |
template<typename T> struct X { typedef int type; }; |
| 565 |
template<typename ...T> void f(typename X<T>::type...); |
| 566 |
template<typename T> void f(T, int, int); |
| 567 |
void g() { |
| 568 |
f<int>(0, 0, 0); |
| 569 |
} |
| 570 |
|
| 571 |
template<int, int*> struct Y {}; |
| 572 |
template<int ...N> void g(Y<N...>); // expected-note {{deduced non-type template argument does not have the same type as the corresponding template parameter ('int *' vs 'int')}} |
| 573 |
int n; |
| 574 |
void h() { g<0>(Y<0, &n>()); } // expected-error {{no matching function}} |
| 575 |
} |
| 576 |
|
| 577 |
namespace dependent_template_template_param_non_type_param_type { |
| 578 |
template<int N> struct A { |
| 579 |
template<typename V = int, V M = 12, V (*Y)[M], template<V (*v)[M]> class W> |
| 580 |
A(W<Y>); |
| 581 |
}; |
| 582 |
|
| 583 |
int n[12]; |
| 584 |
template<int (*)[12]> struct Q {}; |
| 585 |
Q<&n> qn; |
| 586 |
A<0> a(qn); |
| 587 |
} |
| 588 |
|
| 589 |
namespace dependent_list_deduction { |
| 590 |
template<typename T, T V> void a(const int (&)[V]) { |
| 591 |
static_assert(is_same<T, decltype(sizeof(0))>::value, ""); |
| 592 |
static_assert(V == 3, ""); |
| 593 |
} |
| 594 |
template<typename T, T V> void b(const T (&)[V]) { |
| 595 |
static_assert(is_same<T, int>::value, ""); |
| 596 |
static_assert(V == 3, ""); |
| 597 |
} |
| 598 |
template<typename T, T V> void c(const T (&)[V]) { |
| 599 |
static_assert(is_same<T, decltype(sizeof(0))>::value, ""); |
| 600 |
static_assert(V == 3, ""); |
| 601 |
} |
| 602 |
void d() { |
| 603 |
a({1, 2, 3}); |
| 604 |
#if __cplusplus <= 201402L |
| 605 |
// expected-error@-2 {{no match}} expected-note@-15 {{couldn't infer template argument 'T'}} |
| 606 |
#endif |
| 607 |
b({1, 2, 3}); |
| 608 |
c({{}, {}, {}}); |
| 609 |
#if __cplusplus <= 201402L |
| 610 |
// expected-error@-2 {{no match}} expected-note@-12 {{couldn't infer template argument 'T'}} |
| 611 |
#endif |
| 612 |
} |
| 613 |
|
| 614 |
template<typename ...T> struct X; |
| 615 |
template<int ...T> struct Y; |
| 616 |
template<typename ...T, T ...V> void f(const T (&...p)[V]) { |
| 617 |
static_assert(is_same<X<T...>, X<int, char, char>>::value, ""); |
| 618 |
static_assert(is_same<Y<V...>, Y<3, 2, 4>>::value, ""); |
| 619 |
} |
| 620 |
template<typename ...T, T ...V> void g(const T (&...p)[V]) { |
| 621 |
static_assert(is_same<X<T...>, X<int, decltype(sizeof(0))>>::value, ""); |
| 622 |
static_assert(is_same<Y<V...>, Y<2, 3>>::value, ""); |
| 623 |
} |
| 624 |
void h() { |
| 625 |
f({1, 2, 3}, {'a', 'b'}, "foo"); |
| 626 |
g({1, 2}, {{}, {}, {}}); |
| 627 |
#if __cplusplus <= 201402 |
| 628 |
// expected-error@-2 {{no match}} |
| 629 |
// expected-note@-9 {{deduced incomplete pack}} |
| 630 |
// We deduce V$1 = (size_t)3, which in C++1z also deduces T$1 = size_t. |
| 631 |
#endif |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
namespace designators { |
| 636 |
template<typename T, int N> constexpr int f(T (&&)[N]) { return N; } // expected-note 2{{couldn't infer template argument 'T'}} |
| 637 |
static_assert(f({1, 2, [20] = 3}) == 3, ""); // expected-error {{no matching function}} expected-warning 2{{C99}} expected-note {{}} |
| 638 |
|
| 639 |
static_assert(f({.a = 1, .b = 2}) == 3, ""); // expected-error {{no matching function}} |
| 640 |
} |
| 641 |
|
| 642 |
namespace nested_packs { |
| 643 |
template<typename ...T, typename ...U> void f(T (*...f)(U...)); // expected-note {{deduced packs of different lengths for parameter 'U' (<> vs. <int>)}} |
| 644 |
void g() { f(g); f(g, g); f(g, g, g); } |
| 645 |
void h(int) { f(h); f(h, h); f(h, h, h); } |
| 646 |
void i() { f(g, h); } // expected-error {{no matching function}} |
| 647 |
|
| 648 |
#if __cplusplus >= 201703L |
| 649 |
template<auto ...A> struct Q {}; |
| 650 |
template<typename ...T, T ...A, T ...B> void q(Q<A...>, Q<B...>); // #q |
| 651 |
void qt(Q<> q0, Q<1, 2> qii, Q<1, 2, 3> qiii) { |
| 652 |
q(q0, q0); |
| 653 |
q(qii, qii); |
| 654 |
q(qii, qiii); // expected-error {{no match}} expected-note@#q {{deduced packs of different lengths for parameter 'T' (<int, int> vs. <int, int, int>)}} |
| 655 |
q(q0, qiii); // expected-error {{no match}} expected-note@#q {{deduced packs of different lengths for parameter 'T' (<> vs. <int, int, int>)}} |
| 656 |
} |
| 657 |
#endif |
| 658 |
} |
| 659 |
|
| 660 |
namespace PR44890 { |
| 661 |
template<typename ...Ts> |
| 662 |
struct tuple {}; |
| 663 |
|
| 664 |
template<int I, typename ...Ts> |
| 665 |
int get0(const tuple<Ts...> &t) { return 0; } |
| 666 |
|
| 667 |
template<typename ...Ts> struct tuple_wrapper : tuple<Ts...> { |
| 668 |
template<int I> int get() { return get0<0, Ts...>(*this); } |
| 669 |
}; |
| 670 |
|
| 671 |
int f() { |
| 672 |
tuple_wrapper<int> w; |
| 673 |
return w.get<0>(); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
namespace merge_size_only_deductions { |
| 678 |
#if __cplusplus >= 201703L |
| 679 |
// Based on a testcase by Hubert Tong. |
| 680 |
template<typename ...> struct X {}; |
| 681 |
template<auto ...> struct Y {}; |
| 682 |
template<typename T> struct id { using Type = T; }; |
| 683 |
|
| 684 |
template<typename ...T, typename T::Type ...V> |
| 685 |
int f(X<char [V] ...>, Y<V ...>, X<T ...>); |
| 686 |
|
| 687 |
using size_t = __SIZE_TYPE__; |
| 688 |
int a = f(X<char [1], char [2]>(), Y<(size_t)1, (size_t)2>(), X<id<size_t>, id<size_t>>()); |
| 689 |
int b = f(X<char [1], char [2]>(), Y<1, 2>(), X<id<int>, id<int>>()); |
| 690 |
#endif |
| 691 |
} |
| 692 |
|
| 693 |
namespace PR49724 { |
| 694 |
struct A; |
| 695 |
template<int A::*> class X {}; |
| 696 |
template<int A::*P> void f(X<P>); |
| 697 |
void g(X<nullptr> x) { f(x); } |
| 698 |
|
| 699 |
template<void (A::*)()> class Y {}; |
| 700 |
template<void (A::*P)()> void f(Y<P>); |
| 701 |
void g(Y<nullptr> y) { f(y); } |
| 702 |
} |
| 703 |
|
| 704 |
namespace sugared_deduction { |
| 705 |
using Int = int; |
| 706 |
|
| 707 |
template <class T, int C> void f1(T(&)[C], T(&)[C+1]); |
| 708 |
// expected-note@-1 {{candidate template ignored: deduced type 'int[3]' of 2nd parameter does not match adjusted type 'Int[2]' (aka 'int[2]') of argument [with T = Int, C = 2]}} |
| 709 |
|
| 710 |
void t1() { |
| 711 |
Int a[2], b[2]; |
| 712 |
f1(a, b); // expected-error {{no matching function for call to 'f1'}} |
| 713 |
} |
| 714 |
|
| 715 |
#if defined(__cpp_concepts) |
| 716 |
template <class T> void f2() requires false {} |
| 717 |
// expected-note@-1 {{candidate template ignored: constraints not satisfied [with T = Int]}} |
| 718 |
// expected-note@-2 {{because 'false' evaluated to false}} |
| 719 |
|
| 720 |
void t2() { |
| 721 |
f2<Int>(); // expected-error {{no matching function for call to 'f2'}} |
| 722 |
} |
| 723 |
#endif |
| 724 |
} // namespace sugared_deduction |