p4.cpp revision f90b27ad077c3339b62befc892382845339f9490
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
41struct A { };
42struct B { };
43struct C { };
44struct D { };
45
46A *checkA = new HasMixins<A, B, C, D>;
47B *checkB = new HasMixins<A, B, C, D>;
48D *checkD = new HasMixins<A, B, C, D>;
49C *checkC = new HasMixins<A, B, D>; // expected-error{{cannot initialize a variable of type 'C *' with an rvalue of type 'HasMixins<A, B, D> *'}}
50HasMixins<> *checkNone = new HasMixins<>;
51
52template<typename Mixins>
53struct BrokenMixins : public Mixins... { }; // expected-error{{pack expansion does not contain any unexpanded parameter packs}}
54
55// In a template-argument-list (14.3); the pattern is a template-argument.
56template<typename ...Types>
57struct tuple_of_refs {
58  typedef tuple<Types& ...> types;
59};
60
61tuple<int&, float&> *t_int_ref_float_ref;
62tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 =  t_int_ref_float_ref;
63
64template<typename ...Types>
65struct extract_nested_types {
66  typedef tuple<typename Types::type...> types;
67};
68
69tuple<int, float> *t_int_float;
70extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
71  = t_int_float;
72
73template<int ...N>
74struct tuple_of_ints {
75  typedef tuple<int_c<N>...> type;
76};
77
78int check_temp_arg_1[is_same<tuple_of_ints<1, 2, 3, 4, 5>::type,
79                             tuple<int_c<1>, int_c<2>, int_c<3>, int_c<4>,
80                                   int_c<5>>>::value? 1 : -1];
81
82// In a dynamic-exception-specification (15.4); the pattern is a type-id.
83template<typename ...Types>
84struct f_with_except {
85  virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
86};
87
88struct check_f_with_except_1 : f_with_except<int, float> {
89  virtual void f() throw(int, float);
90};
91
92struct check_f_with_except_2 : f_with_except<int, float> {
93  virtual void f() throw(int);
94};
95
96struct check_f_with_except_3 : f_with_except<int, float> {
97  virtual void f() throw(int, float, double); // expected-error{{exception specification of overriding function is more lax than base version}}
98};
99