@@ -3557,50 +3557,44 @@ static unsigned getPackIndexForParam(Sema &S,
3557
3557
// we try to instantiate and update its explicit specifier after constraint
3558
3558
// checking.
3559
3559
static Sema::TemplateDeductionResult
3560
- tryInstantiateExplicitSpecifier (Sema &S, FunctionDecl *Specialization,
3561
- const MultiLevelTemplateArgumentList &SubstArgs,
3562
- TemplateDeductionInfo &Info,
3563
- FunctionTemplateDecl *FunctionTemplate,
3564
- ArrayRef<TemplateArgument> DeducedArgs) {
3565
-
3566
- const auto TryInstantiateExplicitSpecifierForSingleDecl =
3567
- [&](auto *ExplicitDecl) {
3568
- ExplicitSpecifier ExplicitSpecifier =
3569
- ExplicitDecl->getExplicitSpecifier ();
3570
- Expr *const Expr = ExplicitSpecifier.getExpr ();
3571
- if (!Expr) {
3572
- return Sema::TDK_Success;
3573
- }
3574
- if (!Expr->isValueDependent ()) {
3575
- return Sema::TDK_Success;
3576
- }
3577
- // TemplateDeclInstantiator::InitFunctionInstantiation set the
3578
- // ActiveInstType to TemplateInstantiation, but we need
3579
- // to enable SFINAE when instantiating explicit specifier.
3580
- Sema::InstantiatingTemplate Inst (
3581
- S, Info.getLocation (), FunctionTemplate, DeducedArgs,
3582
- Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution,
3583
- Info);
3584
- const auto Instantiated =
3585
- S.instantiateExplicitSpecifier (SubstArgs, ExplicitSpecifier);
3586
- if (Instantiated.isInvalid ()) {
3587
- ExplicitDecl->setInvalidDecl (true );
3588
- return clang::Sema::TDK_SubstitutionFailure;
3589
- }
3590
- ExplicitDecl->setExplicitSpecifier (Instantiated);
3591
- return clang::Sema::TDK_Success;
3592
- };
3593
- Sema::TemplateDeductionResult DeductionResult = clang::Sema::TDK_Success;
3594
- if (CXXConstructorDecl *ConstructorDecl =
3595
- dyn_cast_or_null<CXXConstructorDecl>(Specialization)) {
3596
- DeductionResult =
3597
- TryInstantiateExplicitSpecifierForSingleDecl (ConstructorDecl);
3598
- } else if (CXXConversionDecl *ConversionDecl =
3599
- dyn_cast_or_null<CXXConversionDecl>(Specialization)) {
3600
- DeductionResult =
3601
- TryInstantiateExplicitSpecifierForSingleDecl (ConversionDecl);
3602
- }
3603
- return DeductionResult;
3560
+ resolveExplicitSpecifier (Sema &S, FunctionDecl *Specialization,
3561
+ const MultiLevelTemplateArgumentList &SubstArgs,
3562
+ TemplateDeductionInfo &Info,
3563
+ FunctionTemplateDecl *FunctionTemplate,
3564
+ ArrayRef<TemplateArgument> DeducedArgs) {
3565
+ auto GetExplicitSpecifier = [](FunctionDecl *D) {
3566
+ return isa<CXXConstructorDecl>(D)
3567
+ ? cast<CXXConstructorDecl>(D)->getExplicitSpecifier ()
3568
+ : cast<CXXConversionDecl>(D)->getExplicitSpecifier ();
3569
+ };
3570
+ auto SetExplicitSpecifier = [](FunctionDecl *D, ExplicitSpecifier ES) {
3571
+ isa<CXXConstructorDecl>(D)
3572
+ ? cast<CXXConstructorDecl>(D)->setExplicitSpecifier (ES)
3573
+ : cast<CXXConversionDecl>(D)->setExplicitSpecifier (ES);
3574
+ };
3575
+
3576
+ ExplicitSpecifier ExplicitSpecifier = GetExplicitSpecifier (Specialization);
3577
+ Expr *const Expr = ExplicitSpecifier.getExpr ();
3578
+ if (!Expr) {
3579
+ return Sema::TDK_Success;
3580
+ }
3581
+ if (!Expr->isValueDependent ()) {
3582
+ return Sema::TDK_Success;
3583
+ }
3584
+ // TemplateDeclInstantiator::InitFunctionInstantiation set the
3585
+ // ActiveInstType to TemplateInstantiation, but we need
3586
+ // to enable SFINAE when instantiating an explicit specifier.
3587
+ Sema::InstantiatingTemplate Inst (
3588
+ S, Info.getLocation (), FunctionTemplate, DeducedArgs,
3589
+ Sema::CodeSynthesisContext::DeducedTemplateArgumentSubstitution, Info);
3590
+ const auto Instantiated =
3591
+ S.instantiateExplicitSpecifier (SubstArgs, ExplicitSpecifier);
3592
+ if (Instantiated.isInvalid ()) {
3593
+ Specialization->setInvalidDecl (true );
3594
+ return clang::Sema::TDK_SubstitutionFailure;
3595
+ }
3596
+ SetExplicitSpecifier (Specialization, Instantiated);
3597
+ return clang::Sema::TDK_Success;
3604
3598
}
3605
3599
3606
3600
// / Finish template argument deduction for a function template,
@@ -3733,12 +3727,14 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
3733
3727
}
3734
3728
3735
3729
// We skipped the instantiation of the explicit-specifier during subst the
3736
- // decl before. Now, we try to instantiate it back if the Specialization is a
3730
+ // FD before. So we try to instantiate it back if the ` Specialization` is a
3737
3731
// constructor or a conversion.
3738
- if (TDK_Success !=
3739
- tryInstantiateExplicitSpecifier (*this , Specialization, SubstArgs, Info,
3740
- FunctionTemplate, DeducedArgs)) {
3741
- return TDK_SubstitutionFailure;
3732
+ if (isa<CXXConstructorDecl, CXXConversionDecl>(Specialization)) {
3733
+ if (TDK_Success !=
3734
+ resolveExplicitSpecifier (*this , Specialization, SubstArgs, Info,
3735
+ FunctionTemplate, DeducedArgs)) {
3736
+ return TDK_SubstitutionFailure;
3737
+ }
3742
3738
}
3743
3739
3744
3740
if (OriginalCallArgs) {
0 commit comments