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