pack-deduction.cpp 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // RUN: %clang_cc1 -std=c++11 -verify %s
  2. template<typename ...T> struct X {};
  3. template<typename T, typename U> struct P {};
  4. namespace Nested {
  5. template<typename ...T> int f1(X<T, T...>... a); // expected-note +{{conflicting types for parameter 'T'}}
  6. template<typename ...T> int f2(P<X<T...>, T> ...a); // expected-note +{{conflicting types for parameter 'T'}}
  7. int a1 = f1(X<int, int, double>(), X<double, int, double>());
  8. int a2 = f1(X<int, int>());
  9. int a3 = f1(X<int>(), X<double>()); // expected-error {{no matching}}
  10. int a4 = f1(X<int, int>(), X<int>()); // expected-error {{no matching}}
  11. int a5 = f1(X<int>(), X<int, int>()); // expected-error {{no matching}}
  12. int a6 = f1(X<int, int, int>(), X<int, int, int>(), X<int, int, int, int>()); // expected-error {{no matching}}
  13. int b1 = f2(P<X<int, double>, int>(), P<X<int, double>, double>());
  14. int b2 = f2(P<X<int, double>, int>(), P<X<int, double>, double>(), P<X<int, double>, char>()); // expected-error {{no matching}}
  15. }
  16. namespace PR14841 {
  17. template<typename T, typename U> struct A {};
  18. template<typename ...Ts> void f(A<Ts...>); // expected-note {{substitution failure [with Ts = <char, short, int>]: too many template arg}}
  19. void g(A<char, short> a) {
  20. f(a);
  21. f<char>(a);
  22. f<char, short>(a);
  23. f<char, short, int>(a); // expected-error {{no matching function}}
  24. }
  25. }
  26. namespace RetainExprPacks {
  27. int f(int a, int b, int c);
  28. template<typename ...Ts> struct X {};
  29. template<typename ...Ts> int g(X<Ts...>, decltype(f(Ts()...)));
  30. int n = g<int, int>(X<int, int, int>(), 0);
  31. }
  32. namespace PR14615 {
  33. namespace comment0 {
  34. template <class A, class...> struct X {};
  35. template <class... B> struct X<int, B...> {
  36. typedef int type;
  37. struct valid {};
  38. };
  39. template <typename A, typename... B, typename T = X<A, B...>,
  40. typename = typename T::valid>
  41. typename T::type check(int);
  42. int i = check<int, char>(1);
  43. }
  44. namespace comment2 {
  45. template <class...> struct X;
  46. template <typename... B, typename X<B...>::type I = 0>
  47. char check(B...); // expected-note {{undefined template 'PR14615::comment2::X<char, int>'}}
  48. void f() { check<char>(1, 2); } // expected-error {{no matching function}}
  49. }
  50. namespace comment3 {
  51. template <class...> struct X;
  52. template <typename... B, typename X<B...>::type I = (typename X<B...>::type)0>
  53. char check(B...); // expected-note {{undefined template 'PR14615::comment3::X<char, int>'}}
  54. void f() { check<char>(1, 2); } // expected-error {{no matching function}}
  55. }
  56. }