Clang Project

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