p3.cpp revision 4a5c15f75f76b95e1c2ceb6fa2737dcadd5f4be1
1// RUN: clang-cc -fsyntax-only -verify %s 2 3template<typename T> struct A { }; 4 5// Top-level cv-qualifiers of P's type are ignored for type deduction. 6template<typename T> A<T> f0(const T); 7 8void test_f0(int i, const int ci) { 9 A<int> a0 = f0(i); 10 A<int> a1 = f0(ci); 11} 12 13// If P is a reference type, the type referred to by P is used for type 14// deduction. 15template<typename T> A<T> f1(T&); 16 17void test_f1(int i, const int ci, volatile int vi) { 18 A<int> a0 = f1(i); 19 A<const int> a1 = f1(ci); 20 A<volatile int> a2 = f1(vi); 21} 22 23template<typename T, unsigned N> struct B { }; 24template<typename T, unsigned N> B<T, N> g0(T (&array)[N]); 25 26void test_g0() { 27 int array0[5]; 28 B<int, 5> b0 = g0(array0); 29 const int array1[] = { 1, 2, 3}; 30 B<const int, 3> b1 = g0(array1); 31} 32 33template<typename T> B<T, 0> g1(const A<T>&); 34 35void test_g1(A<float> af) { 36 B<float, 0> b0 = g1(af); 37 B<int, 0> b1 = g1(A<int>()); 38} 39 40// - If the original P is a reference type, the deduced A (i.e., the type 41// referred to by the reference) can be more cv-qualified than the 42// transformed A. 43template<typename T> A<T> f2(const T&); 44 45void test_f2(int i, const int ci, volatile int vi) { 46 A<int> a0 = f2(i); 47 A<int> a1 = f2(ci); 48 A<volatile int> a2 = f2(vi); 49} 50 51// - The transformed A can be another pointer or pointer to member type that 52// can be converted to the deduced A via a qualification conversion (4.4). 53template<typename T> A<T> f3(T * * const * const); 54 55void test_f3(int ***ip, volatile int ***vip) { 56 A<int> a0 = f3(ip); 57 A<volatile int> a1 = f3(vip); 58} 59 60// - If P is a class, and P has the form template-id, then A can be a 61// derived class of the deduced A. Likewise, if P is a pointer to a class 62// of the form template-id, A can be a pointer to a derived class pointed 63// to by the deduced A. 64template<typename T, int I> struct C { }; 65 66struct D : public C<int, 1> { }; 67struct E : public D { }; 68struct F : A<float> { }; 69struct G : A<float>, C<int, 1> { }; 70 71template<typename T, int I> 72 C<T, I> *f4a(const C<T, I>&); 73template<typename T, int I> 74 C<T, I> *f4b(C<T, I>); 75template<typename T, int I> 76 C<T, I> *f4c(C<T, I>*); 77int *f4c(...); 78 79void test_f4(D d, E e, F f, G g) { 80 C<int, 1> *ci1a = f4a(d); 81 C<int, 1> *ci2a = f4a(e); 82 C<int, 1> *ci1b = f4b(d); 83 C<int, 1> *ci2b = f4b(e); 84 C<int, 1> *ci1c = f4c(&d); 85 C<int, 1> *ci2c = f4c(&e); 86 C<int, 1> *ci3c = f4c(&g); 87 int *ip1 = f4c(&f); 88} 89