Skip to content

Commit 2fece00

Browse files
committed
[Clang] Form PackExpansionTypes of TemplateArguments for rewrite substitution
When substituting for rewrite purposes, as in rebuilding constraints for a synthesized deduction guide, it assumed that packs were in PackExpansion* form, such that the instantiator could extract a pattern. For type aliases CTAD, while rebuilding their associated constraints, we rebuild the template arguments using TransformTemplateArgument(), which did not guarantee the establishment of PackExpansions as getInjectedTemplateArguments() does. This patch fixes that by making it call RebuildPackExpansion() if the transformed arguments are still having unexpanded parameter packs.
1 parent 83a8bb3 commit 2fece00

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiate.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,8 +1627,14 @@ namespace {
16271627
TemplateArgumentLoc Input = SemaRef.getTrivialTemplateArgumentLoc(
16281628
pack, QualType(), SourceLocation{});
16291629
TemplateArgumentLoc Output;
1630-
if (SemaRef.SubstTemplateArgument(Input, TemplateArgs, Output))
1630+
if (TransformTemplateArgument(Input, Output, Uneval))
16311631
return true; // fails
1632+
if (Output.getArgument().containsUnexpandedParameterPack())
1633+
// FIXME: Is EllipsisLoc necessary? This pack expansion merely
1634+
// serves as a placeholder type for future rewrite-substitution
1635+
// (e.g. into constraint expressions.)
1636+
Output =
1637+
RebuildPackExpansion(Output, SourceLocation{}, std::nullopt);
16321638
TArgs.push_back(Output.getArgument());
16331639
}
16341640
Output = SemaRef.getTrivialTemplateArgumentLoc(

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,47 @@ ATemplatedClass2 test2(list);
156156
// CHECK-NEXT: |-TypeTraitExpr {{.*}} 'bool' __is_deducible
157157

158158
} // namespace GH90209
159+
160+
namespace GH124715 {
161+
162+
template <class T, class... Args>
163+
concept invocable = true;
164+
165+
template <class T, class... Args> struct Struct {
166+
template <class U>
167+
requires invocable<U, Args...>
168+
Struct(U, Args...) {}
169+
};
170+
171+
template <class Lambda, class... Args>
172+
Struct(Lambda lambda, Args... args) -> Struct<Lambda, Args...>;
173+
174+
template <class T, class... Ts> using Alias = Struct<T, Ts...>;
175+
176+
void foo() {
177+
Alias([](int) {}, 0);
178+
}
179+
180+
// CHECK: |-FunctionTemplateDecl {{.*}} implicit <deduction guide for Alias>
181+
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 0 T
182+
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 1 ... Ts
183+
// CHECK-NEXT: | |-TemplateTypeParmDecl {{.*}} class depth 0 index 2 U
184+
// CHECK-NEXT: | |-BinaryOperator {{.*}} 'bool' '&&'
185+
// CHECK-NEXT: | | |-ConceptSpecializationExpr {{.*}} 'bool' Concept {{.*}} 'invocable'
186+
// CHECK-NEXT: | | | |-ImplicitConceptSpecializationDecl {{.*}}
187+
// CHECK-NEXT: | | | | |-TemplateArgument type 'type-parameter-0-2'
188+
// CHECK-NEXT: | | | | | `-TemplateTypeParmType {{.*}} 'type-parameter-0-2' dependent depth 0 index 2
189+
// CHECK-NEXT: | | | | `-TemplateArgument pack '<type-parameter-0-1...>'
190+
// CHECK-NEXT: | | | | `-TemplateArgument type 'type-parameter-0-1...'
191+
// CHECK-NEXT: | | | | `-PackExpansionType {{.*}} 'type-parameter-0-1...' dependent
192+
// CHECK-NEXT: | | | | `-TemplateTypeParmType {{.*}} 'type-parameter-0-1' dependent contains_unexpanded_pack depth 0 index 1 pack
193+
// CHECK-NEXT: | | | |-TemplateArgument {{.*}} type 'U':'type-parameter-0-2'
194+
// CHECK-NEXT: | | | | `-TemplateTypeParmType {{.*}} 'U' dependent depth 0 index 2
195+
// CHECK-NEXT: | | | | `-TemplateTypeParm {{.*}} 'U'
196+
// CHECK-NEXT: | | | `-TemplateArgument {{.*}} type 'Ts...':'type-parameter-0-1...'
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: | | `-TypeTraitExpr {{.*}} 'bool' __is_deducible
201+
202+
} // namespace GH124715

0 commit comments

Comments
 (0)