1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 template<typename T
> struct A
{ };
5 // Top-level cv-qualifiers of P's type are ignored for type deduction.
6 template<typename T
> A
<T
> f0(const T
);
8 void test_f0(int i
, const int ci
) {
13 // If P is a reference type, the type referred to by P is used for type
15 template<typename T
> A
<T
> f1(T
&);
17 void test_f1(int i
, const int ci
, volatile int vi
) {
19 A
<const int> a1
= f1(ci
);
20 A
<volatile int> a2
= f1(vi
);
23 template<typename T
, unsigned N
> struct B
{ };
24 template<typename T
, unsigned N
> B
<T
, N
> g0(T (&array
)[N
]);
25 template<typename T
, unsigned N
> B
<T
, N
> g0b(const T (&array
)[N
]);
29 B
<int, 5> b0
= g0(array0
);
30 const int array1
[] = { 1, 2, 3};
31 B
<const int, 3> b1
= g0(array1
);
32 B
<int, 3> b2
= g0b(array1
);
35 template<typename T
> B
<T
, 0> g1(const A
<T
>&);
37 void test_g1(A
<float> af
) {
38 B
<float, 0> b0
= g1(af
);
39 B
<int, 0> b1
= g1(A
<int>());
42 // - If the original P is a reference type, the deduced A (i.e., the type
43 // referred to by the reference) can be more cv-qualified than the
45 template<typename T
> A
<T
> f2(const T
&);
47 void test_f2(int i
, const int ci
, volatile int vi
) {
50 A
<volatile int> a2
= f2(vi
);
54 template <typename T
, int N
>
55 void Foo(const T (&a
)[N
]) {
60 const int a
[1] = { 0 };
66 // - The transformed A can be another pointer or pointer to member type that
67 // can be converted to the deduced A via a qualification conversion (4.4).
68 template<typename T
> A
<T
> f3(T
* * const * const);
70 void test_f3(int ***ip
, volatile int ***vip
) {
72 A
<volatile int> a1
= f3(vip
);
75 // Also accept conversions for pointer types which require removing
77 namespace noreturn_stripping
{
79 void f(R (*function
)());
81 void g() __attribute__ ((__noreturn__
));
89 // - If P is a class, and P has the form template-id, then A can be a
90 // derived class of the deduced A. Likewise, if P is a pointer to a class
91 // of the form template-id, A can be a pointer to a derived class pointed
92 // to by the deduced A.
93 template<typename T
, int I
> struct C
{ };
95 struct D
: public C
<int, 1> { };
96 struct E
: public D
{ };
97 struct F
: A
<float> { };
98 struct G
: A
<float>, C
<int, 1> { };
100 template<typename T
, int I
>
101 C
<T
, I
> *f4a(const C
<T
, I
>&);
102 template<typename T
, int I
>
103 C
<T
, I
> *f4b(C
<T
, I
>);
104 template<typename T
, int I
>
105 C
<T
, I
> *f4c(C
<T
, I
>*);
108 void test_f4(D d
, E e
, F f
, G g
) {
109 C
<int, 1> *ci1a
= f4a(d
);
110 C
<int, 1> *ci2a
= f4a(e
);
111 C
<int, 1> *ci1b
= f4b(d
);
112 C
<int, 1> *ci2b
= f4b(e
);
113 C
<int, 1> *ci1c
= f4c(&d
);
114 C
<int, 1> *ci2c
= f4c(&e
);
115 C
<int, 1> *ci3c
= f4c(&g
);
124 template<typename X
, typename Y
> struct B
{};
126 struct J
: B
<T0
,T0
> {};
127 struct K
: B
<T1
,T1
> {};
131 template<typename X
, typename Y
> void F(B
<Y
,X
>);
136 N::F
<T0
>(d
); // Fails
142 template<typename T
> void f(const T
**q
); // expected-note{{candidate template ignored: deduced type 'const int **' of 1st parameter does not match adjusted type 'int **' of argument [with T = int]}}
145 f(p
); // expected-error{{no matching function for call to 'f'}}
154 template<class T
, int i
> struct D
: T
{};
155 template<class T
> void Foo(D
<T
, 1>);
166 template<int N
> struct B
{};
167 struct D
: B
<0>, B
<1> {};
169 template<int N
> int callee(B
<N
>); // expected-note{{failed template argument deduction}}
172 callee(D()); // expected-error{{no matching function}}