221
|
1 // RUN: %clang_cc1 -std=c++2a -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace
|
|
2
|
|
3 template<auto ...> struct X {};
|
|
4 template<template<typename X, X> typename> struct Y {};
|
|
5 template<typename ...> struct Z {};
|
|
6
|
|
7 template<typename T, typename ...Ts> struct A {
|
|
8 template<Ts ...Ns, T *...Ps> A(X<Ps...>, Ts (*...qs)[Ns]);
|
|
9 };
|
|
10 int arr1[3], arr2[3];
|
|
11 short arr3[4];
|
|
12 A a(X<&arr1, &arr2>{}, &arr1, &arr2, &arr3);
|
|
13 using AT = decltype(a);
|
|
14 using AT = A<int[3], int, int, short>;
|
|
15
|
|
16 // CHECK-LABEL: Dumping <deduction guide for A>:
|
|
17 // CHECK: FunctionTemplateDecl
|
|
18 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
|
|
19 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 ... Ts
|
|
20 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'Ts...' depth 0 index 2 ... Ns
|
|
21 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'T *' depth 0 index 3 ... Ps
|
|
22 // CHECK: |-CXXDeductionGuideDecl
|
|
23 // CHECK: | |-ParmVarDecl {{.*}} 'X<Ps...>'
|
|
24 // CHECK: | `-ParmVarDecl {{.*}} 'Ts (*)[Ns]...' pack
|
|
25 // CHECK: `-CXXDeductionGuideDecl
|
|
26 // CHECK: |-TemplateArgument type 'int [3]'
|
|
27 // CHECK: |-TemplateArgument pack
|
|
28 // CHECK: | |-TemplateArgument type 'int'
|
|
29 // CHECK: | |-TemplateArgument type 'int'
|
|
30 // CHECK: | `-TemplateArgument type 'short'
|
|
31 // CHECK: |-TemplateArgument pack
|
|
32 // CHECK: | |-TemplateArgument integral 3
|
|
33 // CHECK: | |-TemplateArgument integral 3
|
|
34 // CHECK: | `-TemplateArgument integral 4
|
|
35 // CHECK: |-TemplateArgument pack
|
|
36 // CHECK: | |-TemplateArgument decl
|
|
37 // CHECK: | | `-Var {{.*}} 'arr1' 'int [3]'
|
|
38 // CHECK: | `-TemplateArgument decl
|
|
39 // CHECK: | `-Var {{.*}} 'arr2' 'int [3]'
|
|
40 // CHECK: |-ParmVarDecl {{.*}} 'X<&arr1, &arr2>':'X<&arr1, &arr2>'
|
|
41 // CHECK: |-ParmVarDecl {{.*}} 'int (*)[3]'
|
|
42 // CHECK: |-ParmVarDecl {{.*}} 'int (*)[3]'
|
|
43 // CHECK: `-ParmVarDecl {{.*}} 'short (*)[4]'
|
|
44 // CHECK: FunctionProtoType {{.*}} 'auto (X<Ps...>, Ts (*)[Ns]...) -> A<T, Ts...>' dependent trailing_return
|
|
45 // CHECK: |-InjectedClassNameType {{.*}} 'A<T, Ts...>' dependent
|
|
46 // CHECK: |-TemplateSpecializationType {{.*}} 'X<Ps...>' dependent X
|
|
47 // CHECK: | `-TemplateArgument expr
|
|
48 // CHECK: | `-PackExpansionExpr {{.*}} 'T *'
|
|
49 // CHECK: | `-DeclRefExpr {{.*}} 'T *' NonTypeTemplateParm {{.*}} 'Ps' 'T *'
|
|
50 // CHECK: `-PackExpansionType {{.*}} 'Ts (*)[Ns]...' dependent
|
|
51 // CHECK: `-PointerType {{.*}} 'Ts (*)[Ns]' dependent contains_unexpanded_pack
|
|
52 // CHECK: `-ParenType {{.*}} 'Ts [Ns]' sugar dependent contains_unexpanded_pack
|
|
53 // CHECK: `-DependentSizedArrayType {{.*}} 'Ts [Ns]' dependent contains_unexpanded_pack
|
|
54 // CHECK: |-TemplateTypeParmType {{.*}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
|
|
55 // CHECK: | `-TemplateTypeParm {{.*}} 'Ts'
|
|
56 // CHECK: `-DeclRefExpr {{.*}} 'Ts' NonTypeTemplateParm {{.*}} 'Ns' 'Ts...'
|
|
57
|
|
58 template<typename T, T V> struct B {
|
|
59 template<typename U, U W> B(X<W, V>);
|
|
60 };
|
|
61 B b(X<nullptr, 'x'>{});
|
|
62 using BT = decltype(b);
|
|
63 using BT = B<char, 'x'>;
|
|
64
|
|
65 // CHECK-LABEL: Dumping <deduction guide for B>:
|
|
66 // CHECK: FunctionTemplateDecl
|
|
67 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
|
|
68 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'T' depth 0 index 1 V
|
|
69 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U
|
|
70 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'type-parameter-0-2' depth 0 index 3 W
|
|
71 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (X<W, V>) -> B<T, V>'
|
|
72 // CHECK: | `-ParmVarDecl {{.*}} 'X<W, V>'
|
|
73 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (X<nullptr, 'x'>) -> B<char, 'x'>'
|
|
74 // CHECK: |-TemplateArgument type 'char'
|
|
75 // CHECK: |-TemplateArgument integral 120
|
|
76 // CHECK: |-TemplateArgument type 'nullptr_t'
|
|
77 // CHECK: |-TemplateArgument nullptr
|
|
78 // CHECK: `-ParmVarDecl {{.*}} 'X<nullptr, 'x'>':'X<nullptr, 'x'>'
|
|
79 // CHECK: FunctionProtoType {{.*}} 'auto (X<W, V>) -> B<T, V>' dependent trailing_return
|
|
80 // CHECK: |-InjectedClassNameType {{.*}} 'B<T, V>' dependent
|
|
81 // CHECK: `-TemplateSpecializationType {{.*}} 'X<W, V>' dependent X
|
|
82 // CHECK: |-TemplateArgument expr
|
|
83 // CHECK: | `-DeclRefExpr {{.*}} 'type-parameter-0-2' NonTypeTemplateParm {{.*}} 'W' 'type-parameter-0-2'
|
|
84 // CHECK: `-TemplateArgument expr
|
|
85 // CHECK: `-DeclRefExpr {{.*}} 'T' NonTypeTemplateParm {{.*}} 'V' 'T'
|
|
86
|
|
87 template<typename A> struct C {
|
|
88 template<template<typename X, X> typename T, typename U, U V = 0> C(A, Y<T>, U);
|
|
89 };
|
|
90 C c(1, Y<B>{}, 2);
|
|
91 using CT = decltype(c);
|
|
92 using CT = C<int>;
|
|
93
|
|
94 // CHECK-LABEL: Dumping <deduction guide for C>:
|
|
95 // CHECK: FunctionTemplateDecl
|
|
96 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 A
|
|
97 // CHECK: |-TemplateTemplateParmDecl {{.*}} depth 0 index 1 T
|
|
98 // CHECK: | |-TemplateTypeParmDecl {{.*}} typename depth 1 index 0 X
|
|
99 // CHECK: | `-NonTypeTemplateParmDecl {{.*}} 'X' depth 1 index 1
|
|
100 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U
|
|
101 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'type-parameter-0-2' depth 0 index 3 V
|
|
102 // CHECK: | `-TemplateArgument expr
|
|
103 // CHECK: | `-IntegerLiteral {{.*}} 'int' 0
|
|
104 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> C<A>'
|
|
105 // CHECK: | |-ParmVarDecl {{.*}} 'A'
|
|
106 // CHECK: | |-ParmVarDecl {{.*}} 'Y<>'
|
|
107 // CHECK: | `-ParmVarDecl {{.*}} 'type-parameter-0-2'
|
|
108 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int, Y<B>, int) -> C<int>'
|
|
109 // CHECK: |-TemplateArgument type 'int'
|
|
110 // CHECK: |-TemplateArgument template B
|
|
111 // CHECK: |-TemplateArgument type 'int'
|
|
112 // CHECK: |-TemplateArgument integral 0
|
|
113 // CHECK: |-ParmVarDecl {{.*}} 'int':'int'
|
|
114 // CHECK: |-ParmVarDecl {{.*}} 'Y<B>':'Y<B>'
|
|
115 // CHECK: `-ParmVarDecl {{.*}} 'int':'int'
|
|
116 // CHECK: FunctionProtoType {{.*}} 'auto (A, Y<>, type-parameter-0-2) -> C<A>' dependent trailing_return cdecl
|
|
117 // CHECK: |-InjectedClassNameType {{.*}} 'C<A>' dependent
|
|
118 // CHECK: |-TemplateTypeParmType {{.*}} 'A' dependent depth 0 index 0
|
|
119 // CHECK: | `-TemplateTypeParm {{.*}} 'A'
|
|
120 // CHECK: |-TemplateSpecializationType {{.*}} 'Y<>' dependent Y
|
|
121 // CHECK: | `-TemplateArgument template
|
|
122 // CHECK: `-TemplateTypeParmType {{.*}} 'type-parameter-0-2' dependent depth 0 index 2
|
|
123
|
|
124 template<typename ...T> struct D { // expected-note {{candidate}}
|
|
125 template<typename... U> using B = int(int (*...p)(T, U));
|
|
126 template<typename U1, typename U2> D(B<U1, U2>*); // expected-note {{candidate}}
|
|
127 };
|
|
128 int f(int(int, int), int(int, int));
|
|
129 // FIXME: We can't deduce this because we can't deduce through a
|
|
130 // SubstTemplateTypeParmPackType.
|
|
131 D d = f; // expected-error {{no viable}}
|
|
132 using DT = decltype(d);
|
|
133 using DT = D<int, int>;
|
|
134
|
|
135 // CHECK-LABEL: Dumping <deduction guide for D>:
|
|
136 // CHECK: FunctionTemplateDecl
|
|
137 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 ... T
|
|
138 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U1
|
|
139 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U2
|
|
140 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<type-parameter-0-1, type-parameter-0-2> *) -> D<T...>'
|
|
141 // CHECK: `-ParmVarDecl {{.*}} 'B<type-parameter-0-1, type-parameter-0-2> *'
|
|
142 // CHECK: FunctionProtoType {{.*}} 'auto (B<type-parameter-0-1, type-parameter-0-2> *) -> D<T...>' dependent trailing_return
|
|
143 // CHECK: |-InjectedClassNameType {{.*}} 'D<T...>' dependent
|
|
144 // CHECK: `-PointerType {{.*}} 'B<type-parameter-0-1, type-parameter-0-2> *' dependent
|
|
145 // CHECK: `-TemplateSpecializationType {{.*}} 'B<type-parameter-0-1, type-parameter-0-2>' sugar dependent alias B
|
|
146 // CHECK: |-TemplateArgument type 'type-parameter-0-1'
|
|
147 // CHECK: |-TemplateArgument type 'type-parameter-0-2'
|
|
148 // CHECK: `-FunctionProtoType {{.*}} 'int (int (*)(T, U)...)' dependent cdecl
|
|
149 // CHECK: |-BuiltinType {{.*}} 'int'
|
|
150 // CHECK: `-PackExpansionType {{.*}} 'int (*)(T, U)...' dependent expansions 2
|
|
151 // CHECK: `-PointerType {{.*}} 'int (*)(T, U)' dependent contains_unexpanded_pack
|
|
152 // CHECK: `-ParenType {{.*}} 'int (T, U)' sugar dependent contains_unexpanded_pack
|
|
153 // CHECK: `-FunctionProtoType {{.*}} 'int (T, U)' dependent contains_unexpanded_pack cdecl
|
|
154 // CHECK: |-BuiltinType {{.*}} 'int'
|
|
155 // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
|
|
156 // CHECK: | `-TemplateTypeParm {{.*}} 'T'
|
|
157 // CHECK: `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack
|
|
158 // CHECK: |-TemplateTypeParmType {{.*}} 'U' dependent contains_unexpanded_pack depth 1 index 0 pack
|
|
159 // CHECK: | `-TemplateTypeParm {{.*}} 'U'
|
|
160 // CHECK: `-TemplateArgument pack
|
|
161 // CHECK: |-TemplateArgument type 'type-parameter-0-1'
|
|
162 // CHECK-NOT: Subst
|
|
163 // CHECK: | `-TemplateTypeParmType
|
|
164 // CHECK: `-TemplateArgument type 'type-parameter-0-2'
|
|
165 // CHECK-NOT: Subst
|
|
166 // CHECK: `-TemplateTypeParmType
|
|
167
|
|
168 template<int ...N> struct E { // expected-note {{candidate}}
|
|
169 template<int ...M> using B = Z<X<N, M>...>;
|
|
170 template<int M1, int M2> E(B<M1, M2>); // expected-note {{candidate}}
|
|
171 };
|
|
172 // FIXME: We can't deduce this because we can't deduce through a
|
|
173 // SubstNonTypeTemplateParmPackExpr.
|
|
174 E e = Z<X<1, 2>, X<3, 4>>(); // expected-error {{no viable}}
|
|
175 using ET = decltype(e);
|
|
176 using ET = E<1, 3>;
|
|
177
|
|
178 // CHECK-LABEL: Dumping <deduction guide for E>:
|
|
179 // CHECK: FunctionTemplateDecl
|
|
180 // CHECK: |-NonTypeTemplateParmDecl [[N:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 0 ... N
|
|
181 // CHECK: |-NonTypeTemplateParmDecl [[M1:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 1 M1
|
|
182 // CHECK: |-NonTypeTemplateParmDecl [[M2:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 2 M2
|
|
183 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<M1, M2>) -> E<N...>'
|
|
184 // CHECK: `-ParmVarDecl {{.*}} 'B<M1, M2>':'Z<X<N, M>...>'
|
|
185 // CHECK: FunctionProtoType {{.*}} 'auto (B<M1, M2>) -> E<N...>' dependent trailing_return
|
|
186 // CHECK: |-InjectedClassNameType {{.*}} 'E<N...>' dependent
|
|
187 // CHECK: `-TemplateSpecializationType {{.*}} 'B<M1, M2>' sugar dependent alias B
|
|
188 // CHECK: |-TemplateArgument expr
|
|
189 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M1' 'int'
|
|
190 // CHECK: |-TemplateArgument expr
|
|
191 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M2' 'int'
|
|
192 // CHECK: `-TemplateSpecializationType {{.*}} 'Z<X<N, M>...>' dependent Z
|
|
193 // CHECK: `-TemplateArgument type 'X<N, M>...'
|
|
194 // CHECK: `-PackExpansionType {{.*}} 'X<N, M>...' dependent expansions 2
|
|
195 // CHECK: `-TemplateSpecializationType {{.*}} 'X<N, M>' dependent contains_unexpanded_pack X
|
|
196 // CHECK: |-TemplateArgument expr
|
|
197 // CHECK-NOT: Subst
|
|
198 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[N]] 'N' 'int'
|
|
199 // CHECK: `-TemplateArgument expr
|
|
200 // CHECK: `-SubstNonTypeTemplateParmPackExpr {{.*}} 'int'
|
|
201 // CHECK: |-NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 1 index 0 ... M
|
|
202 // CHECK: `-TemplateArgument pack
|
|
203 // CHECK: |-TemplateArgument expr
|
|
204 // CHECK-NOT: Subst
|
|
205 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M1]] 'M1' 'int'
|
|
206 // CHECK: `-TemplateArgument expr
|
|
207 // CHECK-NOT: Subst
|
|
208 // CHECK: `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int'
|