p4.cpp revision 3fb9e4b89f72823f162096086f0f964e6dcf66d6
1// RUN: %clang_cc1 -std=c++0x -fsyntax-only -fexceptions -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: Many more bullets to go
22
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.
26void five_args(int, int, int, int, int); // expected-note{{candidate function not viable: requires 5 arguments, but 6 were provided}}
27
28template<int ...Values>
29void 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'}}
32}
33
34template void initializer_list_expansion<1, 2, 3, 4, 5>();
35template 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}}
36
37// In a base-specifier-list (Clause 10); the pattern is a base-specifier.
38template<typename ...Mixins>
39struct HasMixins : public Mixins... {
40  HasMixins();
41  HasMixins(const HasMixins&);
42  HasMixins(int i);
43};
44
45struct A { }; // expected-note{{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}} \
46// expected-note{{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
47struct B { };
48struct C { };
49struct D { };
50
51A *checkA = new HasMixins<A, B, C, D>;
52B *checkB = new HasMixins<A, B, C, D>;
53D *checkD = new HasMixins<A, B, C, D>;
54C *checkC = new HasMixins<A, B, D>; // expected-error{{cannot initialize a variable of type 'C *' with an rvalue of type 'HasMixins<A, B, D> *'}}
55HasMixins<> *checkNone = new HasMixins<>;
56
57template<typename Mixins>
58struct BrokenMixins : public Mixins... { }; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
59
60// In a mem-initializer-list (12.6.2); the pattern is a mem-initializer.
61template<typename ...Mixins>
62HasMixins<Mixins...>::HasMixins(): Mixins()... { }
63
64template<typename ...Mixins>
65HasMixins<Mixins...>::HasMixins(const HasMixins &other): Mixins(other)... { }
66
67template<typename ...Mixins>
68HasMixins<Mixins...>::HasMixins(int i): Mixins(i)... { } // expected-error{{no matching constructor for initialization of 'A'}}
69
70void test_has_mixins() {
71  HasMixins<A, B> ab;
72  HasMixins<A, B> ab2 = ab;
73  HasMixins<A, B> ab3(17); // expected-note{{in instantiation of member function 'HasMixins<A, B>::HasMixins' requested here}}
74}
75
76template<typename T>
77struct X {
78  T member;
79
80  X() : member()... { } // expected-error{{pack expansion for initialization of member 'member'}}
81};
82
83// In a template-argument-list (14.3); the pattern is a template-argument.
84template<typename ...Types>
85struct tuple_of_refs {
86  typedef tuple<Types& ...> types;
87};
88
89tuple<int&, float&> *t_int_ref_float_ref;
90tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 =  t_int_ref_float_ref;
91
92template<typename ...Types>
93struct extract_nested_types {
94  typedef tuple<typename Types::type...> types;
95};
96
97tuple<int, float> *t_int_float;
98extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
99  = t_int_float;
100
101template<int ...N>
102struct tuple_of_ints {
103  typedef tuple<int_c<N>...> type;
104};
105
106int check_temp_arg_1[is_same<tuple_of_ints<1, 2, 3, 4, 5>::type,
107                             tuple<int_c<1>, int_c<2>, int_c<3>, int_c<4>,
108                                   int_c<5>>>::value? 1 : -1];
109
110// In a dynamic-exception-specification (15.4); the pattern is a type-id.
111template<typename ...Types>
112struct f_with_except {
113  virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
114};
115
116struct check_f_with_except_1 : f_with_except<int, float> {
117  virtual void f() throw(int, float);
118};
119
120struct check_f_with_except_2 : f_with_except<int, float> {
121  virtual void f() throw(int);
122};
123
124struct check_f_with_except_3 : f_with_except<int, float> {
125  virtual void f() throw(int, float, double); // expected-error{{exception specification of overriding function is more lax than base version}}
126};
127