1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2 template <typename T
> struct X
; // expected-note {{'X<X<X<int>>>' is incomplete}}
3 template<int I
> struct Y
;
8 Y
<1 >> 2> *y2
; // FIXME: expected-error{{expected unqualified-id}}
10 X
<X
<X
<X
<X
<int>>>>> *x2
;
12 template<> struct X
<int> { };
16 void f(const X
<int> x
) {
17 (void)reinterpret_cast<X
<int>>(x
); // expected-error{{reinterpret_cast from 'const X<int>' to 'X<int>' is not allowed}}
18 (void)reinterpret_cast<X
<X
<X
<int>>>>(x
); // expected-error{{reinterpret_cast from 'const X<int>' to 'X<X<X<int>>>' is not allowed}}
23 template<typename T
= void> struct X1
{ };
27 namespace ParameterPackExpansions
{
29 // A template parameter pack that [contains an unexpanded parameter pack] is a
32 template<typename
...Ts
> struct Outer
{
33 // From [temp.variadic]p4:
34 // In a template parameter pack that is a pack expansion, the pattern is
35 // [...the template-parameter...] without the ellipsis.
36 // Therefore the resulting sequence of parameters is not a parameter pack,
37 // so is not required to be the last template parameter.
38 template<Ts
...As
, template<Ts
> class ...Bs
, typename
...Cs
> struct Inner
{
39 struct Check
: Bs
<As
>... {
45 template<int> struct TemplateInt
{};
46 template<char> struct TemplateChar
{};
47 template<int*> struct TemplateIntPtr
{};
50 Outer
<int, char, int*>::
52 TemplateInt
, TemplateChar
, TemplateIntPtr
,
57 template<typename
...Ts
> struct types
;
60 template<place
...> struct places
{};
62 template<typename P1
, typename P2
> struct append_places
;
63 template<place
...X1
, place
...X2
>
64 struct append_places
<places
<X1
...>, places
<X2
...>> {
65 typedef places
<X1
...,X2
...> type
;
69 struct make_places
: append_places
<typename make_places
<N
/2>::type
,
70 typename make_places
<N
-N
/2>::type
> {};
71 template<> struct make_places
<0> { typedef places
<> type
; };
72 template<> struct make_places
<1> { typedef places
<_
> type
; };
74 template<typename T
> struct wrap
{
75 template<place
> struct inner
{ typedef T type
; };
78 template<typename T
> struct takedrop_impl
;
79 template<place
...X
> struct takedrop_impl
<places
<X
...>> {
80 template<template<decltype(X
)> class ...Take
,
81 template<place
> class ...Drop
>
82 struct inner
{ // expected-note 2{{declared}}
83 typedef types
<typename Take
<_
>::type
...> take
;
84 typedef types
<typename Drop
<_
>::type
...> drop
;
88 template<unsigned N
, typename
...Ts
> struct take
{
89 using type
= typename takedrop_impl
<typename make_places
<N
>::type
>::
90 template inner
<wrap
<Ts
>::template inner
...>::take
; // expected-error {{too few template arguments}}
92 template<unsigned N
, typename
...Ts
> struct drop
{
93 using type
= typename takedrop_impl
<typename make_places
<N
>::type
>::
94 template inner
<wrap
<Ts
>::template inner
...>::drop
; // expected-error {{too few template arguments}}
97 using T1
= take
<3, int, char, double, long>::type
; // expected-note {{previous}}
98 // FIXME: Desguar the types on the RHS in this diagnostic.
99 // desired-error {{'types<void, void, void, void>' vs 'types<int, char, double, (no argument)>'}}
100 using T1
= types
<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<typename inner<_>::type, typename inner<_>::type, typename inner<_>::type, (no argument)>'}}
101 using D1
= drop
<3, int, char, double, long>::type
;
102 using D1
= types
<long>;
104 using T2
= take
<4, int, char, double, long>::type
; // expected-note {{previous}}
105 // FIXME: Desguar the types on the RHS in this diagnostic.
106 // desired-error {{'types<void, void, void, void>' vs 'types<int, char, double, long>'}}
107 using T2
= types
<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<typename inner<_>::type, typename inner<_>::type, typename inner<_>::type, typename inner<_>::type>'}}
108 using T2
= types
<int, char, double, long>;
109 using D2
= drop
<4, int, char, double, long>::type
;
112 using T3
= take
<5, int, char, double, long>::type
; // expected-note {{in instantiation of}}
113 using D3
= drop
<5, int, char, double, long>::type
; // expected-note {{in instantiation of}}
116 // FIXME: We should accept this code. A parameter pack within a default argument
117 // in a template template parameter pack is expanded, because the pack is
118 // implicitly a pack expansion.
119 template<typename
...Default
> struct DefArg
{
120 template<template<typename T
= Default
> class ...Classes
> struct Inner
{ // expected-error {{default argument contains unexpanded parameter pack}} expected-note {{here}}
121 Inner(Classes
<>...); // expected-error {{too few}}
124 template<typename T
> struct vector
{};
125 template<typename T
> struct list
{};
128 DefArg
<int, char>::Inner
<vector
, list
> defarg(vi
, lc
);
132 // A template parameter pack that is a pack expansion shall not expand a
133 // parameter pack declared in the same template-parameter-list.
134 template<typename
...Ts
, Ts
...Vs
> void error(); // desired-error
136 // This case should not produce an error, because in A's instantiation, Cs is
137 // not a parameter pack.
138 template<typename
...Ts
> void consume(Ts
...);
139 template<typename
...Ts
> struct A
{
140 template<template<typename
, Ts
= 0> class ...Cs
, Cs
<Ts
> ...Vs
> struct B
{ // ok
143 int arr
[Vs
]; // expected-error {{negative size}}
144 // expected-note@-2 {{while substituting into a lambda expression here}}
149 template<typename
, int> using Int
= int;
150 template<typename
, short> using Char
= char;
151 A
<int, short>::B
<Int
, Char
, -1, 'x'> b
; // expected-note {{here}}
156 template<typename
...T
> struct A
{
157 template<template<T
> class ...> struct B
{
161 template<int> struct C
{ };
162 template<long> struct D
{ };
165 A
<int, long>::B
<C
, D
> e
;
169 namespace std_examples
{
170 template <class... Types
> class Tuple
;
171 template <class T
, int... Dims
> struct multi_array
;
172 template <class... T
> struct value_holder
{
173 template<T
... Values
> struct apply
{ };
175 template <class... T
, T
... Values
> struct static_array
; // expected-error {{must be the last}}
178 value_holder
<int, char, int*>::apply
<12345, 'x', &n
> test
;