p4.cpp revision dcaa1ca0b475dfa887e1d061678a1e3501288510
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 template-argument-list (14.3); the pattern is a template-argument.
38template<typename ...Types>
39struct tuple_of_refs {
40  typedef tuple<Types& ...> types;
41};
42
43tuple<int&, float&> *t_int_ref_float_ref;
44tuple_of_refs<int&, float&>::types *t_int_ref_float_ref_2 =  t_int_ref_float_ref;
45
46template<typename ...Types>
47struct extract_nested_types {
48  typedef tuple<typename Types::type...> types;
49};
50
51tuple<int, float> *t_int_float;
52extract_nested_types<identity<int>, identity<float> >::types *t_int_float_2
53  = t_int_float;
54
55template<int ...N>
56struct tuple_of_ints {
57  typedef tuple<int_c<N>...> type;
58};
59
60int 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];
63
64// In a dynamic-exception-specification (15.4); the pattern is a type-id.
65template<typename ...Types>
66struct f_with_except {
67  virtual void f() throw(Types...); // expected-note{{overridden virtual function is here}}
68};
69
70struct check_f_with_except_1 : f_with_except<int, float> {
71  virtual void f() throw(int, float);
72};
73
74struct check_f_with_except_2 : f_with_except<int, float> {
75  virtual void f() throw(int);
76};
77
78struct 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}}
80};
81