1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc template<typename T, typename U = const T> struct Def1;
3*f4a2713aSLionel Sambuc
4*f4a2713aSLionel Sambuc template<> struct Def1<int> {
5*f4a2713aSLionel Sambuc void foo();
6*f4a2713aSLionel Sambuc };
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel Sambuc template<> struct Def1<const int> { // expected-note{{previous definition is here}}
9*f4a2713aSLionel Sambuc void bar();
10*f4a2713aSLionel Sambuc };
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc template<> struct Def1<int&> {
13*f4a2713aSLionel Sambuc void wibble();
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc
test_Def1(Def1<int,const int> * d1,Def1<const int,const int> * d2,Def1<int &,int &> * d3)16*f4a2713aSLionel Sambuc void test_Def1(Def1<int, const int> *d1, Def1<const int, const int> *d2,
17*f4a2713aSLionel Sambuc Def1<int&, int&> *d3) {
18*f4a2713aSLionel Sambuc d1->foo();
19*f4a2713aSLionel Sambuc d2->bar();
20*f4a2713aSLionel Sambuc d3->wibble();
21*f4a2713aSLionel Sambuc }
22*f4a2713aSLionel Sambuc
23*f4a2713aSLionel Sambuc template<typename T, // FIXME: bad error message below, needs better location info
24*f4a2713aSLionel Sambuc typename T2 = const T*> // expected-error{{'T2' declared as a pointer to a reference}}
25*f4a2713aSLionel Sambuc struct Def2;
26*f4a2713aSLionel Sambuc
27*f4a2713aSLionel Sambuc template<> struct Def2<int> {
28*f4a2713aSLionel Sambuc void foo();
29*f4a2713aSLionel Sambuc };
30*f4a2713aSLionel Sambuc
test_Def2(Def2<int,int const * > * d2)31*f4a2713aSLionel Sambuc void test_Def2(Def2<int, int const*> *d2) {
32*f4a2713aSLionel Sambuc d2->foo();
33*f4a2713aSLionel Sambuc }
34*f4a2713aSLionel Sambuc
35*f4a2713aSLionel Sambuc typedef int& int_ref_t;
36*f4a2713aSLionel Sambuc Def2<int_ref_t> *d2; // expected-note{{in instantiation of default argument for 'Def2<int &>' required here}}
37*f4a2713aSLionel Sambuc
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel Sambuc template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<const int>'}}
40*f4a2713aSLionel Sambuc
41*f4a2713aSLionel Sambuc template<typename T, typename T2 = T&> struct Def3;
42*f4a2713aSLionel Sambuc
43*f4a2713aSLionel Sambuc template<> struct Def3<int> {
44*f4a2713aSLionel Sambuc void foo();
45*f4a2713aSLionel Sambuc };
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc template<> struct Def3<int&> {
48*f4a2713aSLionel Sambuc void bar();
49*f4a2713aSLionel Sambuc };
50*f4a2713aSLionel Sambuc
test_Def3(Def3<int,int &> * d3a,Def3<int &,int &> * d3b)51*f4a2713aSLionel Sambuc void test_Def3(Def3<int, int&> *d3a, Def3<int&, int&> *d3b) {
52*f4a2713aSLionel Sambuc d3a->foo();
53*f4a2713aSLionel Sambuc d3b->bar();
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc template<typename T, typename T2 = T[]> struct Def4;
58*f4a2713aSLionel Sambuc
59*f4a2713aSLionel Sambuc template<> struct Def4<int> {
60*f4a2713aSLionel Sambuc void foo();
61*f4a2713aSLionel Sambuc };
62*f4a2713aSLionel Sambuc
test_Def4(Def4<int,int[]> * d4a)63*f4a2713aSLionel Sambuc void test_Def4(Def4<int, int[]> *d4a) {
64*f4a2713aSLionel Sambuc d4a->foo();
65*f4a2713aSLionel Sambuc }
66*f4a2713aSLionel Sambuc
67*f4a2713aSLionel Sambuc template<typename T, typename T2 = T const[12]> struct Def5;
68*f4a2713aSLionel Sambuc
69*f4a2713aSLionel Sambuc template<> struct Def5<int> {
70*f4a2713aSLionel Sambuc void foo();
71*f4a2713aSLionel Sambuc };
72*f4a2713aSLionel Sambuc
73*f4a2713aSLionel Sambuc template<> struct Def5<int, int const[13]> {
74*f4a2713aSLionel Sambuc void bar();
75*f4a2713aSLionel Sambuc };
76*f4a2713aSLionel Sambuc
test_Def5(Def5<int,const int[12]> * d5a,Def5<int,const int[13]> * d5b)77*f4a2713aSLionel Sambuc void test_Def5(Def5<int, const int[12]> *d5a, Def5<int, const int[13]> *d5b) {
78*f4a2713aSLionel Sambuc d5a->foo();
79*f4a2713aSLionel Sambuc d5b->bar();
80*f4a2713aSLionel Sambuc }
81*f4a2713aSLionel Sambuc
82*f4a2713aSLionel Sambuc template<typename R, typename Arg1, typename Arg2 = Arg1,
83*f4a2713aSLionel Sambuc typename FuncType = R (*)(Arg1, Arg2)>
84*f4a2713aSLionel Sambuc struct Def6;
85*f4a2713aSLionel Sambuc
86*f4a2713aSLionel Sambuc template<> struct Def6<int, float> {
87*f4a2713aSLionel Sambuc void foo();
88*f4a2713aSLionel Sambuc };
89*f4a2713aSLionel Sambuc
90*f4a2713aSLionel Sambuc template<> struct Def6<bool, int[5], float(double, double)> {
91*f4a2713aSLionel Sambuc void bar();
92*f4a2713aSLionel Sambuc };
93*f4a2713aSLionel Sambuc
test_Def6(Def6<int,float,float> * d6a,Def6<int,float,float,int (*)(float,float)> * d6b,Def6<bool,int[5],float (double,double),bool (*)(int *,float (*)(double,double))> * d6c)94*f4a2713aSLionel Sambuc bool test_Def6(Def6<int, float, float> *d6a,
95*f4a2713aSLionel Sambuc Def6<int, float, float, int (*)(float, float)> *d6b,
96*f4a2713aSLionel Sambuc Def6<bool, int[5], float(double, double),
97*f4a2713aSLionel Sambuc bool(*)(int*, float(*)(double, double))> *d6c) {
98*f4a2713aSLionel Sambuc d6a->foo();
99*f4a2713aSLionel Sambuc d6b->foo();
100*f4a2713aSLionel Sambuc d6c->bar();
101*f4a2713aSLionel Sambuc return d6a == d6b;
102*f4a2713aSLionel Sambuc }
103