aboutsummaryrefslogtreecommitdiff
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-09-07 02:06:42 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-09-07 02:06:42 +0000
commit1fde8ece371a86fe3aae232e9d143fbd8dc34d08 (patch)
treee02b5ce8098d8aaae92b5a6e42692c2438a41f21 /clang/test
parent97158ca5c26c759ccdc81ef01a3f94f2fdb264c6 (diff)
downloadllvm-1fde8ece371a86fe3aae232e9d143fbd8dc34d08.zip
llvm-1fde8ece371a86fe3aae232e9d143fbd8dc34d08.tar.gz
llvm-1fde8ece371a86fe3aae232e9d143fbd8dc34d08.tar.bz2
PR9023: A template template parameter whose template parameter list contains an
unexpanded parameter pack is a pack expansion. Thus, as with a non-type template parameter which is a pack expansion, it needs to be expanded early into a fixed list of template parameters. Since the expanded list of template parameters is not itself a parameter pack, it is permitted to appear before the end of the template parameter list, so also remove that restriction (for both template template parameter pack expansions and non-type template parameter pack expansions). llvm-svn: 163369
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/CXX/temp/temp.param/p15-cxx0x.cpp150
-rw-r--r--clang/test/PCH/cxx-variadic-templates.cpp4
-rw-r--r--clang/test/PCH/cxx-variadic-templates.h7
3 files changed, 161 insertions, 0 deletions
diff --git a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
index 5fc57a4..4cc1f17 100644
--- a/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
+++ b/clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
@@ -22,3 +22,153 @@ void f(const X<int> x) {
template<typename T = void> struct X1 { };
X1<X1<>> x1a;
+
+
+namespace ParameterPackExpansions {
+
+// A template parameter pack that [contains an unexpanded parameter pack] is a
+// pack expansion.
+
+template<typename...Ts> struct Outer {
+ // From [temp.variadic]p4:
+ // In a template parameter pack that is a pack expansion, the pattern is
+ // [...the template-parameter...] without the ellipsis.
+ // Therefore the resulting sequence of parameters is not a parameter pack,
+ // so is not required to be the last template parameter.
+ template<Ts ...As, template<Ts> class ...Bs, typename ...Cs> struct Inner {
+ struct Check : Bs<As>... {
+ Check(Cs...);
+ };
+ };
+};
+
+template<int> struct TemplateInt {};
+template<char> struct TemplateChar {};
+template<int*> struct TemplateIntPtr {};
+int x;
+
+Outer<int, char, int*>::
+Inner<12345, 'x', &x,
+ TemplateInt, TemplateChar, TemplateIntPtr,
+ int*>::
+Check check(&x);
+
+
+template<typename...Ts> struct types;
+
+enum place { _ };
+template<place...> struct places {};
+
+template<typename P1, typename P2> struct append_places;
+template<place...X1, place...X2>
+struct append_places<places<X1...>, places<X2...>> {
+ typedef places<X1...,X2...> type;
+};
+
+template<unsigned N>
+struct make_places : append_places<typename make_places<N/2>::type,
+ typename make_places<N-N/2>::type> {};
+template<> struct make_places<0> { typedef places<> type; };
+template<> struct make_places<1> { typedef places<_> type; };
+
+template<typename T> struct wrap {
+ template<place> struct inner { typedef T type; };
+};
+
+template<typename T> struct takedrop_impl;
+template<place...X> struct takedrop_impl<places<X...>> {
+ template<template<decltype(X)> class ...Take,
+ template<place > class ...Drop>
+ struct inner { // expected-note 2{{declared}}
+ typedef types<typename Take<_>::type...> take;
+ typedef types<typename Drop<_>::type...> drop;
+ };
+};
+
+template<unsigned N, typename...Ts> struct take {
+ using type = typename takedrop_impl<typename make_places<N>::type>::
+ template inner<wrap<Ts>::template inner...>::take; // expected-error {{too few template arguments}}
+};
+template<unsigned N, typename...Ts> struct drop {
+ using type = typename takedrop_impl<typename make_places<N>::type>::
+ template inner<wrap<Ts>::template inner...>::drop; // expected-error {{too few template arguments}}
+};
+
+using T1 = take<3, int, char, double, long>::type; // expected-note {{previous}}
+using T1 = types<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<int, char, double, (no argument)>'}}
+using D1 = drop<3, int, char, double, long>::type;
+using D1 = types<long>;
+
+using T2 = take<4, int, char, double, long>::type; // expected-note {{previous}}
+using T2 = types<int, char, double, long>;
+using T2 = types<void, void, void, void>; // expected-error {{'types<void, void, void, void>' vs 'types<int, char, double, long>'}}
+using D2 = drop<4, int, char, double, long>::type;
+using D2 = types<>;
+
+using T3 = take<5, int, char, double, long>::type; // expected-note {{in instantiation of}}
+using D3 = drop<5, int, char, double, long>::type; // expected-note {{in instantiation of}}
+
+
+// FIXME: We should accept this code. A parameter pack within a default argument
+// in a template template parameter pack is expanded, because the pack is
+// implicitly a pack expansion.
+template<typename ...Default> struct DefArg {
+ template<template<typename T = Default> class ...Classes> struct Inner { // expected-error {{default argument contains unexpanded parameter pack}} expected-note {{here}}
+ Inner(Classes<>...); // expected-error {{too few}}
+ };
+};
+template<typename T> struct vector {};
+template<typename T> struct list {};
+vector<int> vi;
+list<char> lc;
+DefArg<int, char>::Inner<vector, list> defarg(vi, lc);
+
+
+// FIXME:
+// A template parameter pack that is a pack expansion shall not expand a
+// parameter pack declared in the same template-parameter-list.
+template<typename...Ts, Ts...Vs> void error(); // desired-error
+
+// This case should not produce an error, because in A's instantiation, Cs is
+// not a parameter pack.
+template<typename...Ts> void consume(Ts...);
+template<typename...Ts> struct A {
+ template<template<typename, Ts = 0> class ...Cs, Cs<Ts> ...Vs> struct B { // ok
+ B() {
+ consume([]{
+ int arr[Vs]; // expected-error {{negative size}}
+ }...);
+ }
+ };
+};
+template<typename, int> using Int = int;
+template<typename, short> using Char = char;
+A<int, short>::B<Int, Char, -1, 'x'> b; // expected-note {{here}}
+
+}
+
+namespace PR9023 {
+ template<typename ...T> struct A {
+ template<template<T> class ...> struct B {
+ };
+ };
+
+ template<int> struct C { };
+ template<long> struct D { };
+
+ int main() {
+ A<int, long>::B<C, D> e;
+ }
+}
+
+namespace std_examples {
+ template <class... Types> class Tuple;
+ template <class T, int... Dims> struct multi_array;
+ template <class... T> struct value_holder {
+ template<T... Values> struct apply { };
+ };
+ template <class... T, T... Values> struct static_array; // expected-error {{must be the last}}
+
+ int n;
+ value_holder<int, char, int*>::apply<12345, 'x', &n> test;
+}
diff --git a/clang/test/PCH/cxx-variadic-templates.cpp b/clang/test/PCH/cxx-variadic-templates.cpp
index 5b58693..c78a1a5 100644
--- a/clang/test/PCH/cxx-variadic-templates.cpp
+++ b/clang/test/PCH/cxx-variadic-templates.cpp
@@ -9,3 +9,7 @@
// CHECK: allocate_shared
shared_ptr<int> spi = shared_ptr<int>::allocate_shared(1, 2);
+
+template<int> struct A {};
+template<int> struct B {};
+outer<int, int>::inner<1, 2, A, B> i(A<1>{}, B<2>{});
diff --git a/clang/test/PCH/cxx-variadic-templates.h b/clang/test/PCH/cxx-variadic-templates.h
index f6ee787..50596cd 100644
--- a/clang/test/PCH/cxx-variadic-templates.h
+++ b/clang/test/PCH/cxx-variadic-templates.h
@@ -16,3 +16,10 @@ shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
shared_ptr<_Tp> __r;
return __r;
}
+
+template<typename...Ts> struct outer {
+ template<Ts...Vs, template<Ts> class ...Cs> struct inner {
+ inner(Cs<Vs>...);
+ };
+};
+template struct outer<int, int>;