blob: f0ce0d3cc669d3e2f47232fa909ef9473b400889 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregor99ebf652009-02-27 19:31:52 +00002template<typename T, typename U = const T> struct Def1;
3
4template<> struct Def1<int> {
5 void foo();
6};
7
8template<> struct Def1<const int> { // expected-note{{previous definition is here}}
9 void bar();
10};
11
Douglas Gregorcd281c32009-02-28 00:25:32 +000012template<> struct Def1<int&> {
13 void wibble();
14};
15
16void test_Def1(Def1<int, const int> *d1, Def1<const int, const int> *d2,
17 Def1<int&, int&> *d3) {
Douglas Gregor99ebf652009-02-27 19:31:52 +000018 d1->foo();
19 d2->bar();
Douglas Gregorcd281c32009-02-28 00:25:32 +000020 d3->wibble();
Douglas Gregor99ebf652009-02-27 19:31:52 +000021}
22
Douglas Gregorcd281c32009-02-28 00:25:32 +000023template<typename T, // FIXME: bad error message below, needs better location info
24 typename T2 = const T*> // expected-error{{'T2' declared as a pointer to a reference}}
25 struct Def2;
26
27template<> struct Def2<int> {
28 void foo();
29};
30
31void test_Def2(Def2<int, int const*> *d2) {
32 d2->foo();
33}
34
Douglas Gregordf667e72009-03-10 20:44:00 +000035typedef int& int_ref_t;
36Def2<int_ref_t> *d2; // expected-note{{in instantiation of default argument for 'Def2<int &>' required here}}
Douglas Gregorcd281c32009-02-28 00:25:32 +000037
38
Douglas Gregorc8ab2562009-05-31 09:31:02 +000039template<> struct Def1<const int, const int> { }; // expected-error{{redefinition of 'Def1<int const>'}}
Douglas Gregor99ebf652009-02-27 19:31:52 +000040
Douglas Gregorcd281c32009-02-28 00:25:32 +000041template<typename T, typename T2 = T&> struct Def3;
42
43template<> struct Def3<int> {
44 void foo();
45};
46
47template<> struct Def3<int&> {
48 void bar();
49};
50
51void test_Def3(Def3<int, int&> *d3a, Def3<int&, int&> *d3b) {
52 d3a->foo();
53 d3b->bar();
54}
55
56
57template<typename T, typename T2 = T[]> struct Def4;
58
59template<> struct Def4<int> {
60 void foo();
61};
62
63void test_Def4(Def4<int, int[]> *d4a) {
64 d4a->foo();
65}
66
67template<typename T, typename T2 = T const[12]> struct Def5;
68
69template<> struct Def5<int> {
70 void foo();
71};
72
73template<> struct Def5<int, int const[13]> {
74 void bar();
75};
76
77void test_Def5(Def5<int, const int[12]> *d5a, Def5<int, const int[13]> *d5b) {
78 d5a->foo();
79 d5b->bar();
80}
81
Douglas Gregor724651c2009-02-28 01:04:19 +000082template<typename R, typename Arg1, typename Arg2 = Arg1,
83 typename FuncType = R (*)(Arg1, Arg2)>
84 struct Def6;
85
86template<> struct Def6<int, float> {
87 void foo();
88};
89
90template<> struct Def6<bool, int[5], float(double, double)> {
91 void bar();
92};
93
94bool test_Def6(Def6<int, float, float> *d6a,
95 Def6<int, float, float, int (*)(float, float)> *d6b,
96 Def6<bool, int[5], float(double, double),
97 bool(*)(int*, float(*)(double, double))> *d6c) {
98 d6a->foo();
99 d6b->foo();
100 d6c->bar();
101 return d6a == d6b;
102}