Skip to content

Commit dc45f60

Browse files
committed
Address review comments.
1 parent 1481708 commit dc45f60

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
@@ -2779,7 +2779,7 @@ Expr *
27792779
buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
27802780
TypeAliasTemplateDecl *AliasTemplate,
27812781
ArrayRef<DeducedTemplateArgument> DeduceResults,
2782-
unsigned UndeducedTemplateParameterStartIndex,
2782+
unsigned FirstUndeducedParamIdx,
27832783
Expr *IsDeducible) {
27842784
Expr *RC = F->getTemplateParameters()->getRequiresClause();
27852785
if (!RC)
@@ -2841,16 +2841,16 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28412841
for (unsigned Index = 0; Index < DeduceResults.size(); ++Index) {
28422842
const auto &D = DeduceResults[Index];
28432843
if (D.isNull()) { // non-deduced template parameters of f
2844-
auto TP = F->getTemplateParameters()->getParam(Index);
2844+
NamedDecl* TP = F->getTemplateParameters()->getParam(Index);
28452845
MultiLevelTemplateArgumentList Args;
28462846
Args.setKind(TemplateSubstitutionKind::Rewrite);
28472847
Args.addOuterTemplateArguments(TemplateArgsForBuildingRC);
28482848
// Rebuild the template parameter with updated depth and index.
28492849
NamedDecl *NewParam = transformTemplateParameter(
28502850
SemaRef, F->getDeclContext(), TP, Args,
2851-
/*NewIndex=*/UndeducedTemplateParameterStartIndex++,
2851+
/*NewIndex=*/FirstUndeducedParamIdx,
28522852
getTemplateParameterDepth(TP) + AdjustDepth);
2853-
2853+
FirstUndeducedParamIdx += 1;
28542854
assert(TemplateArgsForBuildingRC[Index].isNull());
28552855
TemplateArgsForBuildingRC[Index] = Context.getCanonicalTemplateArgument(
28562856
Context.getInjectedTemplateArg(NewParam));
@@ -2871,11 +2871,9 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28712871
MultiLevelTemplateArgumentList ArgsForBuildingRC;
28722872
ArgsForBuildingRC.setKind(clang::TemplateSubstitutionKind::Rewrite);
28732873
ArgsForBuildingRC.addOuterTemplateArguments(TemplateArgsForBuildingRC);
2874-
// For 2), if the underlying function template F is nested in a class template
2875-
// (either instantiated from an explicitly-written deduction guide, or
2876-
// synthesized from a constructor), we need the entire template argument list,
2877-
// as the constraint AST in the require-clause of F remains completely
2878-
// uninstantiated.
2874+
// For 2), if the underlying deduction guide F is nested in a class template,
2875+
// we need the entire template argument list, as the constraint AST in the
2876+
// require-clause of F remains completely uninstantiated.
28792877
//
28802878
// For example:
28812879
// template <typename T> // depth 0
@@ -2898,6 +2896,11 @@ buildAssociatedConstraints(Sema &SemaRef, FunctionTemplateDecl *F,
28982896
// We add the outer template arguments which is [int] to the multi-level arg
28992897
// list to ensure that the occurrence U in `C<U>` will be replaced with int
29002898
// during the substitution.
2899+
//
2900+
// NOTE: The underlying deduction guide F is instantiated -- either from an
2901+
// explicitly-written deduction guide member, or from a constructor.
2902+
// getInstantiatedFromMemberTemplate() can only handle the former case, so we
2903+
// check the DeclContext kind.
29012904
if (F->getLexicalDeclContext()->getDeclKind() ==
29022905
clang::Decl::ClassTemplateSpecialization) {
29032906
auto OuterLevelArgs = SemaRef.getTemplateInstantiationArgs(
@@ -3117,7 +3120,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
31173120
Context.getInjectedTemplateArg(NewParam));
31183121
TransformedDeducedAliasArgs[AliasTemplateParamIdx] = NewTemplateArgument;
31193122
}
3120-
unsigned UndeducedTemplateParameterStartIndex = FPrimeTemplateParams.size();
3123+
unsigned FirstUndeducedParamIdx = FPrimeTemplateParams.size();
31213124
// ...followed by the template parameters of f that were not deduced
31223125
// (including their default template arguments)
31233126
for (unsigned FTemplateParamIdx : NonDeducedTemplateParamsInFIndex) {
@@ -3188,7 +3191,7 @@ BuildDeductionGuideForTypeAlias(Sema &SemaRef,
31883191
SemaRef, AliasTemplate, FPrime->getReturnType(), FPrimeTemplateParams);
31893192
Expr *RequiresClause = buildAssociatedConstraints(
31903193
SemaRef, F, AliasTemplate, DeduceResults,
3191-
UndeducedTemplateParameterStartIndex, IsDeducible);
3194+
FirstUndeducedParamIdx, IsDeducible);
31923195

31933196
auto *FPrimeTemplateParamList = TemplateParameterList::Create(
31943197
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)