Implement support for pack expansions in initializer lists and
[clang.git] / test / CXX / temp / temp.decls / temp.variadic / p4.cpp
blob440bd4b5dbfed338748dbf0b830a6b91dd4f8bbf
1 // RUN: %clang_cc1 -std=c++0x -fsyntax-only -fexceptions -verify %s
3 template<typename... Types> struct tuple;
4 template<int I> struct int_c;
6 template<typename T>
7 struct identity {
8 typedef T type;
9 };
11 template<typename T, typename U>
12 struct is_same {
13 static const bool value = false;
16 template<typename T>
17 struct is_same<T, T> {
18 static const bool value = true;
21 // FIXME: Many more bullets to go
23 // In an initializer-list (8.5); the pattern is an initializer-clause.
24 // Note: this also covers expression-lists, since expression-list is
25 // just defined as initializer-list.
26 void five_args(int, int, int, int, int); // expected-note{{candidate function not viable: requires 5 arguments, but 6 were provided}}
28 template<int ...Values>
29 void initializer_list_expansion() {
30 int values[5] = { Values... }; // expected-error{{excess elements in array initializer}}
31 five_args(Values...); // expected-error{{no matching function for call to 'five_args'}}
34 template void initializer_list_expansion<1, 2, 3, 4, 5>();
35 template void initializer_list_expansion<1, 2, 3, 4, 5, 6>(); // expected-note{{in instantiation of function template specialization 'initializer_list_expansion<1, 2, 3, 4, 5, 6>' requested here}}
37 // In a template-argument-list (14.3); the pattern is a template-argument.
38 template<typename ...Types>
39 struct tuple_of_refs {
40 typedef tuple<Types& ...> types;
43 tuple<int&, float&> *t_int_ref_float_ref;
44 tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 = t_int_ref_float_ref;
46 template<typename ...Types>
47 struct extract_nested_types {
48 typedef tuple<typename Types::type...> types;
51 tuple<int, float> *t_int_float;
52 extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
53 = t_int_float;
55 template<int ...N>
56 struct tuple_of_ints {
57 typedef tuple<int_c<N>...> type;
60 int check_temp_arg_1[is_same<tuple_of_ints<1, 2, 3, 4, 5>::type,
61 tuple<int_c<1>, int_c<2>, int_c<3>, int_c<4>,
62 int_c<5>>>::value? 1 : -1];
64 // In a dynamic-exception-specification (15.4); the pattern is a type-id.
65 template<typename ...Types>
66 struct f_with_except {
67 virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
70 struct check_f_with_except_1 : f_with_except<int, float> {
71 virtual void f() throw(int, float);
74 struct check_f_with_except_2 : f_with_except<int, float> {
75 virtual void f() throw(int);
78 struct check_f_with_except_3 : f_with_except<int, float> {
79 virtual void f() throw(int, float, double); // expected-error{{exception specification of overriding function is more lax than base version}}