1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
6 template<typename T
> using C
= typename
T::B
;
7 template<typename T
> struct D
{
8 template<typename U
> using E
= typename A
<U
>::template C
<A
<T
>>;
9 template<typename U
> using F
= A
<E
<U
>>;
10 template<typename U
> using G
= C
<F
<U
>>;
13 typedef decltype(D
<B
>().g
) H
;
15 template<typename T
> using I
= A
<decltype(h
.g
)>;
16 template<typename T
> using J
= typename A
<decltype(h
.g
)>::template C
<I
<T
>>;
22 template<typename T
> T
make();
25 template<typename T
> struct traits
{
27 typedef decltype(val(make
<thing
>())) inner_ptr
;
29 template<typename U
> using rebind_thing
= typename
thing::template rebind
<U
>;
30 template<typename U
> using rebind
= traits
<rebind_thing
<U
>>;
33 void free(inner_ptr
&&);
36 template<typename T
> struct ptr_traits
{
39 template<typename T
> using ptr
= typename ptr_traits
<T
>::type
;
41 template<typename T
> struct thing
{
43 typedef ptr
<inner
> inner_ptr
;
44 typedef traits
<thing
<inner
>> traits_type
;
46 template<typename U
> using rebind
= thing
<U
>;
48 thing(traits_type
&traits
) : traits(traits
), val(traits
.alloc()) {}
49 ~thing() { traits
.free(static_cast<inner_ptr
&&>(val
)); }
54 friend inner_ptr
val(const thing
&t
) { return t
.val
; }
57 template<> struct ptr_traits
<bool> {
60 template<> bool &traits
<thing
<bool>>::alloc() { static bool b
; return b
; }
61 template<> void traits
<thing
<bool>>::free(bool&) {}
64 typedef X::traits
<X::thing
<int>> itt
;
66 itt::thing::traits_type itr
;
69 itt::rebind
<bool> btr
;
70 itt::rebind_thing
<bool> btt(btr
);
73 template<typename T
> using U
= int;
75 template<typename T
, typename
...Ts
>
76 void f1(U
<T
> i
, U
<Ts
> ...is
) { // expected-note 2{{couldn't infer template argument 'T'}}
77 return i
+ f1
<Ts
...>(is
...);
80 template<typename
...Ts
>
81 void f2(U
<Ts
> ...is
) { } // expected-note {{deduced incomplete pack <(no value)> for template parameter 'Ts'}}
83 template<typename
...> struct type_tuple
{};
84 template<typename
...Ts
>
85 void f3(type_tuple
<Ts
...>, U
<Ts
> ...is
) {} // expected-note {{deduced packs of different lengths for parameter 'Ts' (<void, void, void> vs. <(no value), (no value)>)}}
88 f1(U
<void>()); // expected-error {{no match}}
89 f1(1, 2, 3, 4, 5); // expected-error {{no match}}
91 f2(1); // expected-error {{no match}}
93 f3(type_tuple
<void, void, void>(), 1, 2); // expected-error {{no match}}
94 f3(type_tuple
<void, void, void>(), 1, 2, 3);
97 template<typename
...Ts
>
104 template<typename
...Ts
>
105 Hidden1(typename
T::template U
<Ts
> ...ts
);
108 template<typename T
, typename
...Ts
>
110 Hidden2(typename
T::template U
<Ts
> ...ts
);
114 template<typename T
> using U
= int;
118 Hidden2
<Hide
, double, char> h2(1, 2);
121 namespace Core22036
{
124 template<typename T
> using Y
= X
;
125 template<typename T
, typename
...Ts
> struct S
{
126 // An expression can contain an unexpanded pack without being type or
127 // value dependent. This is true even if the expression's type is a pack
129 void f1(Y
<T
> a
) { h(g(a
)); } // expected-error {{undeclared identifier 'g'}}
130 void f2(Y
<Ts
>...as
) { h(g(as
)...); } // expected-error {{undeclared identifier 'g'}}
131 void f3(Y
<Ts
>...as
) { g(as
...); } // ok
132 void f4(Ts
...ts
) { h(g(sizeof(ts
))...); } // expected-error {{undeclared identifier 'g'}}
133 // FIXME: We can reject this, since it has no valid instantiations because
134 // 'g' never has any associated namespaces.
135 void f5(Ts
...ts
) { g(sizeof(ts
)...); } // ok
140 template<typename A
> struct X
{};
141 template<int I
> struct C
{};
142 template<int I
> using Ci
= C
<I
>;
144 template<typename A
, int I
> void f(X
<A
>, Ci
<I
>) {}
145 template void f(X
<int>, C
<0>);
149 template <typename T
, T
... Numbers
>
150 struct NumberTuple
{ };
152 template <unsigned int... Numbers
>
153 using MyNumberTuple
= NumberTuple
<unsigned int, Numbers
...>;
155 template <typename U
, unsigned int... Numbers
>
156 void foo(U
&&, MyNumberTuple
<Numbers
...>);
158 template <typename U
, unsigned int... Numbers
>
159 void bar(U
&&, NumberTuple
<unsigned int, Numbers
...>);
162 foo(1, NumberTuple
<unsigned int, 0, 1>());
163 bar(1, NumberTuple
<unsigned int, 0, 1>());
170 template <typename T
> struct DefaultValue
{ const T value
=0;};
171 template <typename
... Args
> struct tuple
{};
172 template <typename
... Args
> using Zero
= tuple
<DefaultValue
<Args
> ...>;
173 template <typename
... Args
> void f(const Zero
<Args
...> &t
);
175 f(Zero
<int,double,double>());
180 template<int x
> struct X
{};
181 template <template<int x
> class temp
> struct DefaultValue
{ const temp
<0> value
; };
182 template <typename
... Args
> struct tuple
{};
183 template <template<int x
> class... Args
> using Zero
= tuple
<DefaultValue
<Args
> ...>;
184 template <template<int x
> class... Args
> void f(const Zero
<Args
...> &t
);
192 template <typename
,typename
>
194 template <typename
> struct derived
;
196 template <typename T
, typename U
, typename V
>
197 using derived
= base
<T
, U
>::template derived
<V
>; // expected-warning {{missing 'typename'}}
198 template <typename T
, typename U
, typename V
>
199 using derived2
= ::PR16904::base
<T
, U
>::template derived
<V
>; // expected-warning {{missing 'typename'}}
203 template<typename
...T
> using X
= int[sizeof...(T
)];
205 template<typename
...U
> struct Y
{
208 using A
= Y
<int, int, int, int>::Z
;
211 // FIXME: These should be treated as being redeclarations.
212 template<typename
...T
> void f(X
<T
...> &) {}
213 template<typename
...T
> void f(int(&)[sizeof...(T
)]) {}
215 template<typename
...T
> void g(X
<typename
T::type
...> &) {}
216 template<typename
...T
> void g(int(&)[sizeof...(T
)]) {} // ok, different
218 template<typename
...T
, typename
...U
> void h(X
<T
...> &) {}
219 template<typename
...T
, typename
...U
> void h(X
<U
...> &) {} // ok, different
221 template<typename
...T
> void i(auto (T
...t
) -> int(&)[sizeof...(t
)]);
222 auto mk_arr(int, int) -> int(&)[2];
223 void test_i() { i
<int, int>(mk_arr
); }
225 #if 0 // FIXME: This causes clang to assert.
226 template<typename
...T
> using Z
= auto (T
...p
) -> int (&)[sizeof...(p
)];
227 template<typename
...T
, typename
...U
> void j(Z
<T
..., U
...> &) {}
228 void test_j() { j
<int, int>(mk_arr
); }
231 template<typename
...T
> struct Q
{
232 template<typename
...U
> using V
= int[sizeof...(U
)];
233 template<typename
...U
> void f(V
<typename
U::type
..., typename
T::type
...> *);
235 struct B
{ typedef int type
; };
236 void test_q(int (&a
)[5]) { Q
<B
, B
, B
>().f
<B
, B
>(&a
); }
240 template<typename
> using A
= int;
241 template<typename
= void> using A
= int;
246 template<typename T
, typename
> using EnableTupleSize
= T
;
248 template<typename T
> struct tuple_size
{ static const int value
= 0; };
249 template<typename T
> struct tuple_size
<EnableTupleSize
<const T
, decltype(tuple_size
<T
>::value
)>> {};
250 template<typename T
> struct tuple_size
<EnableTupleSize
<volatile T
, decltype(tuple_size
<T
>::value
)>> {};
252 tuple_size
<const int> t
;
255 namespace an_alias_template_is_not_a_class_template
{
256 template<typename T
> using Foo
= int; // expected-note 3{{here}}
257 Foo x
; // expected-error {{use of alias template 'Foo' requires template arguments}}
258 Foo
<> y
; // expected-error {{too few template arguments for alias template 'Foo'}}
259 int z
= Foo(); // expected-error {{use of alias template 'Foo' requires template arguments}}
261 template<template<typename
> class Bar
> void f() { // expected-note 3{{here}}
262 Bar x
; // expected-error {{use of template template parameter 'Bar' requires template arguments}}
263 Bar
<> y
; // expected-error {{too few template arguments for template template parameter 'Bar'}}
264 int z
= Bar(); // expected-error {{use of template template parameter 'Bar' requires template arguments}}
268 namespace resolved_nttp
{
269 template <typename T
> struct A
{
270 template <int N
> using Arr
= T
[N
];
273 using TA
= decltype(A
<int>::a
);
276 template <typename T
> struct B
{
277 template <int... N
> using Fn
= T(int(*...A
)[N
]);
280 using TB
= decltype(B
<int>::p
);
281 using TB
= int (*)(int (*)[1], int (*)[2], int (*)[3]);
283 template <typename T
, int ...M
> struct C
{
284 template <T
... N
> using Fn
= T(int(*...A
)[N
]);
285 Fn
<1, M
..., 4> *p
; // expected-error-re 3{{evaluates to {{[234]}}, which cannot be narrowed to type 'bool'}}
287 using TC
= decltype(C
<int, 2, 3>::p
);
288 using TC
= int (*)(int (*)[1], int (*)[2], int (*)[3], int (*)[4]);
290 using TC2
= decltype(C
<bool, 2, 3>::p
); // expected-note {{instantiation of}}