1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fexceptions -fcxx-exceptions -verify %s
2
3template<typename... Types> struct tuple;
4template<int I> struct int_c;
5
6template<typename T>
7struct identity {
8  typedef T type;
9};
10
11template<typename T, typename U>
12struct is_same {
13  static const bool value = false;
14};
15
16template<typename T>
17struct 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.
25namespace PR11850 {
26  template<typename ...T> struct S {
27    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}
60namespace PR12096 {
61  void Foo(int) {}
62  void Foo(int, int) = delete;
63  template<typename ...Args> struct Var {
64    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.
72void five_args(int, int, int, int, int); // expected-note{{candidate function not viable: requires 5 arguments, but 6 were provided}}
73
74template<int ...Values>
75void 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
80template void initializer_list_expansion<1, 2, 3, 4, 5>();
81template 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
83namespace PR8977 {
84  struct A { };
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.
94template<typename ...Mixins>
95struct HasMixins : public Mixins... {
96  HasMixins();
97  HasMixins(const HasMixins&);
98  HasMixins(int i);
99};
100
101struct 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}}
104struct B { };
105struct C { };
106struct D { };
107
108A *checkA = new HasMixins<A, B, C, D>;
109B *checkB = new HasMixins<A, B, C, D>;
110D *checkD = new HasMixins<A, B, C, D>;
111C *checkC = new HasMixins<A, B, D>; // expected-error{{cannot initialize a variable of type 'C *' with an rvalue of type 'HasMixins<A, B, D> *'}}
112HasMixins<> *checkNone = new HasMixins<>;
113
114template<typename Mixins>
115struct 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.
118template<typename ...Mixins>
119HasMixins<Mixins...>::HasMixins(): Mixins()... { }
120
121template<typename ...Mixins>
122HasMixins<Mixins...>::HasMixins(const HasMixins &other): Mixins(other)... { }
123
124template<typename ...Mixins>
125HasMixins<Mixins...>::HasMixins(int i): Mixins(i)... { } // expected-error{{no matching constructor for initialization of 'A'}}
126
127void 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
133template<typename T>
134struct X {
135  T member;
136
137  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.
142template<typename ...T>
143struct DelayedParseTest : T...
144{
145  int a;
146  DelayedParseTest(T... i) : T{i}..., a{10} {}
147};
148
149
150// In a template-argument-list (14.3); the pattern is a template-argument.
151template<typename ...Types>
152struct tuple_of_refs {
153  typedef tuple<Types& ...> types;
154};
155
156tuple<int&, float&> *t_int_ref_float_ref;
157tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 =  t_int_ref_float_ref;
158
159template<typename ...Types>
160struct extract_nested_types {
161  typedef tuple<typename Types::type...> types;
162};
163
164tuple<int, float> *t_int_float;
165extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
166  = t_int_float;
167
168template<int ...N>
169struct tuple_of_ints {
170  typedef tuple<int_c<N>...> type;
171};
172
173int 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.
178template<typename ...Types>
179struct f_with_except {
180  virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
181};
182
183struct check_f_with_except_1 : f_with_except<int, float> {
184  virtual void f() throw(int, float);
185};
186
187struct check_f_with_except_2 : f_with_except<int, float> {
188  virtual void f() throw(int);
189};
190
191struct 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