Home | History | Annotate | Download | only in temp.deduct.call
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 template<typename T> struct A { };
      4 
      5 // Top-level cv-qualifiers of P's type are ignored for type deduction.
      6 template<typename T> A<T> f0(const T);
      7 
      8 void 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.
     15 template<typename T> A<T> f1(T&);
     16 
     17 void 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 
     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]);
     26 
     27 void 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 
     35 template<typename T> B<T, 0> g1(const A<T>&);
     36 
     37 void 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.
     45 template<typename T> A<T> f2(const T&);
     46 
     47 void 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
     54 template <typename T, int N>
     55 void Foo(const T (&a)[N]) {
     56   T x;
     57   x = 0;
     58 }
     59 
     60 const int a[1] = { 0 };
     61 
     62 void 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).
     68 template<typename T> A<T> f3(T * * const * const);
     69 
     70 void test_f3(int ***ip, volatile int ***vip) {
     71   A<int> a0 = f3(ip);
     72   A<volatile int> a1 = f3(vip);
     73 }
     74 
     75 // Also accept conversions for pointer types which require removing
     76 // [[noreturn]].
     77 namespace noreturn_stripping {
     78   template <class R>
     79   void f(R (*function)());
     80 
     81   void g() __attribute__ ((__noreturn__));
     82   void h();
     83   void test() {
     84     f(g);
     85     f(h);
     86   }
     87 }
     88 
     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 { };
     94 
     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> { };
     99 
    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>*);
    106 int *f4c(...);
    107 
    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);
    116   int       *ip1 = f4c(&f);
    117 }
    118 
    119 // PR8462
    120 namespace N {
    121   struct T0;
    122   struct T1;
    123 
    124   template<typename X, typename Y> struct B {};
    125 
    126   struct J : B<T0,T0> {};
    127   struct K : B<T1,T1> {};
    128 
    129   struct D : J, K {};
    130 
    131   template<typename X, typename Y> void F(B<Y,X>);
    132 
    133   void test()
    134   {
    135     D d;
    136     N::F<T0>(d); // Fails
    137     N::F<T1>(d); // OK
    138   }
    139 }
    140 
    141 namespace PR9233 {
    142   template<typename T> void f(const T **q); // expected-note{{candidate template ignored: substitution failure [with T = int]}}
    143 
    144   void g(int **p) {
    145     f(p); // expected-error{{no matching function for call to 'f'}}
    146   }
    147 
    148 }
    149