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