Debian Codegraph @

clang/test/AST/ast-dump-ctad-alias.cpp

raw
1 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++2a -ast-dump %s | FileCheck -strict-whitespace %s
2
3 template <typename, typename>
4 constexpr bool Concept = true;
5 template<typename T> // depth 0
6 struct Out {
7 template<typename U> // depth 1
8 struct Inner {
9 U t;
10 };
11
12 template<typename V> // depth1
13 requires Concept<T, V>
14 Inner(V) -> Inner<V>;
15 };
16
17 template <typename X>
18 struct Out2 {
19 template<typename Y> // depth1
20 using AInner = Out<int>::Inner<Y>;
21 };
22 Out2<double>::AInner t(1.0);
23
24 // Verify that the require-clause of alias deduction guide is transformed correctly:
25 // - Occurrence T should be replaced with `int`;
26 // - Occurrence V should be replaced with the Y with depth 1
27 // - Depth of occurrence Y in the __is_deducible constraint should be 1
28 //
29 // CHECK: | `-FunctionTemplateDecl {{.*}} <deduction guide for AInner>
30 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} typename depth 0 index 0 Y
31 // CHECK-NEXT: | |-BinaryOperator {{.*}} '<dependent type>' '&&'
32 // CHECK-NEXT: | | |-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'Concept'
33 // CHECK-NEXT: | | | |-TemplateArgument type 'int'
34 // CHECK-NEXT: | | | | `-BuiltinType {{.*}} 'int'
35 // CHECK-NEXT: | | | `-TemplateArgument type 'Y':'type-parameter-1-0'
36 // CHECK-NEXT: | | | `-TemplateTypeParmType {{.*}} 'Y' dependent depth 1 index 0
37 // CHECK-NEXT: | | | `-TemplateTypeParm {{.*}} 'Y'
38 // CHECK-NEXT: | | `-TypeTraitExpr {{.*}} 'bool' __is_deducible
39 // CHECK-NEXT: | | |-DeducedTemplateSpecializationType {{.*}} 'Out2<double>::AInner' dependent
40 // CHECK-NEXT: | | | `-name: 'Out2<double>::AInner'
41 // CHECK-NEXT: | | | `-TypeAliasTemplateDecl {{.+}} AInner{{$}}
42 // CHECK-NEXT: | | `-TemplateSpecializationType {{.*}} 'Inner<Y>' dependent
43 // CHECK-NEXT: | | |-name: 'Inner':'Out<int>::Inner' qualified
44 // CHECK-NEXT: | | | `-ClassTemplateDecl {{.+}} Inner{{$}}
45 // CHECK-NEXT: | | `-TemplateArgument type 'Y'
46 // CHECK-NEXT: | | `-SubstTemplateTypeParmType {{.*}} 'Y'
47 // CHECK-NEXT: | | |-FunctionTemplate {{.*}} '<deduction guide for Inner>'
48 // CHECK-NEXT: | | `-TemplateTypeParmType {{.*}} 'Y' dependent depth 1 index 0
49 // CHECK-NEXT: | | `-TemplateTypeParm {{.*}} 'Y'
50 // CHECK-NEXT: | |-CXXDeductionGuideDecl {{.*}} <deduction guide for AInner> 'auto (Y) -> Inner<Y>'
51 // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'Y'
52 // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} used <deduction guide for AInner> 'auto (double) -> Inner<double>' implicit_instantiation
53 // CHECK-NEXT: | |-TemplateArgument type 'double'
54 // CHECK-NEXT: | | `-BuiltinType {{.*}} 'double'
55 // CHECK-NEXT: | `-ParmVarDecl {{.*}} 'double'
56
57 // GH92596
58 template <typename T0>
59 struct Out3 {
60 template<class T1, typename T2>
61 struct Foo {
62 // Deduction guide:
63 // template <typename T1, typename T2, typename V>
64 // Foo(V, T1) -> Foo<T1, T2>;
65 template<class V> requires Concept<T0, V> // V in require clause of Foo deduction guide: depth 1, index: 2
66 Foo(V, T1);
67 };
68 };
69 template<class T3>
70 using AFoo3 = Out3<int>::Foo<T3, T3>;
71 AFoo3 afoo3{0, 1};
72 // Verify occurrence V in the require-clause is transformed (depth: 1 => 0, index: 2 => 1) correctly.
73
74 // CHECK: FunctionTemplateDecl {{.*}} implicit <deduction guide for AFoo3>
75 // CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T3
76 // CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 1 V
77 // CHECK-NEXT: |-BinaryOperator {{.*}} '<dependent type>' '&&'
78 // CHECK-NEXT: | |-UnresolvedLookupExpr {{.*}} '<dependent type>' lvalue (no ADL) = 'Concept'
79 // CHECK-NEXT: | | |-TemplateArgument type 'int'
80 // CHECK-NEXT: | | | `-BuiltinType {{.*}} 'int'
81 // CHECK-NEXT: | | `-TemplateArgument type 'V'
82 // CHECK-NEXT: | | `-TemplateTypeParmType {{.*}} 'V' dependent depth 0 index 1
83
84 template <typename... T1>
85 struct Foo {
86 Foo(T1...);
87 };
88
89 template <typename...T2>
90 using AFoo = Foo<T2...>;
91 AFoo a(1, 2);
92 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for AFoo> 'auto (T2...) -> Foo<T2...>'
93 // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'T2...' pack
94 // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for AFoo> 'auto (int, int) -> Foo<int, int>' implicit_instantiation
95
96 template <typename T>
97 using BFoo = Foo<T, T>;
98 BFoo b2(1.0, 2.0);
99 // CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for BFoo> 'auto (T, T) -> Foo<T, T>'
100 // CHECK-NEXT: | | |-ParmVarDecl {{.*}} 'T'
101 // CHECK-NEXT: | | `-ParmVarDecl {{.*}} 'T'
102 // CHECK-NEXT: | `-CXXDeductionGuideDecl {{.*}} implicit used <deduction guide for BFoo> 'auto (double, double) -> Foo<double, double>' implicit_instantiation
103
104 namespace GH90209 {
105 // Case 1: type template parameter
106 template <class Ts>
107 struct List1 {
108 List1(int);
109 };
110
111 template <class T1>
112 struct TemplatedClass1 {
113 TemplatedClass1(T1);
114 };
115
116 template <class T1>
117 TemplatedClass1(T1) -> TemplatedClass1<List1<T1>>;
118
119 template <class T2>
120 using ATemplatedClass1 = TemplatedClass1<List1<T2>>;
121
122 ATemplatedClass1 test1(1);
123 // Verify that we have a correct template parameter list for the deduction guide.
124 //
125 // CHECK: FunctionTemplateDecl {{.*}} <deduction guide for ATemplatedClass1>
126 // CHECK-NEXT: |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T2
127 // CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible
128
129 // Case 2: template template parameter
130 template<typename K> struct Foo{};
131
132 template <template<typename> typename Ts>
133 struct List2 {
134 List2(int);
135 };
136
137 template <typename T1>
138 struct TemplatedClass2 {
139 TemplatedClass2(T1);
140 };
141
142 template <template<typename> typename T1>
143 TemplatedClass2(T1<int>) -> TemplatedClass2<List2<T1>>;
144
145 template <template<typename> typename T2>
146 using ATemplatedClass2 = TemplatedClass2<List2<T2>>;
147
148 List2<Foo> list(1);
149 ATemplatedClass2 test2(list);
150 // Verify that we have a correct template parameter list for the deduction guide.
151 //
152 // CHECK: FunctionTemplateDecl {{.*}} <deduction guide for ATemplatedClass2>
153 // CHECK-NEXT: |-TemplateTemplateParmDecl {{.*}} depth 0 index 0 T2
154 // CHECK-NEXT: | `-TemplateTypeParmDecl {{.*}} typename depth 0 index 0
155 // CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible
156
157 } // namespace GH90209
158
159 namespace GH124715 {
160
161 template <class T, class... Args>
162 concept invocable = true;
163
164 template <class T, class... Args> struct Struct {
165 template <class U>
166 requires invocable<U, Args...>
167 Struct(U, Args...) {}
168 };
169
170 template <class...> struct Packs {};
171
172 template <class Lambda, class... Args>
173 Struct(Lambda lambda, Args... args) -> Struct<Lambda, Args...>;
174
175 template <class T, class... Ts> using Alias = Struct<T, Packs<Ts...>>;
176
177 void foo() {
178 Alias([](int) {}, Packs<int>());
179 }
180
181 // CHECK: |-FunctionTemplateDecl {{.*}} implicit <deduction guide for Alias>
182 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T
183 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 1 ... Ts
184 // CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 2 U
185 // CHECK-NEXT: | |-BinaryOperator {{.*}} 'bool' '&&'
186 // CHECK-NEXT: | | |-ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}} 'invocable'
187 // CHECK-NEXT: | | | |-ImplicitConceptSpecializationDecl {{.*}}
188 // CHECK-NEXT: | | | | |-TemplateArgument type 'U'
189 // CHECK-NEXT: | | | | | `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2
190 // CHECK-NEXT: | | | | | `-TemplateTypeParm {{.*}} 'U'
191 // CHECK-NEXT: | | | | `-TemplateArgument pack '<Packs<Ts...>>'
192 // CHECK-NEXT: | | | | `-TemplateArgument type 'Packs<Ts...>'
193 // CHECK-NEXT: | | | | `-TemplateSpecializationType {{.*}} 'Packs<Ts...>' dependent
194 // CHECK-NEXT: | | | | |-name: 'Packs':'GH124715::Packs' qualified
195 // CHECK-NEXT: | | | | | `-ClassTemplateDecl {{.*}} Packs
196 // CHECK-NEXT: | | | | `-TemplateArgument type 'Ts...'
197 // CHECK-NEXT: | | | | `-PackExpansionType {{.*}} 'Ts...' dependent
198 // CHECK-NEXT: | | | | `-TemplateTypeParmType {{.*}} 'Ts' dependent contains_unexpanded_pack depth 0 index 1 pack
199 // CHECK-NEXT: | | | | `-TemplateTypeParm {{.*}} 'Ts'
200 // CHECK-NEXT: | | | |-TemplateArgument {{.*}} type 'U':'type-parameter-0-2'
201 // CHECK-NEXT: | | | | `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2
202 // CHECK-NEXT: | | | | `-TemplateTypeParm {{.*}} 'U'
203
204 } // namespace GH124715