1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
2*67e74705SXin Li template<typename T> struct X; // expected-note {{'X' is incomplete}}
3*67e74705SXin Li template<int I> struct Y;
4*67e74705SXin Li
5*67e74705SXin Li X<X<int>> *x1;
6*67e74705SXin Li
7*67e74705SXin Li Y<(1 >> 2)> *y1;
8*67e74705SXin Li Y<1 >> 2> *y2; // FIXME: expected-error{{expected unqualified-id}}
9*67e74705SXin Li
10*67e74705SXin Li X<X<X<X<X<int>>>>> *x2;
11*67e74705SXin Li
12*67e74705SXin Li template<> struct X<int> { };
13*67e74705SXin Li typedef X<int> X_int;
14*67e74705SXin Li struct Z : X_int { };
15*67e74705SXin Li
f(const X<int> x)16*67e74705SXin Li void f(const X<int> x) {
17*67e74705SXin Li (void)reinterpret_cast<X<int>>(x); // expected-error{{reinterpret_cast from}}
18*67e74705SXin Li (void)reinterpret_cast<X<X<X<int>>>>(x); // expected-error{{reinterpret_cast from}}
19*67e74705SXin Li
20*67e74705SXin Li X<X<int>> *x1;
21*67e74705SXin Li }
22*67e74705SXin Li
23*67e74705SXin Li template<typename T = void> struct X1 { };
24*67e74705SXin Li X1<X1<>> x1a;
25*67e74705SXin Li
26*67e74705SXin Li
27*67e74705SXin Li namespace ParameterPackExpansions {
28*67e74705SXin Li
29*67e74705SXin Li // A template parameter pack that [contains an unexpanded parameter pack] is a
30*67e74705SXin Li // pack expansion.
31*67e74705SXin Li
32*67e74705SXin Li template<typename...Ts> struct Outer {
33*67e74705SXin Li // From [temp.variadic]p4:
34*67e74705SXin Li // In a template parameter pack that is a pack expansion, the pattern is
35*67e74705SXin Li // [...the template-parameter...] without the ellipsis.
36*67e74705SXin Li // Therefore the resulting sequence of parameters is not a parameter pack,
37*67e74705SXin Li // so is not required to be the last template parameter.
38*67e74705SXin Li template<Ts ...As, template<Ts> class ...Bs, typename ...Cs> struct Inner {
39*67e74705SXin Li struct Check : Bs<As>... {
40*67e74705SXin Li Check(Cs...);
41*67e74705SXin Li };
42*67e74705SXin Li };
43*67e74705SXin Li };
44*67e74705SXin Li
45*67e74705SXin Li template<int> struct TemplateInt {};
46*67e74705SXin Li template<char> struct TemplateChar {};
47*67e74705SXin Li template<int*> struct TemplateIntPtr {};
48*67e74705SXin Li int x;
49*67e74705SXin Li
50*67e74705SXin Li Outer<int, char, int*>::
51*67e74705SXin Li Inner<12345, 'x', &x,
52*67e74705SXin Li TemplateInt, TemplateChar, TemplateIntPtr,
53*67e74705SXin Li int*>::
54*67e74705SXin Li Check check(&x);
55*67e74705SXin Li
56*67e74705SXin Li
57*67e74705SXin Li template<typename...Ts> struct types;
58*67e74705SXin Li
59*67e74705SXin Li enum place { _ };
60*67e74705SXin Li template<place...> struct places {};
61*67e74705SXin Li
62*67e74705SXin Li template<typename P1, typename P2> struct append_places;
63*67e74705SXin Li template<place...X1, place...X2>
64*67e74705SXin Li struct append_places<places<X1...>, places<X2...>> {
65*67e74705SXin Li typedef places<X1...,X2...> type;
66*67e74705SXin Li };
67*67e74705SXin Li
68*67e74705SXin Li template<unsigned N>
69*67e74705SXin Li struct make_places : append_places<typename make_places<N/2>::type,
70*67e74705SXin Li typename make_places<N-N/2>::type> {};
71*67e74705SXin Li template<> struct make_places<0> { typedef places<> type; };
72*67e74705SXin Li template<> struct make_places<1> { typedef places<_> type; };
73*67e74705SXin Li
74*67e74705SXin Li template<typename T> struct wrap {
75*67e74705SXin Li template<place> struct inner { typedef T type; };
76*67e74705SXin Li };
77*67e74705SXin Li
78*67e74705SXin Li template<typename T> struct takedrop_impl;
79*67e74705SXin Li template<place...X> struct takedrop_impl<places<X...>> {
80*67e74705SXin Li template<template<decltype(X)> class ...Take,
81*67e74705SXin Li template<place > class ...Drop>
82*67e74705SXin Li struct inner { // expected-note 2{{declared}}
83*67e74705SXin Li typedef types<typename Take<_>::type...> take;
84*67e74705SXin Li typedef types<typename Drop<_>::type...> drop;
85*67e74705SXin Li };
86*67e74705SXin Li };
87*67e74705SXin Li
88*67e74705SXin Li template<unsigned N, typename...Ts> struct take {
89*67e74705SXin Li using type = typename takedrop_impl<typename make_places<N>::type>::
90*67e74705SXin Li template inner<wrap<Ts>::template inner...>::take; // expected-error {{too few template arguments}}
91*67e74705SXin Li };
92*67e74705SXin Li template<unsigned N, typename...Ts> struct drop {
93*67e74705SXin Li using type = typename takedrop_impl<typename make_places<N>::type>::
94*67e74705SXin Li template inner<wrap<Ts>::template inner...>::drop; // expected-error {{too few template arguments}}
95*67e74705SXin Li };
96*67e74705SXin Li
97*67e74705SXin Li using T1 = take<3, int, char, double, long>::type; // expected-note {{previous}}
98*67e74705SXin Li // FIXME: Desguar the types on the RHS in this diagnostic.
99*67e74705SXin Li // desired-error {{'types<void, void, void, void>' vs 'types<int, char, double, (no argument)>'}}
100*67e74705SXin Li 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*67e74705SXin Li using D1 = drop<3, int, char, double, long>::type;
102*67e74705SXin Li using D1 = types<long>;
103*67e74705SXin Li
104*67e74705SXin Li using T2 = take<4, int, char, double, long>::type; // expected-note {{previous}}
105*67e74705SXin Li using T2 = types<int, char, double, long>;
106*67e74705SXin Li // FIXME: Desguar the types on the RHS in this diagnostic.
107*67e74705SXin Li // desired-error {{'types<void, void, void, void>' vs 'types<int, char, double, long>'}}
108*67e74705SXin Li 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>'}}
109*67e74705SXin Li using D2 = drop<4, int, char, double, long>::type;
110*67e74705SXin Li using D2 = types<>;
111*67e74705SXin Li
112*67e74705SXin Li using T3 = take<5, int, char, double, long>::type; // expected-note {{in instantiation of}}
113*67e74705SXin Li using D3 = drop<5, int, char, double, long>::type; // expected-note {{in instantiation of}}
114*67e74705SXin Li
115*67e74705SXin Li
116*67e74705SXin Li // FIXME: We should accept this code. A parameter pack within a default argument
117*67e74705SXin Li // in a template template parameter pack is expanded, because the pack is
118*67e74705SXin Li // implicitly a pack expansion.
119*67e74705SXin Li template<typename ...Default> struct DefArg {
120*67e74705SXin Li template<template<typename T = Default> class ...Classes> struct Inner { // expected-error {{default argument contains unexpanded parameter pack}} expected-note {{here}}
121*67e74705SXin Li Inner(Classes<>...); // expected-error {{too few}}
122*67e74705SXin Li };
123*67e74705SXin Li };
124*67e74705SXin Li template<typename T> struct vector {};
125*67e74705SXin Li template<typename T> struct list {};
126*67e74705SXin Li vector<int> vi;
127*67e74705SXin Li list<char> lc;
128*67e74705SXin Li DefArg<int, char>::Inner<vector, list> defarg(vi, lc);
129*67e74705SXin Li
130*67e74705SXin Li
131*67e74705SXin Li // FIXME:
132*67e74705SXin Li // A template parameter pack that is a pack expansion shall not expand a
133*67e74705SXin Li // parameter pack declared in the same template-parameter-list.
134*67e74705SXin Li template<typename...Ts, Ts...Vs> void error(); // desired-error
135*67e74705SXin Li
136*67e74705SXin Li // This case should not produce an error, because in A's instantiation, Cs is
137*67e74705SXin Li // not a parameter pack.
138*67e74705SXin Li template<typename...Ts> void consume(Ts...);
139*67e74705SXin Li template<typename...Ts> struct A {
140*67e74705SXin Li template<template<typename, Ts = 0> class ...Cs, Cs<Ts> ...Vs> struct B { // ok
BParameterPackExpansions::A::B141*67e74705SXin Li B() {
142*67e74705SXin Li consume([]{
143*67e74705SXin Li int arr[Vs]; // expected-error {{negative size}}
144*67e74705SXin Li }...);
145*67e74705SXin Li }
146*67e74705SXin Li };
147*67e74705SXin Li };
148*67e74705SXin Li template<typename, int> using Int = int;
149*67e74705SXin Li template<typename, short> using Char = char;
150*67e74705SXin Li A<int, short>::B<Int, Char, -1, 'x'> b; // expected-note {{here}}
151*67e74705SXin Li
152*67e74705SXin Li }
153*67e74705SXin Li
154*67e74705SXin Li namespace PR9023 {
155*67e74705SXin Li template<typename ...T> struct A {
156*67e74705SXin Li template<template<T> class ...> struct B {
157*67e74705SXin Li };
158*67e74705SXin Li };
159*67e74705SXin Li
160*67e74705SXin Li template<int> struct C { };
161*67e74705SXin Li template<long> struct D { };
162*67e74705SXin Li
main()163*67e74705SXin Li int main() {
164*67e74705SXin Li A<int, long>::B<C, D> e;
165*67e74705SXin Li }
166*67e74705SXin Li }
167*67e74705SXin Li
168*67e74705SXin Li namespace std_examples {
169*67e74705SXin Li template <class... Types> class Tuple;
170*67e74705SXin Li template <class T, int... Dims> struct multi_array;
171*67e74705SXin Li template <class... T> struct value_holder {
172*67e74705SXin Li template<T... Values> struct apply { };
173*67e74705SXin Li };
174*67e74705SXin Li template <class... T, T... Values> struct static_array; // expected-error {{must be the last}}
175*67e74705SXin Li
176*67e74705SXin Li int n;
177*67e74705SXin Li value_holder<int, char, int*>::apply<12345, 'x', &n> test;
178*67e74705SXin Li }
179