1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -fexceptions -fcxx-exceptions -verify %s
2
3 template<typename... Types> struct tuple;
4 template<int I> struct int_c;
5
6 template<typename T>
7 struct identity {
8 typedef T type;
9 };
10
11 template<typename T, typename U>
12 struct is_same {
13 static const bool value = false;
14 };
15
16 template<typename T>
17 struct is_same<T, T> {
18 static const bool value = true;
19 };
20
21 // FIXME: Several more bullets to go
22
23 // In a function parameter pack, the pattern is the parameter-declaration
24 // without the ellipsis.
25 namespace PR11850 {
26 template<typename ...T> struct S {
fPR11850::S27 int f(T...a, int b) { return b; }
28 };
29 S<> s;
30 S<int*, char, const double&> t;
31 int k = s.f(0);
32 int l = t.f(&k, 'x', 5.9, 4);
33
34 template<typename ...As> struct A {
35 template<typename ...Bs> struct B {
36 template<typename ...Cs> struct C {
37 C(As..., Bs..., int &k, Cs...);
38 };
39 };
40 };
41 A<>::B<>::C<> c000(k);
42 A<int>::B<>::C<int> c101(1, k, 3);
43 A<>::B<int>::C<int> c011(1, k, 3);
44 A<int>::B<int>::C<> c110(1, 2, k);
45 A<int, int>::B<int, int>::C<int, int> c222(1, 2, 3, 4, k, 5, 6);
46 A<int, int, int>::B<>::C<> c300(1, 2, 3, k);
47
48 int &f();
49 char &f(void*);
50 template<typename ...A> struct U {
51 template<typename ...B> struct V {
52 auto g(A...a, B...b) -> decltype(f(a...));
53 };
54 };
55 U<>::V<int*> v0;
56 U<int*>::V<> v1;
57 int &v0f = v0.g(0);
58 char &v1f = v1.g(0);
59 }
60 namespace PR12096 {
Foo(int)61 void Foo(int) {}
62 void Foo(int, int) = delete;
63 template<typename ...Args> struct Var {
VarPR12096::Var64 Var(const Args &...args, int *) { Foo(args...); }
65 };
66 Var<int> var(1, 0);
67 }
68
69 // In an initializer-list (8.5); the pattern is an initializer-clause.
70 // Note: this also covers expression-lists, since expression-list is
71 // just defined as initializer-list.
72 void five_args(int, int, int, int, int); // expected-note{{candidate function not viable: requires 5 arguments, but 6 were provided}}
73
74 template<int ...Values>
initializer_list_expansion()75 void initializer_list_expansion() {
76 int values[5] = { Values... }; // expected-error{{excess elements in array initializer}}
77 five_args(Values...); // expected-error{{no matching function for call to 'five_args'}}
78 }
79
80 template void initializer_list_expansion<1, 2, 3, 4, 5>();
81 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}}
82
83 namespace PR8977 {
84 struct A { };
f(Args...args)85 template<typename T, typename... Args> void f(Args... args) {
86 // An empty expression-list performs value initialization.
87 constexpr T t(args...);
88 };
89
90 template void f<A>();
91 }
92
93 // In a base-specifier-list (Clause 10); the pattern is a base-specifier.
94 template<typename ...Mixins>
95 struct HasMixins : public Mixins... {
96 HasMixins();
97 HasMixins(const HasMixins&);
98 HasMixins(int i);
99 };
100
101 struct A { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}} \
102 // expected-note{{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument}} \
103 // expected-note{{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
104 struct B { };
105 struct C { };
106 struct D { };
107
108 A *checkA = new HasMixins<A, B, C, D>;
109 B *checkB = new HasMixins<A, B, C, D>;
110 D *checkD = new HasMixins<A, B, C, D>;
111 C *checkC = new HasMixins<A, B, D>; // expected-error{{cannot initialize a variable of type 'C *' with an rvalue of type 'HasMixins<A, B, D> *'}}
112 HasMixins<> *checkNone = new HasMixins<>;
113
114 template<typename Mixins>
115 struct BrokenMixins : public Mixins... { }; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
116
117 // In a mem-initializer-list (12.6.2); the pattern is a mem-initializer.
118 template<typename ...Mixins>
HasMixins()119 HasMixins<Mixins...>::HasMixins(): Mixins()... { }
120
121 template<typename ...Mixins>
HasMixins(const HasMixins & other)122 HasMixins<Mixins...>::HasMixins(const HasMixins &other): Mixins(other)... { }
123
124 template<typename ...Mixins>
HasMixins(int i)125 HasMixins<Mixins...>::HasMixins(int i): Mixins(i)... { } // expected-error{{no matching constructor for initialization of 'A'}}
126
test_has_mixins()127 void test_has_mixins() {
128 HasMixins<A, B> ab;
129 HasMixins<A, B> ab2 = ab;
130 HasMixins<A, B> ab3(17); // expected-note{{in instantiation of member function 'HasMixins<A, B>::HasMixins' requested here}}
131 }
132
133 template<typename T>
134 struct X {
135 T member;
136
XX137 X() : member()... { } // expected-error{{pack expansion for initialization of member 'member'}}
138 };
139
140 // There was a bug in the delayed parsing code for the
141 // following case.
142 template<typename ...T>
143 struct DelayedParseTest : T...
144 {
145 int a;
DelayedParseTestDelayedParseTest146 DelayedParseTest(T... i) : T{i}..., a{10} {}
147 };
148
149
150 // In a template-argument-list (14.3); the pattern is a template-argument.
151 template<typename ...Types>
152 struct tuple_of_refs {
153 typedef tuple<Types& ...> types;
154 };
155
156 tuple<int&, float&> *t_int_ref_float_ref;
157 tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 = t_int_ref_float_ref;
158
159 template<typename ...Types>
160 struct extract_nested_types {
161 typedef tuple<typename Types::type...> types;
162 };
163
164 tuple<int, float> *t_int_float;
165 extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
166 = t_int_float;
167
168 template<int ...N>
169 struct tuple_of_ints {
170 typedef tuple<int_c<N>...> type;
171 };
172
173 int check_temp_arg_1[is_same<tuple_of_ints<1, 2, 3, 4, 5>::type,
174 tuple<int_c<1>, int_c<2>, int_c<3>, int_c<4>,
175 int_c<5>>>::value? 1 : -1];
176
177 // In a dynamic-exception-specification (15.4); the pattern is a type-id.
178 template<typename ...Types>
179 struct f_with_except {
180 virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
181 };
182
183 struct check_f_with_except_1 : f_with_except<int, float> {
184 virtual void f() throw(int, float);
185 };
186
187 struct check_f_with_except_2 : f_with_except<int, float> {
188 virtual void f() throw(int);
189 };
190
191 struct check_f_with_except_3 : f_with_except<int, float> {
192 virtual void f() throw(int, float, double); // expected-error{{exception specification of overriding function is more lax than base version}}
193 };
194