@@ -1127,6 +1127,7 @@ void OverloadCandidateSet::clear(CandidateSetKind CSK) {
1127
1127
FirstDeferredCandidate = nullptr;
1128
1128
DeferredCandidatesCount = 0;
1129
1129
HasDeferredTemplateConstructors = false;
1130
+ ResolutionByPerfectCandidateIsDisabled = false;
1130
1131
}
1131
1132
1132
1133
namespace {
@@ -7981,15 +7982,20 @@ void Sema::AddTemplateOverloadCandidate(
7981
7982
if (!CandidateSet.isNewCandidate(FunctionTemplate, PO))
7982
7983
return;
7983
7984
7985
+ bool DependentExplicitSpecifier = hasDependentExplicit(FunctionTemplate);
7986
+
7984
7987
if (ExplicitTemplateArgs ||
7985
7988
!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
7986
7989
(isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl()) &&
7987
- hasDependentExplicit(FunctionTemplate) )) {
7990
+ DependentExplicitSpecifier )) {
7988
7991
7989
7992
AddTemplateOverloadCandidateImmediately(
7990
7993
*this, CandidateSet, FunctionTemplate, FoundDecl, ExplicitTemplateArgs,
7991
7994
Args, SuppressUserConversions, PartialOverloading, AllowExplicit,
7992
7995
IsADLCandidate, PO, AggregateCandidateDeduction);
7996
+
7997
+ if (DependentExplicitSpecifier)
7998
+ CandidateSet.DisableResolutionByPerfectCandidate();
7993
7999
return;
7994
8000
}
7995
8001
@@ -8374,13 +8380,15 @@ void Sema::AddTemplateConversionCandidate(
8374
8380
return;
8375
8381
8376
8382
if (!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
8377
- hasDependentExplicit(FunctionTemplate)) {
8378
-
8383
+ CandidateSet.getKind() ==
8384
+ OverloadCandidateSet::CSK_InitByUserDefinedConversion ||
8385
+ CandidateSet.getKind() == OverloadCandidateSet::CSK_InitByConstructor) {
8379
8386
AddTemplateConversionCandidateImmediately(
8380
8387
*this, CandidateSet, FunctionTemplate, FoundDecl, ActingDC, From,
8381
8388
ToType, AllowObjCConversionOnExplicit, AllowExplicit,
8382
8389
AllowResultConversion);
8383
8390
8391
+ CandidateSet.DisableResolutionByPerfectCandidate();
8384
8392
return;
8385
8393
}
8386
8394
@@ -11020,6 +11028,7 @@ void OverloadCandidateSet::AddDeferredTemplateCandidate(
11020
11028
Args,
11021
11029
IsADLCandidate,
11022
11030
PO};
11031
+
11023
11032
HasDeferredTemplateConstructors |=
11024
11033
isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl());
11025
11034
}
@@ -11191,19 +11200,19 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
11191
11200
11192
11201
assert(shouldDeferTemplateArgumentDeduction(S.getLangOpts()) ||
11193
11202
DeferredCandidatesCount == 0 &&
11194
- "Unexpected deferred template candidate ");
11203
+ "Unexpected deferred template candidates ");
11195
11204
11196
- bool TwoPhaseResolution = DeferredCandidatesCount != 0;
11205
+ bool TwoPhaseResolution =
11206
+ DeferredCandidatesCount != 0 && !ResolutionByPerfectCandidateIsDisabled;
11197
11207
11198
11208
if (TwoPhaseResolution) {
11199
11209
11200
11210
PerfectViableFunction(S, Loc, Best);
11201
11211
if (Best != end())
11202
11212
return ResultForBestCandidate(Best);
11203
-
11204
- InjectNonDeducedTemplateCandidates(S);
11205
11213
}
11206
11214
11215
+ InjectNonDeducedTemplateCandidates(S);
11207
11216
return BestViableFunctionImpl(S, Loc, Best);
11208
11217
}
11209
11218
@@ -11212,8 +11221,10 @@ void OverloadCandidateSet::PerfectViableFunction(
11212
11221
11213
11222
Best = end();
11214
11223
for (auto It = begin(); It != end(); ++It) {
11224
+
11215
11225
if (!It->isPerfectMatch(S.getASTContext()))
11216
11226
continue;
11227
+
11217
11228
// We found a suitable conversion function
11218
11229
// but if there is a template constructor in the target class
11219
11230
// we might prefer that instead.
@@ -11238,6 +11249,7 @@ void OverloadCandidateSet::PerfectViableFunction(
11238
11249
Best = It;
11239
11250
continue;
11240
11251
}
11252
+ // ambiguous
11241
11253
Best = end();
11242
11254
break;
11243
11255
}
0 commit comments