Skip to content

Commit 99f4e99

Browse files
committed
[clang] Move the aggreate deduction guide cache login to
SemaTemplate.cpp, NFC. this is a NFC refactoring change, which is needed for the upcoming fix for alias templates.
1 parent 451cad3 commit 99f4e99

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

clang/lib/Sema/SemaInit.cpp

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10930,32 +10930,15 @@ QualType Sema::DeduceTemplateSpecializationFromInitializer(
1093010930
Context.getLValueReferenceType(ElementTypes[I].withConst());
1093110931
}
1093210932

10933-
llvm::FoldingSetNodeID ID;
10934-
ID.AddPointer(Template);
10935-
for (auto &T : ElementTypes)
10936-
T.getCanonicalType().Profile(ID);
10937-
unsigned Hash = ID.ComputeHash();
10938-
if (AggregateDeductionCandidates.count(Hash) == 0) {
10939-
if (FunctionTemplateDecl *TD =
10940-
DeclareImplicitDeductionGuideFromInitList(
10941-
Template, ElementTypes,
10942-
TSInfo->getTypeLoc().getEndLoc())) {
10943-
auto *GD = cast<CXXDeductionGuideDecl>(TD->getTemplatedDecl());
10944-
GD->setDeductionCandidateKind(DeductionCandidate::Aggregate);
10945-
AggregateDeductionCandidates[Hash] = GD;
10946-
addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
10947-
OnlyListConstructors,
10948-
/*AllowAggregateDeductionCandidate=*/true);
10949-
}
10950-
} else {
10951-
CXXDeductionGuideDecl *GD = AggregateDeductionCandidates[Hash];
10952-
FunctionTemplateDecl *TD = GD->getDescribedFunctionTemplate();
10953-
assert(TD && "aggregate deduction candidate is function template");
10933+
if (FunctionTemplateDecl *TD =
10934+
DeclareImplicitDeductionGuideFromInitList(
10935+
Template, ElementTypes, TSInfo->getTypeLoc().getEndLoc())) {
10936+
auto *GD = cast<CXXDeductionGuideDecl>(TD->getTemplatedDecl());
1095410937
addDeductionCandidate(TD, GD, DeclAccessPair::make(TD, AS_public),
1095510938
OnlyListConstructors,
1095610939
/*AllowAggregateDeductionCandidate=*/true);
10940+
HasAnyDeductionGuide = true;
1095710941
}
10958-
HasAnyDeductionGuide = true;
1095910942
}
1096010943
};
1096110944

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,6 +3019,23 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
30193019
FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
30203020
TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes,
30213021
SourceLocation Loc) {
3022+
llvm::FoldingSetNodeID ID;
3023+
ID.AddPointer(Template);
3024+
for (auto &T : ParamTypes)
3025+
T.getCanonicalType().Profile(ID);
3026+
unsigned Hash = ID.ComputeHash();
3027+
3028+
auto Found = AggregateDeductionCandidates.find(Hash);
3029+
if (Found != AggregateDeductionCandidates.end()) {
3030+
CXXDeductionGuideDecl *GD = Found->getSecond();
3031+
return GD->getDescribedFunctionTemplate();
3032+
}
3033+
3034+
// if (auto *AliasTemplate = llvm::dyn_cast<TypeAliasTemplateDecl>(Template)) {
3035+
// DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc);
3036+
// return;
3037+
// }
3038+
30223039
if (CXXRecordDecl *DefRecord =
30233040
cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
30243041
if (TemplateDecl *DescribedTemplate =
@@ -3051,10 +3068,13 @@ FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
30513068
Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
30523069
ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
30533070

3054-
auto *DG = cast<FunctionTemplateDecl>(
3071+
auto *FTD = cast<FunctionTemplateDecl>(
30553072
Transform.buildSimpleDeductionGuide(ParamTypes));
30563073
SavedContext.pop();
3057-
return DG;
3074+
auto *GD = cast<CXXDeductionGuideDecl>(FTD->getTemplatedDecl());
3075+
GD->setDeductionCandidateKind(DeductionCandidate::Aggregate);
3076+
AggregateDeductionCandidates[Hash] = GD;
3077+
return FTD;
30583078
}
30593079

30603080
void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,

0 commit comments

Comments
 (0)