@@ -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 {
@@ -7985,15 +7986,20 @@ void Sema::AddTemplateOverloadCandidate(
7985
7986
if (!CandidateSet.isNewCandidate(FunctionTemplate, PO))
7986
7987
return;
7987
7988
7989
+ bool DependentExplicitSpecifier = hasDependentExplicit(FunctionTemplate);
7990
+
7988
7991
if (ExplicitTemplateArgs ||
7989
7992
!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
7990
7993
(isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl()) &&
7991
- hasDependentExplicit(FunctionTemplate) )) {
7994
+ DependentExplicitSpecifier )) {
7992
7995
7993
7996
AddTemplateOverloadCandidateImmediately(
7994
7997
*this, CandidateSet, FunctionTemplate, FoundDecl, ExplicitTemplateArgs,
7995
7998
Args, SuppressUserConversions, PartialOverloading, AllowExplicit,
7996
7999
IsADLCandidate, PO, AggregateCandidateDeduction);
8000
+
8001
+ if (DependentExplicitSpecifier)
8002
+ CandidateSet.DisableResolutionByPerfectCandidate();
7997
8003
return;
7998
8004
}
7999
8005
@@ -8378,13 +8384,15 @@ void Sema::AddTemplateConversionCandidate(
8378
8384
return;
8379
8385
8380
8386
if (!CandidateSet.shouldDeferTemplateArgumentDeduction(getLangOpts()) ||
8381
- hasDependentExplicit(FunctionTemplate)) {
8382
-
8387
+ CandidateSet.getKind() ==
8388
+ OverloadCandidateSet::CSK_InitByUserDefinedConversion ||
8389
+ CandidateSet.getKind() == OverloadCandidateSet::CSK_InitByConstructor) {
8383
8390
AddTemplateConversionCandidateImmediately(
8384
8391
*this, CandidateSet, FunctionTemplate, FoundDecl, ActingDC, From,
8385
8392
ToType, AllowObjCConversionOnExplicit, AllowExplicit,
8386
8393
AllowResultConversion);
8387
8394
8395
+ CandidateSet.DisableResolutionByPerfectCandidate();
8388
8396
return;
8389
8397
}
8390
8398
@@ -11024,6 +11032,7 @@ void OverloadCandidateSet::AddDeferredTemplateCandidate(
11024
11032
Args,
11025
11033
IsADLCandidate,
11026
11034
PO};
11035
+
11027
11036
HasDeferredTemplateConstructors |=
11028
11037
isa<CXXConstructorDecl>(FunctionTemplate->getTemplatedDecl());
11029
11038
}
@@ -11195,19 +11204,19 @@ OverloadingResult OverloadCandidateSet::BestViableFunction(Sema &S,
11195
11204
11196
11205
assert(shouldDeferTemplateArgumentDeduction(S.getLangOpts()) ||
11197
11206
DeferredCandidatesCount == 0 &&
11198
- "Unexpected deferred template candidate ");
11207
+ "Unexpected deferred template candidates ");
11199
11208
11200
- bool TwoPhaseResolution = DeferredCandidatesCount != 0;
11209
+ bool TwoPhaseResolution =
11210
+ DeferredCandidatesCount != 0 && !ResolutionByPerfectCandidateIsDisabled;
11201
11211
11202
11212
if (TwoPhaseResolution) {
11203
11213
11204
11214
PerfectViableFunction(S, Loc, Best);
11205
11215
if (Best != end())
11206
11216
return ResultForBestCandidate(Best);
11207
-
11208
- InjectNonDeducedTemplateCandidates(S);
11209
11217
}
11210
11218
11219
+ InjectNonDeducedTemplateCandidates(S);
11211
11220
return BestViableFunctionImpl(S, Loc, Best);
11212
11221
}
11213
11222
@@ -11216,8 +11225,10 @@ void OverloadCandidateSet::PerfectViableFunction(
11216
11225
11217
11226
Best = end();
11218
11227
for (auto It = begin(); It != end(); ++It) {
11228
+
11219
11229
if (!It->isPerfectMatch(S.getASTContext()))
11220
11230
continue;
11231
+
11221
11232
// We found a suitable conversion function
11222
11233
// but if there is a template constructor in the target class
11223
11234
// we might prefer that instead.
@@ -11242,6 +11253,7 @@ void OverloadCandidateSet::PerfectViableFunction(
11242
11253
Best = It;
11243
11254
continue;
11244
11255
}
11256
+ // ambiguous
11245
11257
Best = end();
11246
11258
break;
11247
11259
}
0 commit comments