@@ -5453,7 +5453,7 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
5453
5453
// is used.
5454
5454
if (DeduceTemplateArgumentsByTypeMatch (
5455
5455
S, TemplateParams, FD2->getType (), FD1->getType (), Info, Deduced,
5456
- TDF_None ,
5456
+ TDF_AllowCompatibleFunctionType ,
5457
5457
/* PartialOrdering=*/ true ) != TemplateDeductionResult::Success)
5458
5458
return false ;
5459
5459
break ;
@@ -5485,20 +5485,40 @@ static bool isAtLeastAsSpecializedAs(Sema &S, SourceLocation Loc,
5485
5485
switch (TPOC) {
5486
5486
case TPOC_Call:
5487
5487
for (unsigned I = 0 , N = Args2.size (); I != N; ++I)
5488
- ::MarkUsedTemplateParameters (S.Context, Args2[I], false ,
5489
- TemplateParams->getDepth (),
5490
- UsedParameters);
5488
+ ::MarkUsedTemplateParameters (S.Context, Args2[I], /* OnlyDeduced=*/ false ,
5489
+ TemplateParams->getDepth (), UsedParameters);
5491
5490
break ;
5492
5491
5493
5492
case TPOC_Conversion:
5494
- ::MarkUsedTemplateParameters (S.Context, Proto2->getReturnType (), false,
5493
+ ::MarkUsedTemplateParameters (S.Context, Proto2->getReturnType (),
5494
+ /* OnlyDeduced=*/ false,
5495
5495
TemplateParams->getDepth(), UsedParameters);
5496
5496
break ;
5497
5497
5498
5498
case TPOC_Other:
5499
- ::MarkUsedTemplateParameters (S.Context, FD2->getType (), false,
5500
- TemplateParams->getDepth(),
5501
- UsedParameters);
5499
+ // We do not deduce template arguments from the exception specification
5500
+ // when determining the primary template of a function template
5501
+ // specialization or when taking the address of a function template.
5502
+ // Therefore, we do not mark template parameters in the exception
5503
+ // specification as used during partial ordering to prevent the following
5504
+ // from being ambiguous:
5505
+ //
5506
+ // template<typename T, typename U>
5507
+ // void f(U) noexcept(noexcept(T())); // #1
5508
+ //
5509
+ // template<typename T>
5510
+ // void f(T*) noexcept; // #2
5511
+ //
5512
+ // template<>
5513
+ // void f<int>(int*) noexcept; // explicit specialization of #2
5514
+ //
5515
+ // Although there is no corresponding wording in the standard, this seems
5516
+ // to be the intended behavior given the definition of
5517
+ // 'deduction substitution loci' in [temp.deduct].
5518
+ ::MarkUsedTemplateParameters (
5519
+ S.Context,
5520
+ S.Context.getFunctionTypeWithExceptionSpec(FD2->getType (), EST_None),
5521
+ /* OnlyDeduced=*/ false, TemplateParams->getDepth(), UsedParameters);
5502
5522
break ;
5503
5523
}
5504
5524
0 commit comments