partial-ordering.cpp revision 9da95e6eefc4b0ca25e18bdab1b703f5c185deab
1// RUN: %clang_cc1 -std=c++0x -fsyntax-only -verify %s 2 3// Various tests related to partial ordering of variadic templates. 4template<typename ...Types> struct tuple; 5 6template<typename Tuple> 7struct X1 { 8 static const unsigned value = 0; 9}; 10 11template<typename Head, typename ...Tail> 12struct X1<tuple<Head, Tail...> > { 13 static const unsigned value = 1; 14}; 15 16template<typename Head, typename ...Tail> 17struct X1<tuple<Head, Tail&...> > { 18 static const unsigned value = 2; 19}; 20 21template<typename Head, typename ...Tail> 22struct X1<tuple<Head&, Tail&...> > { 23 static const unsigned value = 3; 24}; 25 26int check0[X1<tuple<>>::value == 0? 1 : -1]; 27int check1[X1<tuple<int>>::value == 2? 1 : -1]; 28int check2[X1<tuple<int, int>>::value == 1? 1 : -1]; 29int check3[X1<tuple<int, int&>>::value == 2? 1 : -1]; 30int check4[X1<tuple<int&, int&>>::value == 3? 1 : -1]; 31 32// Partial ordering of function templates. 33template<typename T1, typename T2, typename ...Rest> 34int &f0(T1, T2, Rest...); 35 36template<typename T1, typename T2> 37float &f0(T1, T2); 38 39void test_f0() { 40 int &ir1 = f0(1, 2.0, 'a'); 41 float &fr1 = f0(1, 2.0); 42} 43 44template<typename T1, typename T2, typename ...Rest> 45int &f1(T1, T2, Rest...); 46 47template<typename T1, typename T2> 48float &f1(T1, T2, ...); 49 50void test_f1() { 51 int &ir1 = f1(1, 2.0, 'a'); 52} 53 54template<typename T1, typename T2, typename ...Rest> 55int &f2(T1, T2, Rest...); 56 57float &f2(...); 58 59void test_f2() { 60 int &ir1 = f2(1, 2.0, 'a'); 61} 62