Skip to content

Commit 53c6c6a

Browse files
committed
add hasErrorOccurred check
1 parent 808802b commit 53c6c6a

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,15 +3553,14 @@ static unsigned getPackIndexForParam(Sema &S,
35533553
llvm_unreachable("parameter index would not be produced from template");
35543554
}
35553555

3556-
// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`
3557-
// we try to instantiate and update its explicit specifier after constraint
3556+
// if `Specialization` is a `CXXConstructorDecl` or `CXXConversionDecl`,
3557+
// we'll try to instantiate and update its explicit specifier after constraint
35583558
// checking.
3559-
static Sema::TemplateDeductionResult
3560-
resolveExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
3561-
const MultiLevelTemplateArgumentList &SubstArgs,
3562-
TemplateDeductionInfo &Info,
3563-
FunctionTemplateDecl *FunctionTemplate,
3564-
ArrayRef<TemplateArgument> DeducedArgs) {
3559+
static Sema::TemplateDeductionResult instantiateExplicitSpecifierDeferred(
3560+
Sema &S, FunctionDecl *Specialization,
3561+
const MultiLevelTemplateArgumentList &SubstArgs,
3562+
TemplateDeductionInfo &Info, FunctionTemplateDecl *FunctionTemplate,
3563+
ArrayRef<TemplateArgument> DeducedArgs) {
35653564
auto GetExplicitSpecifier = [](FunctionDecl *D) {
35663565
return isa<CXXConstructorDecl>(D)
35673566
? cast<CXXConstructorDecl>(D)->getExplicitSpecifier()
@@ -3581,19 +3580,24 @@ resolveExplicitSpecifier(Sema &S, FunctionDecl *Specialization,
35813580
if (!Expr->isValueDependent()) {
35823581
return Sema::TDK_Success;
35833582
}
3584-
// TemplateDeclInstantiator::InitFunctionInstantiation set the
3585-
// ActiveInstType to TemplateInstantiation, but we need
3586-
// to enable SFINAE when instantiating an explicit specifier.
3583+
// The `InstantiatingTemplate` here is used to restore `ActiveInstType` to
3584+
// `DeducedTemplateArgumentSubstitution` because ActiveInstType was set to
3585+
// `TemplateInstantiation` in
3586+
// `TemplateDeclInstantiator::InitFunctionInstantiation`. The real depth of
3587+
// instantiation should be the same as the depth in
3588+
// `FinishTemplateArgumentDeduction`.
3589+
// So we don't check `InstantiatingTemplate::IsValid` here.
35873590
Sema::InstantiatingTemplate Inst(
35883591
S, Info.getLocation(), FunctionTemplate, DeducedArgs,
35893592
Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3593+
Sema::SFINAETrap Trap(S);
35903594
const auto Instantiated = S.instantiateExplicitSpecifier(SubstArgs, ES);
3591-
if (Instantiated.isInvalid()) {
3595+
if (Instantiated.isInvalid() || Trap.hasErrorOccurred()) {
35923596
Specialization->setInvalidDecl(true);
3593-
return clang::Sema::TDK_SubstitutionFailure;
3597+
return Sema::TDK_SubstitutionFailure;
35943598
}
35953599
SetExplicitSpecifier(Specialization, Instantiated);
3596-
return clang::Sema::TDK_Success;
3600+
return Sema::TDK_Success;
35973601
}
35983602

35993603
/// Finish template argument deduction for a function template,
@@ -3725,13 +3729,13 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
37253729
}
37263730
}
37273731

3728-
// We skipped the instantiation of the explicit-specifier during subst the
3729-
// FD before. So we try to instantiate it back if the `Specialization` is a
3730-
// constructor or a conversion.
3732+
// We skipped the instantiation of the explicit-specifier during the
3733+
// substitution of `FD` before. So, we try to instantiate it back if
3734+
// `Specialization` is either a constructor or a conversion function.
37313735
if (isa<CXXConstructorDecl, CXXConversionDecl>(Specialization)) {
3732-
if (TDK_Success !=
3733-
resolveExplicitSpecifier(*this, Specialization, SubstArgs, Info,
3734-
FunctionTemplate, DeducedArgs)) {
3736+
if (TDK_Success != instantiateExplicitSpecifierDeferred(
3737+
*this, Specialization, SubstArgs, Info,
3738+
FunctionTemplate, DeducedArgs)) {
37353739
return TDK_SubstitutionFailure;
37363740
}
37373741
}

0 commit comments

Comments
 (0)