Skip to content

Commit 9264c85

Browse files
authored
[Sema] Remove the duplicated DeduceTemplateArguments for partial specialization, NFC (#87782)
We have two identical "DeduceTemplateArguments" implementations for class and variable partial template specializations, this patch removes the duplicated code.
1 parent 2606c87 commit 9264c85

File tree

1 file changed

+24
-61
lines changed

1 file changed

+24
-61
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 24 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3140,13 +3140,15 @@ static TemplateDeductionResult FinishTemplateArgumentDeduction(
31403140
return TemplateDeductionResult::Success;
31413141
}
31423142

3143-
/// Perform template argument deduction to determine whether
3144-
/// the given template arguments match the given class template
3145-
/// partial specialization per C++ [temp.class.spec.match].
3146-
TemplateDeductionResult
3147-
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
3148-
ArrayRef<TemplateArgument> TemplateArgs,
3149-
TemplateDeductionInfo &Info) {
3143+
/// Perform template argument deduction to determine whether the given template
3144+
/// arguments match the given class or variable template partial specialization
3145+
/// per C++ [temp.class.spec.match].
3146+
template <typename T>
3147+
static std::enable_if_t<IsPartialSpecialization<T>::value,
3148+
TemplateDeductionResult>
3149+
DeduceTemplateArguments(Sema &S, T *Partial,
3150+
ArrayRef<TemplateArgument> TemplateArgs,
3151+
TemplateDeductionInfo &Info) {
31503152
if (Partial->isInvalidDecl())
31513153
return TemplateDeductionResult::Invalid;
31523154

@@ -3158,90 +3160,51 @@ Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
31583160

31593161
// Unevaluated SFINAE context.
31603162
EnterExpressionEvaluationContext Unevaluated(
3161-
*this, Sema::ExpressionEvaluationContext::Unevaluated);
3162-
SFINAETrap Trap(*this);
3163+
S, Sema::ExpressionEvaluationContext::Unevaluated);
3164+
Sema::SFINAETrap Trap(S);
31633165

31643166
// This deduction has no relation to any outer instantiation we might be
31653167
// performing.
3166-
LocalInstantiationScope InstantiationScope(*this);
3168+
LocalInstantiationScope InstantiationScope(S);
31673169

31683170
SmallVector<DeducedTemplateArgument, 4> Deduced;
31693171
Deduced.resize(Partial->getTemplateParameters()->size());
31703172
if (TemplateDeductionResult Result = ::DeduceTemplateArguments(
3171-
*this, Partial->getTemplateParameters(),
3173+
S, Partial->getTemplateParameters(),
31723174
Partial->getTemplateArgs().asArray(), TemplateArgs, Info, Deduced,
31733175
/*NumberOfArgumentsMustMatch=*/false);
31743176
Result != TemplateDeductionResult::Success)
31753177
return Result;
31763178

31773179
SmallVector<TemplateArgument, 4> DeducedArgs(Deduced.begin(), Deduced.end());
3178-
InstantiatingTemplate Inst(*this, Info.getLocation(), Partial, DeducedArgs,
3179-
Info);
3180+
Sema::InstantiatingTemplate Inst(S, Info.getLocation(), Partial, DeducedArgs,
3181+
Info);
31803182
if (Inst.isInvalid())
31813183
return TemplateDeductionResult::InstantiationDepth;
31823184

31833185
if (Trap.hasErrorOccurred())
31843186
return TemplateDeductionResult::SubstitutionFailure;
31853187

31863188
TemplateDeductionResult Result;
3187-
runWithSufficientStackSpace(Info.getLocation(), [&] {
3188-
Result = ::FinishTemplateArgumentDeduction(*this, Partial,
3189+
S.runWithSufficientStackSpace(Info.getLocation(), [&] {
3190+
Result = ::FinishTemplateArgumentDeduction(S, Partial,
31893191
/*IsPartialOrdering=*/false,
31903192
TemplateArgs, Deduced, Info);
31913193
});
31923194
return Result;
31933195
}
31943196

3195-
/// Perform template argument deduction to determine whether
3196-
/// the given template arguments match the given variable template
3197-
/// partial specialization per C++ [temp.class.spec.match].
3197+
TemplateDeductionResult
3198+
Sema::DeduceTemplateArguments(ClassTemplatePartialSpecializationDecl *Partial,
3199+
ArrayRef<TemplateArgument> TemplateArgs,
3200+
TemplateDeductionInfo &Info) {
3201+
return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info);
3202+
}
31983203
TemplateDeductionResult
31993204
Sema::DeduceTemplateArguments(VarTemplatePartialSpecializationDecl *Partial,
32003205
ArrayRef<TemplateArgument> TemplateArgs,
32013206
TemplateDeductionInfo &Info) {
3202-
if (Partial->isInvalidDecl())
3203-
return TemplateDeductionResult::Invalid;
3204-
3205-
// C++ [temp.class.spec.match]p2:
3206-
// A partial specialization matches a given actual template
3207-
// argument list if the template arguments of the partial
3208-
// specialization can be deduced from the actual template argument
3209-
// list (14.8.2).
3210-
3211-
// Unevaluated SFINAE context.
3212-
EnterExpressionEvaluationContext Unevaluated(
3213-
*this, Sema::ExpressionEvaluationContext::Unevaluated);
3214-
SFINAETrap Trap(*this);
3215-
3216-
// This deduction has no relation to any outer instantiation we might be
3217-
// performing.
3218-
LocalInstantiationScope InstantiationScope(*this);
3219-
3220-
SmallVector<DeducedTemplateArgument, 4> Deduced;
3221-
Deduced.resize(Partial->getTemplateParameters()->size());
3222-
if (TemplateDeductionResult Result = ::DeduceTemplateArguments(
3223-
*this, Partial->getTemplateParameters(),
3224-
Partial->getTemplateArgs().asArray(), TemplateArgs, Info, Deduced,
3225-
/*NumberOfArgumentsMustMatch=*/false);
3226-
Result != TemplateDeductionResult::Success)
3227-
return Result;
3228-
3229-
SmallVector<TemplateArgument, 4> DeducedArgs(Deduced.begin(), Deduced.end());
3230-
InstantiatingTemplate Inst(*this, Info.getLocation(), Partial, DeducedArgs,
3231-
Info);
3232-
if (Inst.isInvalid())
3233-
return TemplateDeductionResult::InstantiationDepth;
3234-
3235-
if (Trap.hasErrorOccurred())
3236-
return TemplateDeductionResult::SubstitutionFailure;
3237-
3238-
TemplateDeductionResult Result;
3239-
runWithSufficientStackSpace(Info.getLocation(), [&] {
3240-
Result = ::FinishTemplateArgumentDeduction(*this, Partial,
3241-
/*IsPartialOrdering=*/false,
3242-
TemplateArgs, Deduced, Info);
3243-
});
3244-
return Result;
3207+
return ::DeduceTemplateArguments(*this, Partial, TemplateArgs, Info);
32453208
}
32463209

32473210
/// Determine whether the given type T is a simple-template-id type.

0 commit comments

Comments
 (0)