p15-cxx0x.cpp revision 6964b3f80ce1ba489e7e25e7cd58062699af9b0c
1// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s 2template<typename T> struct X; 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}} 98using T1 = types<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<int, char, double, (no argument)>'}} 99using D1 = drop<3, int, char, double, long>::type; 100using D1 = types<long>; 101 102using T2 = take<4, int, char, double, long>::type; // expected-note {{previous}} 103using T2 = types<int, char, double, long>; 104using T2 = types<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<int, char, double, long>'}} 105using D2 = drop<4, int, char, double, long>::type; 106using D2 = types<>; 107 108using T3 = take<5, int, char, double, long>::type; // expected-note {{in instantiation of}} 109using D3 = drop<5, int, char, double, long>::type; // expected-note {{in instantiation of}} 110 111 112// FIXME: We should accept this code. A parameter pack within a default argument 113// in a template template parameter pack is expanded, because the pack is 114// implicitly a pack expansion. 115template<typename ...Default> struct DefArg { 116 template<template<typename T = Default> class ...Classes> struct Inner { // expected-error {{default argument contains unexpanded parameter pack}} expected-note {{here}} 117 Inner(Classes<>...); // expected-error {{too few}} 118 }; 119}; 120template<typename T> struct vector {}; 121template<typename T> struct list {}; 122vector<int> vi; 123list<char> lc; 124DefArg<int, char>::Inner<vector, list> defarg(vi, lc); 125 126 127// FIXME: 128// A template parameter pack that is a pack expansion shall not expand a 129// parameter pack declared in the same template-parameter-list. 130template<typename...Ts, Ts...Vs> void error(); // desired-error 131 132// This case should not produce an error, because in A's instantiation, Cs is 133// not a parameter pack. 134template<typename...Ts> void consume(Ts...); 135template<typename...Ts> struct A { 136 template<template<typename, Ts = 0> class ...Cs, Cs<Ts> ...Vs> struct B { // ok 137 B() { 138 consume([]{ 139 int arr[Vs]; // expected-error {{negative size}} 140 }...); 141 } 142 }; 143}; 144template<typename, int> using Int = int; 145template<typename, short> using Char = char; 146A<int, short>::B<Int, Char, -1, 'x'> b; // expected-note {{here}} 147 148} 149 150namespace PR9023 { 151 template<typename ...T> struct A { 152 template<template<T> class ...> struct B { 153 }; 154 }; 155 156 template<int> struct C { }; 157 template<long> struct D { }; 158 159 int main() { 160 A<int, long>::B<C, D> e; 161 } 162} 163 164namespace std_examples { 165 template <class... Types> class Tuple; 166 template <class T, int... Dims> struct multi_array; 167 template <class... T> struct value_holder { 168 template<T... Values> struct apply { }; 169 }; 170 template <class... T, T... Values> struct static_array; // expected-error {{must be the last}} 171 172 int n; 173 value_holder<int, char, int*>::apply<12345, 'x', &n> test; 174} 175