1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
3 template<typename T
, T
...Values
> struct value_tuple
{};
4 template<typename
...> struct tuple
{ };
5 template<typename T
, typename U
> struct pair
{ };
7 template<typename T
, T Value
> struct value_c
;
9 template<typename T
, typename U
>
11 static const bool value
= false;
15 struct is_same
<T
, T
> {
16 static const bool value
= true;
22 void f(value_tuple
<T
, Values
...> * = 0);
26 X0
<int>().f
<1, 2, 3, 4, 5>();
29 namespace PacksAtDifferentLevels
{
31 template<typename
...Types
>
33 template<typename
> struct Inner
{
34 static const unsigned value
= 1;
37 template<typename
...YTypes
>
38 struct Inner
<tuple
<pair
<Types
, YTypes
>...> > {
39 static const unsigned value
= sizeof...(Types
) - sizeof...(YTypes
);
43 int check0
[X
<short, int, long>::Inner
<tuple
<pair
<short, unsigned short>,
44 pair
<int, unsigned int>,
45 pair
<long, unsigned long>>
46 >::value
== 0? 1 : -1];
48 int check1
[X
<short, int>::Inner
<tuple
<pair
<short, unsigned short>,
49 pair
<int, unsigned int>,
50 pair
<long, unsigned long>>
51 >::value
== 1? 1 : -1];
53 template<unsigned ...Values
> struct unsigned_tuple
{ };
54 template<typename
...Types
>
56 template<typename
, typename
> struct Inner
{
57 static const unsigned value
= 0;
60 template<typename
...YTypes
>
61 struct Inner
<tuple
<pair
<Types
, YTypes
>...>,
62 unsigned_tuple
<sizeof(Types
) + sizeof(YTypes
)...>> {
63 static const unsigned value
= 1;
67 int check2
[X1
<short, int, long>::Inner
<tuple
<pair
<short, unsigned short>,
68 pair
<int, unsigned int>,
69 pair
<long, unsigned long>>,
70 unsigned_tuple
<sizeof(short) + sizeof(unsigned short),
71 sizeof(int) + sizeof(unsigned int),
72 sizeof(long) + sizeof(unsigned long)>
73 >::value
== 1? 1 : -1];
74 int check3
[X1
<short, int>::Inner
<tuple
<pair
<short, unsigned short>,
75 pair
<int, unsigned int>,
76 pair
<long, unsigned long>>,
77 unsigned_tuple
<sizeof(short) + sizeof(unsigned short),
78 sizeof(int) + sizeof(unsigned int),
79 sizeof(long) + sizeof(unsigned long)>
80 >::value
== 0? 1 : -1];
82 template<typename
...Types
>
84 template<typename
> struct Inner
{
85 static const unsigned value
= 1;
88 template<typename R
, typename
...YTypes
>
89 struct Inner
<R(pair
<Types
, YTypes
>...)> {
90 static const unsigned value
= sizeof...(Types
) - sizeof...(YTypes
);
94 int check4
[X2
<short, int, long>::Inner
<int(pair
<short, unsigned short>,
95 pair
<int, unsigned int>,
96 pair
<long, unsigned long>)
97 >::value
== 0? 1 : -1];
99 int check5
[X2
<short, int>::Inner
<int(pair
<short, unsigned short>,
100 pair
<int, unsigned int>,
101 pair
<long, unsigned long>)
102 >::value
== 1? 1 : -1];
104 template<typename T
, typename U
>
105 struct some_function_object
{
110 template<template<class> class...> struct metafun_tuple
{ };
112 template<typename
...Types1
>
114 template<typename
, typename
> struct Inner
{
115 static const unsigned value
= 0;
118 template<typename
...Types2
>
119 struct Inner
<tuple
<pair
<Types1
, Types2
>...>,
120 metafun_tuple
<some_function_object
<Types1
, Types2
>::template result_of
...> > {
121 static const unsigned value
= 1;
125 int check6
[X3
<short, int, long>::Inner
<tuple
<pair
<short, unsigned short>,
126 pair
<int, unsigned int>,
127 pair
<long, unsigned long>>,
129 some_function_object
<short, unsigned short>::result_of
,
130 some_function_object
<int, unsigned int>::result_of
,
131 some_function_object
<long, unsigned long>::result_of
>
132 >::value
== 1? 1 : -1];
133 int check7
[X3
<short, int>::Inner
<tuple
<pair
<short, unsigned short>,
134 pair
<int, unsigned int>,
135 pair
<long, unsigned long>>,
137 some_function_object
<short, unsigned short>::result_of
,
138 some_function_object
<int, unsigned int>::result_of
,
139 some_function_object
<long, unsigned long>::result_of
>
140 >::value
== 0? 1 : -1];
142 template<unsigned I
, unsigned J
> struct unsigned_pair
{ };
144 template<unsigned ...Values1
>
146 template<typename
> struct Inner
{
147 static const unsigned value
= 0;
150 template<unsigned ...Values2
>
151 struct Inner
<tuple
<unsigned_pair
<Values1
, Values2
>...>> {
152 static const unsigned value
= 1;
156 int check8
[X4
<1, 3, 5>::Inner
<tuple
<unsigned_pair
<1, 2>,
159 >::value
== 1? 1 : -1];
160 int check9
[X4
<1, 3>::Inner
<tuple
<unsigned_pair
<1, 2>,
163 >::value
== 0? 1 : -1];
165 template<class> struct add_reference
;
166 template<class> struct add_pointer
;
167 template<class> struct add_const
;
169 template<template<class> class ...Templates
>
171 template<typename
> struct Inner
{
172 static const unsigned value
= 0;
175 template<typename
...Types
>
176 struct Inner
<tuple
<Templates
<Types
>...>> {
177 static const unsigned value
= 1;
181 int check10
[X5
<add_reference
, add_pointer
, add_const
>
182 ::Inner
<tuple
<add_reference
<int>,
184 add_const
<double>>>::value
== 1? 1 : -1];
185 int check11
[X5
<add_reference
, add_pointer
>
186 ::Inner
<tuple
<add_reference
<int>,
188 add_const
<double>>>::value
== 0? 1 : -1];
191 constexpr int g(int n
, int m
) { return n
* 10 + m
; }
193 template<typename
...A
>
195 template<typename
...B
>
196 constexpr auto f1(A
...a
) const -> decltype(g(A(a
+ B())...)) { return g(A(a
+ B())...); }
198 template<typename
...B
>
199 constexpr auto f2(A
...a
, B
...b
) const -> decltype(g((&a
)[b
] ...)) { return g((&a
)[b
] ...); } // expected-note {{past-the-end}}
201 template<typename
...B
> struct Inner
{
202 template<typename
...C
>
203 constexpr auto f(A
...a
, B
...b
, C
...c
) const -> decltype(g(a
+b
+c
...)) { return g(a
+b
+c
...); }
206 struct A
{ constexpr operator int() const { return 2; } };
207 struct B
{ constexpr operator int() const { return 1; } };
209 static_assert(X6
<unsigned char, int>().f1
<A
, B
>(255, 1) == 12, "");
210 static_assert(X6
<int, int>().f2(3, 4, 0, 0) == 34, "");
211 static_assert(X6
<int, int>().f2(3, 4, 0, 1) == 34, ""); // expected-error {{constant expression}} expected-note {{in call}}
212 static_assert(X6
<int, int>::Inner
<int, int>().f(1, 2, 3, 4, 5, 6) == 102, "");
216 namespace ExpandingNonTypeTemplateParameters
{
217 template<typename
...Types
>
218 struct tuple_of_values
{
219 template<Types
...Values
> // expected-error{{a non-type template parameter cannot have type 'float'}} \
220 // expected-note{{template parameter is declared here}}
221 struct apply
{ // expected-note 2{{template is declared here}}
222 typedef tuple
<value_c
<Types
, Values
>...> type
;
228 int check_tuple_of_values_1
[
229 is_same
<tuple_of_values
<int&, float&, char, int>::apply
<i
, f
, 'a', 17>
231 tuple
<value_c
<int&, i
>, value_c
<float&, f
>, value_c
<char, 'a'>,
235 tuple_of_values
<int, float> tv1
; // expected-note{{in instantiation of template class 'ExpandingNonTypeTemplateParameters::tuple_of_values<int, float>' requested here}}
237 tuple_of_values
<int&, float&>::apply
<i
, i
>::type tv2
; // expected-error{{non-type template parameter of reference type 'float &' cannot bind to template argument of type 'int'}}
239 tuple_of_values
<int&, float&>::apply
<i
>::type tv3
; // expected-error{{too few template arguments for class template 'apply'}}
241 tuple_of_values
<int&, float&>::apply
<i
, f
, i
>::type tv4
; // expected-error{{too many template arguments for class template 'apply'}}
244 namespace ExpandingFunctionParameters
{
245 template<typename
...T
>
250 template<typename
...T
>
252 template<typename
... U
>
253 typename X0
<T(T
, U
...)...>::type
f(U
...);
266 template<typename
... Args
>
267 auto f() -> int(&)[sizeof...(Args
)];
272 int (&ir1
)[1] = s
<int>().f
<int>();
273 int (&ir3
)[3] = s
<int>().f
<int, float, double>();
278 template<typename
...> struct tuple
{};
279 template<typename
...T
>
281 template<typename
...U
>
282 void f(T
&&...t
, U
&&...u
) {} // expected-note {{candidate}}
283 template<typename
...U
>
284 void g(U
&&...u
, T
&&...t
) {} // expected-note {{candidate}}
285 template<typename
...U
>
286 void h(tuple
<T
, U
> &&...) {}
287 // expected-note@-1 {{candidate template ignored: could not match 'tuple<T, U>' against 'int'}}
288 // expected-note@-2 {{candidate template ignored: substitution failure: deduced incomplete pack <(no value)> for template parameter 'U'}}
290 template<typename
...U
>
292 template<typename
...V
>
293 void x(tuple
<T
, U
, V
> &&...); // expected-error {{different lengths}}
302 S
<int, int>().f(0); // expected-error {{no matching member function for call}}
307 S
<int>().g(0, 1); // expected-error {{no matching member function for call}}
308 S
<int>().g
<int>(0, 1);
309 S
<int, int>().g(0, 1);
312 S
<>().h(0); // expected-error {{no matching member function for call}}
313 S
<int>().h({}); // expected-error {{no matching member function for call}}
315 S
<int>().h(tuple
<int,int>{});
316 S
<int, int>().h(tuple
<int,int>{}, tuple
<int,int>{});
318 S
<int, int>::X
<char>(); // expected-note {{here}}