[AMDGPU] Update base addr of dyn alloca considering GrowingUp stack (#119822)
[llvm-project.git] / clang / test / CXX / temp / temp.fct.spec / temp.deduct / temp.deduct.call / p3.cpp
blobff8178f94769164d3e45e9d602f6f4a422830d86
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) {
9 A<int> a0 = f0(i);
10 A<int> a1 = f0(ci);
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&);
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);
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]);
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);
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
44 // transformed A.
45 template<typename T> A<T> f2(const T&);
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);
53 // PR5913
54 template <typename T, int N>
55 void Foo(const T (&a)[N]) {
56 T x;
57 x = 0;
60 const int a[1] = { 0 };
62 void Test() {
63 Foo(a);
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) {
71 A<int> a0 = f3(ip);
72 A<volatile int> a1 = f3(vip);
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)());
81 void g() __attribute__ ((__noreturn__));
82 void h();
83 void test() {
84 f(g);
85 f(h);
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>*);
106 int *f4c(...);
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);
119 // PR8462
120 namespace N {
121 struct T0;
122 struct T1;
124 template<typename X, typename Y> struct B {};
126 struct J : B<T0,T0> {};
127 struct K : B<T1,T1> {};
129 struct D : J, K {};
131 template<typename X, typename Y> void F(B<Y,X>);
133 void test()
135 D d;
136 N::F<T0>(d); // Fails
137 N::F<T1>(d); // OK
141 namespace PR9233 {
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]}}
144 void g(int **p) {
145 f(p); // expected-error{{no matching function for call to 'f'}}
150 namespace PR27155 {
152 struct B {};
154 template<class T, int i> struct D : T {};
155 template<class T> void Foo(D<T, 1>);
157 int fn() {
158 D<D<B, 1>, 0> f;
159 Foo(f);
164 namespace PR28195 {
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}}
171 int caller() {
172 callee(D()); // expected-error{{no matching function}}