Skip to content

Commit 2447bf8

Browse files
committed
Address review comments.
1 parent b0b8d5b commit 2447bf8

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2743,7 +2743,7 @@ Expr *
27432743
buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
27442744
TypeAliasTemplateDecl *AliasTemplate,
27452745
ArrayRef<DeducedTemplateArgument> DeduceResults,
2746-
unsigned UndeducedTemplateParameterStartIndex,
2746+
unsigned FirstUndeducedParamIdx,
27472747
Expr *IsDeducible) {
27482748
Expr *RC = F->getTemplateParameters()->getRequiresClause();
27492749
if (!RC)
@@ -2805,16 +2805,16 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28052805
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
28062806
const auto &D = DeduceResults[Index];
28072807
if (D.isNull()) { // non-deduced template parameters of f
2808-
auto TP = F->getTemplateParameters()->getParam(Index);
2808+
NamedDecl* TP = F->getTemplateParameters()->getParam(Index);
28092809
MultiLevelTemplateArgumentList Args;
28102810
Args.setKind(TemplateSubstitutionKind::Rewrite);
28112811
Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
28122812
// Rebuild the template parameter with updated depth and index.
28132813
NamedDecl *NewParam = transformTemplateParameter(
28142814
SemaRef, F->getDeclContext(), TP, Args,
2815-
/*NewIndex=*/UndeducedTemplateParameterStartIndex++,
2815+
/*NewIndex=*/FirstUndeducedParamIdx,
28162816
getTemplateParameterDepth(TP) + AdjustDepth);
2817-
2817+
FirstUndeducedParamIdx += 1;
28182818
assert(TemplateArgsForBuildingRC[Index].isNull());
28192819
TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument(
28202820
Context.getInjectedTemplateArg(NewParam));
@@ -2835,11 +2835,9 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28352835
MultiLevelTemplateArgumentList ArgsForBuildingRC;
28362836
ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
28372837
ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
2838-
// For 2), if the underlying function template F is nested in a class template
2839-
// (either instantiated from an explicitly-written deduction guide, or
2840-
// synthesized from a constructor), we need the entire template argument list,
2841-
// as the constraint AST in the require-clause of F remains completely
2842-
// uninstantiated.
2838+
// For 2), if the underlying deduction guide F is nested in a class template,
2839+
// we need the entire template argument list, as the constraint AST in the
2840+
// require-clause of F remains completely uninstantiated.
28432841
//
28442842
// For example:
28452843
// template <typename T> // depth 0
@@ -2862,6 +2860,11 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28622860
// We add the outer template arguments which is [int] to the multi-level arg
28632861
// list to ensure that the occurrence U in `C<U>` will be replaced with int
28642862
// during the substitution.
2863+
//
2864+
// NOTE: The underlying deduction guide F is instantiated -- either from an
2865+
// explicitly-written deduction guide member, or from a constructor.
2866+
// getInstantiatedFromMemberTemplate() can only handle the former case, so we
2867+
// check the DeclContext kind.
28652868
if (F->getLexicalDeclContext()->getDeclKind() ==
28662869
clang::Decl::ClassTemplateSpecialization) {
28672870
auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
@@ -3081,7 +3084,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
30813084
Context.getInjectedTemplateArg(NewParam));
30823085
TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
30833086
}
3084-
unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();
3087+
unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
30853088
// ...followed by the template parameters of f that were not deduced
30863089
// (including their default template arguments)
30873090
for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3152,7 +3155,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
31523155
SemaRef, AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
31533156
Expr *RequiresClause = buildAssociatedConstraints(
31543157
SemaRef, F, AliasTemplate, DeduceResults,
3155-
UndeducedTemplateParameterStartIndex, IsDeducible);
3158+
FirstUndeducedParamIdx, IsDeducible);
31563159

31573160
auto *FPrimeTemplateParamList = TemplateParameterList::Create(
31583161
Context, AliasTemplate->getTemplateParameters()->getTemplateLoc(),

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ template <typename T0>
5858
struct Out3 {
5959
template<class T1, typename T2>
6060
struct Foo {
61-
// Deduction guide: Foo(T1, T2, V) -> Foo<T1, T2, V>;
61+
// Deduction guide:
62+
// template <typename T1, typename T2, typename V>
63+
// Foo(V, T1) -> Foo<T1, T2>;
6264
template<class V> requires Concept<T0, V> // V in require clause of Foo deduction guide: depth 1, index: 2
6365
Foo(V, T1);
6466
};

0 commit comments

Comments
 (0)