1 // RUN: %clang_cc1 -std=c++11 -verify %s
3 template<typename
...T
> struct X
{};
5 template<typename T
, typename U
> struct P
{};
8 template<typename
...T
> int f1(X
<T
, T
...>... a
); // expected-note +{{packs of different lengths for parameter 'T'}}
9 template<typename
...T
> int f2(P
<X
<T
...>, T
> ...a
); // expected-note +{{packs of different lengths for parameter 'T'}}
11 int a1
= f1(X
<int, int, double>(), X
<double, int, double>());
12 int a2
= f1(X
<int, int>());
13 int a3
= f1(X
<int>(), X
<double>()); // expected-error {{no matching}}
14 int a4
= f1(X
<int, int>(), X
<int>()); // expected-error {{no matching}}
15 int a5
= f1(X
<int>(), X
<int, int>()); // expected-error {{no matching}}
16 int a6
= f1(X
<int, int, int>(), X
<int, int, int>(), X
<int, int, int, int>()); // expected-error {{no matching}}
18 int b1
= f2(P
<X
<int, double>, int>(), P
<X
<int, double>, double>());
19 int b2
= f2(P
<X
<int, double>, int>(), P
<X
<int, double>, double>(), P
<X
<int, double>, char>()); // expected-error {{no matching}}
23 template<typename T
, typename U
> struct A
{};
24 template<typename
...Ts
> void f(A
<Ts
...>); // expected-note {{substitution failure [with Ts = <char, short, int>]: too many template arg}}
26 void g(A
<char, short> a
) {
30 f
<char, short, int>(a
); // expected-error {{no matching function}}
34 namespace RetainExprPacks
{
35 int f(int a
, int b
, int c
);
36 template<typename
...Ts
> struct X
{};
37 template<typename
...Ts
> int g(X
<Ts
...>, decltype(f(Ts()...)));
38 int n
= g
<int, int>(X
<int, int, int>(), 0);
43 template <class A
, class...> struct X
{};
44 template <class... B
> struct X
<int, B
...> {
48 template <typename A
, typename
... B
, typename T
= X
<A
, B
...>,
49 typename
= typename
T::valid
>
50 typename
T::type
check(int);
51 int i
= check
<int, char>(1);
55 template <class...> struct X
;
56 template <typename
... B
, typename X
<B
...>::type I
= 0>
57 char check(B
...); // expected-note {{undefined template 'PR14615::comment2::X<char, int>'}}
58 void f() { check
<char>(1, 2); } // expected-error {{no matching function}}
62 template <class...> struct X
;
63 template <typename
... B
, typename X
<B
...>::type I
= (typename X
<B
...>::type
)0>
64 char check(B
...); // expected-note {{undefined template 'PR14615::comment3::X<char, int>'}}
65 void f() { check
<char>(1, 2); } // expected-error {{no matching function}}
69 namespace fully_expanded_packs
{
70 template<typename
...T
> struct A
{
71 template<T
...X
> static constexpr int f() {
72 // expected-note@-1 1+{{deduced too few arguments for expanded pack 'X'}}
73 // expected-note@-2 1+{{too many template arguments}}
74 return (X
+ ... + 0); // expected-warning {{extension}}
77 template<T
...X
, int Y
> static constexpr int g() {
78 // expected-note@-1 1+{{deduced too few arguments for expanded pack 'X'}}
79 // expected-note@-2 1+{{couldn't infer template argument 'Y'}}
80 // expected-note@-3 1+{{too many template arguments}}
81 return (X
+ ... + (1000 * Y
)); // expected-warning {{extension}}
84 template<T
...X
, int Y
, T
...Z
> static constexpr int h() {
85 // expected-note@-1 1+{{deduced too few arguments for expanded pack 'X'}}
86 // expected-note@-2 1+{{couldn't infer template argument 'Y'}}
87 // expected-note@-3 1+{{deduced too few arguments for expanded pack 'Z'}}
88 // expected-note@-4 1+{{too many template arguments}}
89 return (X
+ ... + (1000 * Y
)) + 1000000 * (Z
+ ... + 0); // expected-warning 2{{extension}}
92 template<T
...X
, int ...Z
> static constexpr int i() {
93 return (X
+ ... + 0) + 1000 * (Z
+ ... + 0); // expected-warning 2{{extension}}
96 template<T
...X
, int Y
, int ...Z
> static constexpr int j() {
97 return (X
+ ... + (1000 * Y
)) + 1000000 * (Z
+ ... + 0); // expected-warning 2{{extension}}
101 void check_invalid_calls() {
102 A
<int, int>::f(); // expected-error {{no matching function}}
103 A
<int, int>::f
<>(); // expected-error {{no matching function}}
104 A
<int, int>::f
<0>(); // expected-error {{no matching function}}
105 A
<int, int>::g(); // expected-error {{no matching function}}
106 A
<int, int>::g
<>(); // expected-error {{no matching function}}
107 A
<int, int>::g
<0>(); // expected-error {{no matching function}}
108 A
<int, int>::g
<0, 0>(); // expected-error {{no matching function}}
109 A
<>::f
<0>(); // expected-error {{no matching function}}
110 A
<>::g(); // expected-error {{no matching function}}
111 A
<>::g
<>(); // expected-error {{no matching function}}
112 A
<>::g
<0, 0>(); // expected-error {{no matching function}}
113 A
<>::h
<>(); // expected-error {{no matching function}}
114 A
<int>::h
<>(); // expected-error {{no matching function}}
115 A
<int>::h
<0, 0>(); // expected-error {{no matching function}}
116 A
<>::h
<0, 0>(); // expected-error {{no matching function}}
119 static_assert(A
<>::f() == 0, "");
120 static_assert(A
<int>::f
<1>() == 1, "");
121 static_assert(A
<>::g
<1>() == 1000, "");
122 static_assert(A
<int>::g
<1, 2>() == 2001, "");
123 static_assert(A
<>::h
<1>() == 1000, "");
124 static_assert(A
<int>::h
<1, 2, 3>() == 3002001, "");
125 static_assert(A
<int, int>::h
<1, 20, 3, 4, 50>() == 54003021, "");
126 static_assert(A
<>::i
<1>() == 1000, "");
127 static_assert(A
<int>::i
<1>() == 1, "");
128 static_assert(A
<>::j
<1, 2, 30>() == 32001000, "");
129 static_assert(A
<int>::j
<1, 2, 3, 40>() == 43002001, "");
132 namespace partial_full_mix
{
133 template<typename T
, typename U
> struct pair
{};
134 template<typename
...T
> struct tuple
{};
135 template<typename
...T
> struct A
{
136 template<typename
...U
> static pair
<tuple
<T
...>, tuple
<U
...>> f(pair
<T
, U
> ...p
);
137 // expected-note@-1 {{[with U = <char, double, long>]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
138 // expected-note@-2 {{[with U = <char, double, void>]: pack expansion contains parameter pack 'U' that has a different length (at least 3 vs. 2) from outer parameter packs}}
140 template<typename
...U
> static pair
<tuple
<T
...>, tuple
<U
...>> g(pair
<T
, U
> ...p
, ...);
141 // expected-note@-1 {{[with U = <char, double, long>]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 3) from outer parameter packs}}
143 template<typename
...U
> static tuple
<U
...> h(tuple
<pair
<T
, U
>..., pair
<int, int>>);
144 // expected-note@-1 {{[with U = <int[2]>]: pack expansion contains parameter pack 'U' that has a different length (2 vs. 1) from outer parameter packs}}
147 pair
<tuple
<int, float>, tuple
<char, double>> k1
= A
<int, float>().f
<char>(pair
<int, char>(), pair
<float, double>());
148 pair
<tuple
<int, float>, tuple
<char, double>> k2
= A
<int, float>().f
<char>(pair
<int, char>(), pair
<float, double>(), pair
<void, long>()); // expected-error {{no match}}
149 pair
<tuple
<int, float>, tuple
<char, double>> k3
= A
<int, float>().f
<char, double, void>(pair
<int, char>(), pair
<float, double>()); // expected-error {{no match}}
151 // FIXME: We should accept this by treating the pack 'p' as having a fixed length of 2 here.
152 pair
<tuple
<int, float>, tuple
<char, double>> k4
= A
<int, float>().g
<char>(pair
<int, char>(), pair
<float, double>(), pair
<void, long>()); // expected-error {{no match}}
154 // FIXME: We should accept this by treating the pack of pairs as having a fixed length of 2 here.
155 tuple
<int[2], int[4]> k5
= A
<int[1], int[3]>::h
<int[2]>(tuple
<pair
<int[1], int[2]>, pair
<int[3], int[4]>, pair
<int, int>>()); // expected-error {{no match}}
158 namespace substitution_vs_function_deduction
{
159 template <typename
... T
> struct A
{
160 template <typename
... U
> void f(void(*...)(T
, U
)); // expected-warning {{ISO C++11 requires a parenthesized pack declaration to have a name}}
161 template <typename
... U
> void g(void...(T
, U
)); // expected-note {{could not match 'void (T, U)' against 'void (*)(int, int)'}}
165 // FIXME: We fail to decay the parameter to a pointer type.
166 A
<int>().g(f
); // expected-error {{no match}}
170 namespace Nested_Explicit_Specialization
{
179 template <typename
... Args
>
180 void Test(Args
...) {}
185 Outer
<void>::Inner
<0>().Test(1,1);