@@ -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 {
@@ -7989,15 +7990,20 @@ void Sema::AddTemplateOverloadCandidate(
7989
7990
if (!CandidateSet.isNewCandidate(FunctionTemplate, PO))
7990
7991
return;
7991
7992
7993
+ bool DependentExplicitSpecifier = hasDependentExplicit(FunctionTemplate);
7994
+
7992
7995
if (ExplicitTemplateArgs ||
7993
7996
!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
7994
7997
(isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl()) &&
7995
- hasDependentExplicit(FunctionTemplate) )) {
7998
+ DependentExplicitSpecifier )) {
7996
7999
7997
8000
AddTemplateOverloadCandidateImmediately(
7998
8001
*this, CandidateSet, FunctionTemplate, FoundDecl, ExplicitTemplateArgs,
7999
8002
Args, SuppressUserConversions, PartialOverloading, AllowExplicit,
8000
8003
IsADLCandidate, PO, AggregateCandidateDeduction);
8004
+
8005
+ if (DependentExplicitSpecifier)
8006
+ CandidateSet.DisableResolutionByPerfectCandidate();
8001
8007
return;
8002
8008
}
8003
8009
@@ -8382,13 +8388,15 @@ void Sema::AddTemplateConversionCandidate(
8382
8388
return;
8383
8389
8384
8390
if (!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
8385
- hasDependentExplicit(FunctionTemplate)) {
8386
-
8391
+ CandidateSet.getKind() ==
8392
+ OverloadCandidateSet::CSK_InitByUserDefinedConversion ||
8393
+ CandidateSet.getKind() == OverloadCandidateSet::CSK_InitByConstructor) {
8387
8394
AddTemplateConversionCandidateImmediately(
8388
8395
*this, CandidateSet, FunctionTemplate, FoundDecl, ActingDC, From,
8389
8396
ToType, AllowObjCConversionOnExplicit, AllowExplicit,
8390
8397
AllowResultConversion);
8391
8398
8399
+ CandidateSet.DisableResolutionByPerfectCandidate();
8392
8400
return;
8393
8401
}
8394
8402
@@ -11028,6 +11036,7 @@ void OverloadCandidateSet::AddDeferredTemplateCandidate(
11028
11036
Args,
11029
11037
IsADLCandidate,
11030
11038
PO};
11039
+
11031
11040
HasDeferredTemplateConstructors |=
11032
11041
isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl());
11033
11042
}
@@ -11199,19 +11208,19 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
11199
11208
11200
11209
assert(shouldDeferTemplateArgumentDeduction(S.getLangOpts()) ||
11201
11210
DeferredCandidatesCount == 0 &&
11202
- "Unexpected deferred template candidate ");
11211
+ "Unexpected deferred template candidates ");
11203
11212
11204
- bool TwoPhaseResolution = DeferredCandidatesCount != 0;
11213
+ bool TwoPhaseResolution =
11214
+ DeferredCandidatesCount != 0 && !ResolutionByPerfectCandidateIsDisabled;
11205
11215
11206
11216
if (TwoPhaseResolution) {
11207
11217
11208
11218
PerfectViableFunction(S, Loc, Best);
11209
11219
if (Best != end())
11210
11220
return ResultForBestCandidate(Best);
11211
-
11212
- InjectNonDeducedTemplateCandidates(S);
11213
11221
}
11214
11222
11223
+ InjectNonDeducedTemplateCandidates(S);
11215
11224
return BestViableFunctionImpl(S, Loc, Best);
11216
11225
}
11217
11226
@@ -11220,8 +11229,10 @@ void OverloadCandidateSet::PerfectViableFunction(
11220
11229
11221
11230
Best = end();
11222
11231
for (auto It = begin(); It != end(); ++It) {
11232
+
11223
11233
if (!It->isPerfectMatch(S.getASTContext()))
11224
11234
continue;
11235
+
11225
11236
// We found a suitable conversion function
11226
11237
// but if there is a template constructor in the target class
11227
11238
// we might prefer that instead.
@@ -11246,6 +11257,7 @@ void OverloadCandidateSet::PerfectViableFunction(
11246
11257
Best = It;
11247
11258
continue;
11248
11259
}
11260
+ // ambiguous
11249
11261
Best = end();
11250
11262
break;
11251
11263
}
0 commit comments