p3.cpp revision 21714013498fd84a6e8d5ceb1af5d14b6531cfb5
1// RUN: %clang_cc1 -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]); 25template<typename T, unsigned N> B<T, N> g0b(const T (&array)[N]); 26 27void test_g0() { 28 int array0[5]; 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); 33} 34 35template<typename T> B<T, 0> g1(const A<T>&); 36 37void test_g1(A<float> af) { 38 B<float, 0> b0 = g1(af); 39 B<int, 0> b1 = g1(A<int>()); 40} 41 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 44// transformed A. 45template<typename T> A<T> f2(const T&); 46 47void test_f2(int i, const int ci, volatile int vi) { 48 A<int> a0 = f2(i); 49 A<int> a1 = f2(ci); 50 A<volatile int> a2 = f2(vi); 51} 52 53// PR5913 54template <typename T, int N> 55void Foo(const T (&a)[N]) { 56 T x; 57 x = 0; 58} 59 60const int a[1] = { 0 }; 61 62void Test() { 63 Foo(a); 64} 65 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). 68template<typename T> A<T> f3(T * * const * const); 69 70void test_f3(int ***ip, volatile int ***vip) { 71 A<int> a0 = f3(ip); 72 A<volatile int> a1 = f3(vip); 73} 74 75// - If P is a class, and P has the form template-id, then A can be a 76// derived class of the deduced A. Likewise, if P is a pointer to a class 77// of the form template-id, A can be a pointer to a derived class pointed 78// to by the deduced A. 79template<typename T, int I> struct C { }; 80 81struct D : public C<int, 1> { }; 82struct E : public D { }; 83struct F : A<float> { }; 84struct G : A<float>, C<int, 1> { }; 85 86template<typename T, int I> 87 C<T, I> *f4a(const C<T, I>&); 88template<typename T, int I> 89 C<T, I> *f4b(C<T, I>); 90template<typename T, int I> 91 C<T, I> *f4c(C<T, I>*); 92int *f4c(...); 93 94void test_f4(D d, E e, F f, G g) { 95 C<int, 1> *ci1a = f4a(d); 96 C<int, 1> *ci2a = f4a(e); 97 C<int, 1> *ci1b = f4b(d); 98 C<int, 1> *ci2b = f4b(e); 99 C<int, 1> *ci1c = f4c(&d); 100 C<int, 1> *ci2c = f4c(&e); 101 C<int, 1> *ci3c = f4c(&g); 102 int *ip1 = f4c(&f); 103} 104