Skip to content

Commit 846394e

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 35886dc commit 846394e

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
@@ -3018,6 +3018,23 @@ void DeclareImplicitDeductionGuidesForTypeAlias(
30183018
FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
30193019
TemplateDecl *Template, MutableArrayRef<QualType> ParamTypes,
30203020
SourceLocation Loc) {
3021+
llvm::FoldingSetNodeID ID;
3022+
ID.AddPointer(Template);
3023+
for (auto &T : ParamTypes)
3024+
T.getCanonicalType().Profile(ID);
3025+
unsigned Hash = ID.ComputeHash();
3026+
3027+
auto Found = AggregateDeductionCandidates.find(Hash);
3028+
if (Found != AggregateDeductionCandidates.end()) {
3029+
CXXDeductionGuideDecl *GD = Found->getSecond();
3030+
return GD->getDescribedFunctionTemplate();
3031+
}
3032+
3033+
// if (auto *AliasTemplate = llvm::dyn_cast<TypeAliasTemplateDecl>(Template)) {
3034+
// DeclareImplicitDeductionGuidesForTypeAlias(*this, AliasTemplate, Loc);
3035+
// return;
3036+
// }
3037+
30213038
if (CXXRecordDecl *DefRecord =
30223039
cast<CXXRecordDecl>(Template->getTemplatedDecl())->getDefinition()) {
30233040
if (TemplateDecl *DescribedTemplate =
@@ -3050,10 +3067,13 @@ FunctionTemplateDecl *Sema::DeclareImplicitDeductionGuideFromInitList(
30503067
Transform.NestedPattern ? Transform.NestedPattern : Transform.Template;
30513068
ContextRAII SavedContext(*this, Pattern->getTemplatedDecl());
30523069

3053-
auto *DG = cast<FunctionTemplateDecl>(
3070+
auto *FTD = cast<FunctionTemplateDecl>(
30543071
Transform.buildSimpleDeductionGuide(ParamTypes));
30553072
SavedContext.pop();
3056-
return DG;
3073+
auto *GD = cast<CXXDeductionGuideDecl>(FTD->getTemplatedDecl());
3074+
GD->setDeductionCandidateKind(DeductionCandidate::Aggregate);
3075+
AggregateDeductionCandidates[Hash] = GD;
3076+
return FTD;
30573077
}
30583078

30593079
void Sema::DeclareImplicitDeductionGuides(TemplateDecl *Template,

0 commit comments

Comments
 (0)