[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaTemplate / deduction-guide.cpp
blobd03c783313dd71d7db9e53dff399b503e0b653ce
1 // RUN: %clang_cc1 -std=c++2a -verify -ast-dump -ast-dump-decl-types -ast-dump-filter "deduction guide" %s | FileCheck %s --strict-whitespace
3 template<auto ...> struct X {};
4 template<template<typename X, X> typename> struct Y {};
5 template<typename ...> struct Z {};
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>;
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 '(short)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>'
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: |-ElaboratedType {{.*}} 'X<Ps...>' sugar dependent
47 // CHECK: | `-TemplateSpecializationType {{.*}} 'X<Ps...>' dependent
48 // CHECK: | `-TemplateArgument expr
49 // CHECK: | `-PackExpansionExpr {{.*}} 'T *'
50 // CHECK: | `-DeclRefExpr {{.*}} 'T *' NonTypeTemplateParm {{.*}} 'Ps' 'T *'
51 // CHECK: `-PackExpansionType {{.*}} 'Ts (*)[Ns]...' dependent
52 // CHECK: `-PointerType {{.*}} 'Ts (*)[Ns]' dependent contains_unexpanded_pack
53 // CHECK: `-ParenType {{.*}} 'Ts[Ns]' sugar dependent contains_unexpanded_pack
54 // CHECK: `-DependentSizedArrayType {{.*}} 'Ts[Ns]' dependent contains_unexpanded_pack
55 // CHECK: |-TemplateTypeParmType {{.*}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
56 // CHECK: | `-TemplateTypeParm {{.*}} 'Ts'
57 // CHECK: `-DeclRefExpr {{.*}} 'Ts' NonTypeTemplateParm {{.*}} 'Ns' 'Ts...'
59 template<typename T, T V> struct B {
60 template<typename U, U W> B(X<W, V>);
62 B b(X<nullptr, 'x'>{});
63 using BT = decltype(b);
64 using BT = B<char, 'x'>;
66 // CHECK-LABEL: Dumping <deduction guide for B>:
67 // CHECK: FunctionTemplateDecl
68 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 T
69 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'T' depth 0 index 1 V
70 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U
71 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'U' depth 0 index 3 W
72 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (X<W, V>) -> B<T, V>'
73 // CHECK: | `-ParmVarDecl {{.*}} 'X<W, V>'
74 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (X<nullptr, 'x'>) -> B<char, 'x'>'
75 // CHECK: |-TemplateArgument type 'char'
76 // CHECK: |-TemplateArgument integral ''x''
77 // CHECK: |-TemplateArgument type 'std::nullptr_t'
78 // CHECK: |-TemplateArgument nullptr
79 // CHECK: `-ParmVarDecl {{.*}} 'X<nullptr, 'x'>'
80 // CHECK: FunctionProtoType {{.*}} 'auto (X<W, V>) -> B<T, V>' dependent trailing_return
81 // CHECK: |-InjectedClassNameType {{.*}} 'B<T, V>' dependent
82 // CHECK: `-TemplateSpecializationType {{.*}} 'X<W, V>' dependent
83 // CHECK: |-TemplateArgument expr
84 // CHECK: | `-DeclRefExpr {{.*}} 'U' NonTypeTemplateParm {{.*}} 'W' 'U'
85 // CHECK: `-TemplateArgument expr
86 // CHECK: `-DeclRefExpr {{.*}} 'T' NonTypeTemplateParm {{.*}} 'V' 'T'
88 template<typename A> struct C {
89 template<template<typename X, X> typename T, typename U, U V = 0> C(A, Y<T>, U);
91 C c(1, Y<B>{}, 2);
92 using CT = decltype(c);
93 using CT = C<int>;
95 // CHECK-LABEL: Dumping <deduction guide for C>:
96 // CHECK: FunctionTemplateDecl
97 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 A
98 // CHECK: |-TemplateTemplateParmDecl {{.*}} depth 0 index 1 T
99 // CHECK: | |-TemplateTypeParmDecl {{.*}} typename depth 1 index 0 X
100 // CHECK: | `-NonTypeTemplateParmDecl {{.*}} 'X' depth 1 index 1
101 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U
102 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'U' depth 0 index 3 V
103 // CHECK: | `-TemplateArgument {{.*}} expr
104 // CHECK: | `-IntegerLiteral {{.*}} 'int' 0
105 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (A, Y<T>, U) -> C<A>'
106 // CHECK: | |-ParmVarDecl {{.*}} 'A'
107 // CHECK: | |-ParmVarDecl {{.*}} 'Y<T>'
108 // CHECK: | `-ParmVarDecl {{.*}} 'U'
109 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int, Y<B>, int) -> C<int>'
110 // CHECK: |-TemplateArgument type 'int'
111 // CHECK: |-TemplateArgument template 'B'
112 // CHECK: |-TemplateArgument type 'int'
113 // CHECK: |-TemplateArgument integral '0'
114 // CHECK: |-ParmVarDecl {{.*}} 'int'
115 // CHECK: |-ParmVarDecl {{.*}} 'Y<B>'
116 // CHECK: `-ParmVarDecl {{.*}} 'int'
117 // CHECK: FunctionProtoType {{.*}} 'auto (A, Y<T>, U) -> C<A>' dependent trailing_return cdecl
118 // CHECK: |-InjectedClassNameType {{.*}} 'C<A>' dependent
119 // CHECK: |-TemplateTypeParmType {{.*}} 'A' dependent depth 0 index 0
120 // CHECK: | `-TemplateTypeParm {{.*}} 'A'
121 // CHECK: |-ElaboratedType {{.*}} 'Y<T>' sugar dependent
122 // CHECK: | `-TemplateSpecializationType {{.*}} 'Y<T>' dependent
123 // CHECK: | `-TemplateArgument template
124 // CHECK: `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2
126 template<typename ...T> struct D { // expected-note {{candidate}} \
127 // expected-note {{implicit deduction guide declared as 'template <typename ...T> D(D<T...>) -> D<T...>'}}
128 template<typename... U> using B = int(int (*...p)(T, U));
129 template<typename U1, typename U2> D(B<U1, U2>*); // expected-note {{candidate}} \
130 // expected-note {{implicit deduction guide declared as 'template <typename ...T, typename U1, typename U2> D(B<U1, U2> *) -> D<T...>'}}
132 int f(int(int, int), int(int, int));
133 // FIXME: We can't deduce this because we can't deduce through a
134 // SubstTemplateTypeParmPackType.
135 D d = f; // expected-error {{no viable}}
136 using DT = decltype(d);
137 using DT = D<int, int>;
139 // CHECK-LABEL: Dumping <deduction guide for D>:
140 // CHECK: FunctionTemplateDecl
141 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 ... T
142 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U1
143 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 2 U2
144 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<U1, U2> *) -> D<T...>'
145 // CHECK: `-ParmVarDecl {{.*}} 'B<U1, U2> *'
146 // CHECK: FunctionProtoType {{.*}} 'auto (B<U1, U2> *) -> D<T...>' dependent trailing_return
147 // CHECK: |-InjectedClassNameType {{.*}} 'D<T...>' dependent
148 // CHECK: `-PointerType {{.*}} 'B<U1, U2> *' dependent
149 // CHECK: `-TemplateSpecializationType {{.*}} 'B<U1, U2>' sugar dependent alias
150 // CHECK: |-TemplateArgument type 'U1'
151 // CHECK: |-TemplateArgument type 'U2'
152 // CHECK: `-FunctionProtoType {{.*}} 'int (int (*)(T, U)...)' dependent cdecl
153 // CHECK: |-BuiltinType {{.*}} 'int'
154 // CHECK: `-PackExpansionType {{.*}} 'int (*)(T, U)...' dependent expansions 2
155 // CHECK: `-PointerType {{.*}} 'int (*)(T, U)' dependent contains_unexpanded_pack
156 // CHECK: `-ParenType {{.*}} 'int (T, U)' sugar dependent contains_unexpanded_pack
157 // CHECK: `-FunctionProtoType {{.*}} 'int (T, U)' dependent contains_unexpanded_pack cdecl
158 // CHECK: |-BuiltinType {{.*}} 'int'
159 // CHECK: |-TemplateTypeParmType {{.*}} 'T' dependent contains_unexpanded_pack depth 0 index 0 pack
160 // CHECK: | `-TemplateTypeParm {{.*}} 'T'
161 // CHECK: `-SubstTemplateTypeParmPackType {{.*}} 'U' dependent contains_unexpanded_pack typename depth 1 index 0 ... U
162 // CHECK: |-TypeAliasTemplate {{.*}} 'B'
163 // CHECK: `-TemplateArgument pack
164 // CHECK: |-TemplateArgument type 'U1':'type-parameter-0-1'
165 // CHECK-NOT: Subst
166 // CHECK: | `-TemplateTypeParmType
167 // CHECK: `-TemplateArgument type 'U2':'type-parameter-0-2'
168 // CHECK-NOT: Subst
169 // CHECK: `-TemplateTypeParmType
171 template<int ...N> struct E { // expected-note {{candidate}} \
172 expected-note {{implicit deduction guide declared as 'template <int ...N> E(E<N...>) -> E<N...>'}}
173 template<int ...M> using B = Z<X<N, M>...>;
174 template<int M1, int M2> E(B<M1, M2>); // expected-note {{candidate}} \
175 // expected-note {{implicit deduction guide declared as 'template <int ...N, int M1, int M2> E(B<M1, M2>) -> E<N...>'}}}}
177 // FIXME: We can't deduce this because we can't deduce through a
178 // SubstNonTypeTemplateParmPackExpr.
179 E e = Z<X<1, 2>, X<3, 4>>(); // expected-error {{no viable}}
180 using ET = decltype(e);
181 using ET = E<1, 3>;
183 // CHECK-LABEL: Dumping <deduction guide for E>:
184 // CHECK: FunctionTemplateDecl
185 // CHECK: |-NonTypeTemplateParmDecl [[N:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 0 ... N
186 // CHECK: |-NonTypeTemplateParmDecl [[M1:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 1 M1
187 // CHECK: |-NonTypeTemplateParmDecl [[M2:0x[0-9a-f]*]] {{.*}} 'int' depth 0 index 2 M2
188 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (B<M1, M2>) -> E<N...>'
189 // CHECK: `-ParmVarDecl {{.*}} 'B<M1, M2>':'Z<X<N, M>...>'
190 // CHECK: FunctionProtoType {{.*}} 'auto (B<M1, M2>) -> E<N...>' dependent trailing_return
191 // CHECK: |-InjectedClassNameType {{.*}} 'E<N...>' dependent
192 // CHECK: `-TemplateSpecializationType {{.*}} 'B<M1, M2>' sugar dependent alias
193 // CHECK: |-TemplateArgument expr
194 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M1' 'int'
195 // CHECK: |-TemplateArgument expr
196 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm {{.*}} 'M2' 'int'
197 // CHECK: `-TemplateSpecializationType {{.*}} 'Z<X<N, M>...>' dependent
198 // CHECK: `-TemplateArgument type 'X<N, M>...'
199 // CHECK: `-PackExpansionType {{.*}} 'X<N, M>...' dependent expansions 2
200 // CHECK: `-TemplateSpecializationType {{.*}} 'X<N, M>' dependent contains_unexpanded_pack
201 // CHECK: |-TemplateArgument expr
202 // CHECK-NOT: Subst
203 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[N]] 'N' 'int'
204 // CHECK: `-TemplateArgument expr
205 // CHECK: `-SubstNonTypeTemplateParmPackExpr {{.*}} 'int'
206 // CHECK: |-NonTypeTemplateParmDecl {{.*}} referenced 'int' depth 1 index 0 ... M
207 // CHECK: `-TemplateArgument pack
208 // CHECK: |-TemplateArgument expr
209 // CHECK-NOT: Subst
210 // CHECK: | `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M1]] 'M1' 'int'
211 // CHECK: `-TemplateArgument expr
212 // CHECK-NOT: Subst
213 // CHECK: `-DeclRefExpr {{.*}} 'int' NonTypeTemplateParm [[M2]] 'M2' 'int'
215 template <char = 'x'> struct F;
217 template <char> struct F {
218 template <typename U>
219 requires(false) F(U);
220 template <typename U>
221 requires(true) F(U);
224 F s(0);
226 // CHECK-LABEL: Dumping <deduction guide for F>:
227 // CHECK: FunctionTemplateDecl
228 // CHECK: |-NonTypeTemplateParmDecl {{.*}} 'char' depth 0 index 0
229 // CHECK: `-TemplateArgument {{.*}} expr
230 // CHECK: | |-inherited from NonTypeTemplateParm {{.*}} '' 'char'
231 // CHECK: | `-CharacterLiteral {{.*}} 'char' 120
232 // CHECK: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 1 U
233 // CHECK: |-ParenExpr {{.*}} 'bool'
234 // CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
235 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (U) -> F<>'
236 // CHECK: | `-ParmVarDecl {{.*}} 'U'
237 // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<>'
238 // CHECK: |-TemplateArgument integral ''x''
239 // CHECK: |-TemplateArgument type 'int'
240 // CHECK: | `-BuiltinType {{.*}} 'int'
241 // CHECK: `-ParmVarDecl {{.*}} 'int'
242 // CHECK: FunctionProtoType {{.*}} 'auto (U) -> F<>' dependent trailing_return cdecl
243 // CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
244 // CHECK: | `-CXXRecord {{.*}} 'F'
245 // CHECK: `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 1
247 template<typename T>
248 struct G { T t; };
250 G g = {1};
251 // CHECK-LABEL: Dumping <deduction guide for G>:
252 // CHECK: FunctionTemplateDecl
253 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for G> 'auto (T) -> G<T>' aggregate
254 // CHECK: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for G> 'auto (int) -> G<int>' implicit_instantiation aggregate
256 template<typename X>
257 using AG = G<X>;
258 AG ag = {1};
259 // Verify that the aggregate deduction guide for alias templates is built.
260 // CHECK-LABEL: Dumping <deduction guide for AG>
261 // CHECK: FunctionTemplateDecl
262 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (X) -> G<X>'
263 // CHECK: `-CXXDeductionGuideDecl {{.*}} 'auto (int) -> G<int>' implicit_instantiation
264 // CHECK: |-TemplateArgument type 'int'
265 // CHECK: | `-BuiltinType {{.*}} 'int'
266 // CHECK: `-ParmVarDecl {{.*}} 'int'
268 template <typename X = int>
269 using BG = G<int>;
270 BG bg(1.0);
271 // CHECK-LABEL: Dumping <deduction guide for BG>
272 // CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for BG>
273 // CHECK: |-CXXDeductionGuideDecl {{.*}} 'auto (int) -> G<int>' aggregate
275 template <typename D>
276 requires (sizeof(D) == 4)
277 struct Foo {
278 Foo(D);
281 template <typename U>
282 using AFoo = Foo<G<U>>;
283 // Verify that the require-clause from the Foo deduction guide is transformed.
284 // The D occurrence should be rewritten to G<U>.
286 // CHECK-LABEL: Dumping <deduction guide for AFoo>
287 // CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for AFoo>
288 // CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 U
289 // CHECK-NEXT: |-BinaryOperator {{.*}} '&&'
290 // CHECK-NEXT: | |-ParenExpr {{.*}} 'bool'
291 // CHECK-NEXT: | | `-BinaryOperator {{.*}} 'bool' '=='
292 // CHECK-NEXT: | | |-UnaryExprOrTypeTraitExpr {{.*}} 'G<U>'
293 // CHECK-NEXT: | | `-ImplicitCastExpr {{.*}}
294 // CHECK-NEXT: | | `-IntegerLiteral {{.*}}
295 // CHECK-NEXT: | `-TypeTraitExpr {{.*}} 'bool' __is_deducible
296 // CHECK-NEXT: | |-DeducedTemplateSpecializationType {{.*}} 'AFoo' dependent
297 // CHECK-NEXT: | | `-name: 'AFoo'
298 // CHECK-NEXT: | | `-TypeAliasTemplateDecl {{.+}} AFoo
299 // CHECK-NEXT: | `-TemplateSpecializationType {{.*}} 'Foo<G<U>>' dependent
300 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for AFoo> 'auto (G<U>) -> Foo<G<U>>'
301 // CHECK-NEXT: | `-ParmVarDecl {{.*}} 'G<U>'
302 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for AFoo> 'auto (G<int>) -> Foo<G<int>>' implicit_instantiation
303 // CHECK-NEXT: |-TemplateArgument type 'int'
304 // CHECK-NEXT: | `-BuiltinType {{.*}} 'int'
305 // CHECK-NEXT: `-ParmVarDecl {{.*}} 'G<int>'
307 AFoo aa(G<int>{});
309 namespace TTP {
310 template<typename> struct A {};
312 template<class T> struct B {
313 template<template <class> typename TT> B(TT<T>);
316 B b(A<int>{});
317 } // namespace TTP
319 // CHECK-LABEL: Dumping TTP::<deduction guide for B>:
320 // CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[# @LINE - 7]]:5, col:51>
321 // CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} class depth 0 index 0 T{{$}}
322 // CHECK-NEXT: |-TemplateTemplateParmDecl {{.+}} depth 0 index 1 TT{{$}}
323 // CHECK-NEXT: | `-TemplateTypeParmDecl {{.+}} class depth 1 index 0{{$}}
324 // CHECK-NEXT: |-CXXDeductionGuideDecl {{.+}} 'auto (TT<T>) -> B<T>'{{$}}
325 // CHECK-NEXT: | `-ParmVarDecl {{.+}} 'TT<T>'{{$}}
326 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} 'auto (A<int>) -> TTP::B<int>'
327 // CHECK-NEXT: |-TemplateArgument type 'int'
328 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'{{$}}
329 // CHECK-NEXT: |-TemplateArgument template 'TTP::A'{{$}}
330 // CHECK-NEXT: | `-ClassTemplateDecl {{.+}} A{{$}}
331 // CHECK-NEXT: `-ParmVarDecl {{.+}} 'A<int>':'TTP::A<int>'{{$}}
332 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (TT<T>) -> B<T>' dependent trailing_return cdecl{{$}}
333 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'B<T>' dependent{{$}}
334 // CHECK-NEXT: | `-CXXRecord {{.+}} 'B'{{$}}
335 // CHECK-NEXT: `-ElaboratedType {{.+}} 'TT<T>' sugar dependent{{$}}
336 // CHECK-NEXT: `-TemplateSpecializationType {{.+}} 'TT<T>' dependent{{$}}
337 // CHECK-NEXT: |-name: 'TT':'template-parameter-0-1' qualified
338 // CHECK-NEXT: | `-TemplateTemplateParmDecl {{.+}} depth 0 index 1
339 // CHECK-NEXT: `-TemplateArgument type 'T':'type-parameter-0-0'{{$}}
340 // CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0{{$}}
341 // CHECK-NEXT: `-TemplateTypeParm {{.+}} 'T'{{$}}
343 namespace GH64625 {
345 template <class T> struct X {
346 T t[2];
349 X x = {{1, 2}};
351 // CHECK-LABEL: Dumping GH64625::<deduction guide for X>:
352 // CHECK-NEXT: FunctionTemplateDecl {{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:27> col:27 implicit <deduction guide for X>
353 // CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:11, col:17> col:17 referenced class depth 0 index 0 T
354 // CHECK: |-CXXDeductionGuideDecl {{.+}} <col:27> col:27 implicit <deduction guide for X> 'auto (T (&&)[2]) -> X<T>' aggregate
355 // CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:27> col:27 'T (&&)[2]'
356 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:27> col:27 implicit used <deduction guide for X> 'auto (int (&&)[2]) -> GH64625::X<int>' implicit_instantiation aggregate
357 // CHECK-NEXT: |-TemplateArgument type 'int'
358 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
359 // CHECK-NEXT: `-ParmVarDecl {{.+}} <col:27> col:27 'int (&&)[2]'
360 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2]) -> X<T>' dependent trailing_return
361 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'X<T>' dependent
362 // CHECK-NEXT: | `-CXXRecord {{.+}} 'X'
363 // CHECK-NEXT: `-RValueReferenceType {{.+}} 'T (&&)[2]' dependent
364 // CHECK-NEXT: `-ConstantArrayType {{.+}} 'T[2]' dependent 2
365 // CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
366 // CHECK-NEXT: `-TemplateTypeParm {{.+}} 'T'
368 template <class T, class U> struct TwoArrays {
369 T t[2];
370 U u[3];
373 TwoArrays ta = {{1, 2}, {3, 4, 5}};
374 // CHECK-LABEL: Dumping GH64625::<deduction guide for TwoArrays>:
375 // CHECK-NEXT: FunctionTemplateDecl {{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:36> col:36 implicit <deduction guide for TwoArrays>
376 // CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:11, col:17> col:17 referenced class depth 0 index 0 T
377 // CHECK-NEXT: |-TemplateTypeParmDecl {{.+}} <col:20, col:26> col:26 referenced class depth 0 index 1 U
378 // CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T (&&)[2], U (&&)[3]) -> TwoArrays<T, U>' aggregate
379 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T (&&)[2]'
380 // CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U (&&)[3]'
381 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int (&&)[2], int (&&)[3]) -> GH64625::TwoArrays<int, int>' implicit_instantiation aggregate
382 // CHECK-NEXT: |-TemplateArgument type 'int'
383 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
384 // CHECK-NEXT: |-TemplateArgument type 'int'
385 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
386 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[2]'
387 // CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[3]'
388 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2], U (&&)[3]) -> TwoArrays<T, U>' dependent trailing_return
389 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'TwoArrays<T, U>' dependent
390 // CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays'
391 // CHECK-NEXT: |-RValueReferenceType {{.+}} 'T (&&)[2]' dependent
392 // CHECK-NEXT: | `-ConstantArrayType {{.+}} 'T[2]' dependent 2
393 // CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
394 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T'
395 // CHECK-NEXT: `-RValueReferenceType {{.+}} 'U (&&)[3]' dependent
396 // CHECK-NEXT: `-ConstantArrayType {{.+}} 'U[3]' dependent 3
397 // CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1
398 // CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U'
400 TwoArrays tb = {1, 2, {3, 4, 5}};
401 // CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T, T, U (&&)[3]) -> TwoArrays<T, U>' aggregate
402 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T'
403 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T'
404 // CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U (&&)[3]'
405 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int, int, int (&&)[3]) -> GH64625::TwoArrays<int, int>' implicit_instantiation aggregate
406 // CHECK-NEXT: |-TemplateArgument type 'int'
407 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
408 // CHECK-NEXT: |-TemplateArgument type 'int'
409 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
410 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int'
411 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int'
412 // CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[3]'
413 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T, T, U (&&)[3]) -> TwoArrays<T, U>' dependent trailing_return
414 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'TwoArrays<T, U>' dependent
415 // CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays'
416 // CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
417 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T'
418 // CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
419 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T'
420 // CHECK-NEXT: `-RValueReferenceType {{.+}} 'U (&&)[3]' dependent
421 // CHECK-NEXT: `-ConstantArrayType {{.+}} 'U[3]' dependent 3
422 // CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1
423 // CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U'
425 TwoArrays tc = {{1, 2}, 3, 4, 5};
426 // CHECK: |-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit <deduction guide for TwoArrays> 'auto (T (&&)[2], U, U, U) -> TwoArrays<T, U>' aggregate
427 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'T (&&)[2]'
428 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'U'
429 // CHECK-NEXT: | |-ParmVarDecl {{.+}} <col:36> col:36 'U'
430 // CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:36> col:36 'U'
431 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:36> col:36 implicit used <deduction guide for TwoArrays> 'auto (int (&&)[2], int, int, int) -> GH64625::TwoArrays<int, int>' implicit_instantiation aggregate
432 // CHECK-NEXT: |-TemplateArgument type 'int'
433 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
434 // CHECK-NEXT: |-TemplateArgument type 'int'
435 // CHECK-NEXT: | `-BuiltinType {{.+}} 'int'
436 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int (&&)[2]'
437 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int'
438 // CHECK-NEXT: |-ParmVarDecl {{.+}} <col:36> col:36 'int'
439 // CHECK-NEXT: `-ParmVarDecl {{.+}} <col:36> col:36 'int'
440 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (T (&&)[2], U, U, U) -> TwoArrays<T, U>' dependent trailing_return
441 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'TwoArrays<T, U>' dependent
442 // CHECK-NEXT: | `-CXXRecord {{.+}} 'TwoArrays'
443 // CHECK-NEXT: |-RValueReferenceType {{.+}} 'T (&&)[2]' dependent
444 // CHECK-NEXT: | `-ConstantArrayType {{.+}} 'T[2]' dependent 2
445 // CHECK-NEXT: | `-TemplateTypeParmType {{.+}} 'T' dependent depth 0 index 0
446 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'T'
447 // CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1
448 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U'
449 // CHECK-NEXT: |-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1
450 // CHECK-NEXT: | `-TemplateTypeParm {{.+}} 'U'
451 // CHECK-NEXT: `-TemplateTypeParmType {{.+}} 'U' dependent depth 0 index 1
452 // CHECK-NEXT: `-TemplateTypeParm {{.+}} 'U'
454 } // namespace GH64625
456 namespace GH83368 {
458 template <int N> struct A {
459 int f1[N];
462 A a{.f1 = {1}};
464 // CHECK-LABEL: Dumping GH83368::<deduction guide for A>:
465 // CHECK-NEXT: FunctionTemplateDecl 0x{{.+}} <{{.+}}:[[#@LINE - 7]]:1, col:25> col:25 implicit <deduction guide for A>
466 // CHECK-NEXT: |-NonTypeTemplateParmDecl {{.+}} <col:11, col:15> col:15 referenced 'int' depth 0 index 0 N
467 // CHECK: |-CXXDeductionGuideDecl {{.+}} <col:25> col:25 implicit <deduction guide for A> 'auto (int (&&)[N]) -> A<N>' aggregate
468 // CHECK-NEXT: | `-ParmVarDecl {{.+}} <col:25> col:25 'int (&&)[N]'
469 // CHECK-NEXT: `-CXXDeductionGuideDecl {{.+}} <col:25> col:25 implicit used <deduction guide for A> 'auto (int (&&)[1]) -> GH83368::A<1>' implicit_instantiation aggregate
470 // CHECK-NEXT: |-TemplateArgument integral '1'
471 // CHECK-NEXT: `-ParmVarDecl {{.+}} <col:25> col:25 'int (&&)[1]'
472 // CHECK-NEXT: FunctionProtoType {{.+}} 'auto (int (&&)[N]) -> A<N>' dependent trailing_return
473 // CHECK-NEXT: |-InjectedClassNameType {{.+}} 'A<N>' dependent
474 // CHECK-NEXT: | `-CXXRecord {{.+}} 'A'
475 // CHECK-NEXT: `-RValueReferenceType {{.+}} 'int (&&)[N]' dependent
476 // CHECK-NEXT: `-DependentSizedArrayType {{.+}} 'int[N]' dependent
477 // CHECK-NEXT: |-BuiltinType {{.+}} 'int'
478 // CHECK-NEXT: `-DeclRefExpr {{.+}} <col:10> 'int' NonTypeTemplateParm {{.+}} 'N' 'int'
480 } // namespace GH83368