Skip to content

Commit a3cd1dc

Browse files
committed
[FOLD] use local UnresolvedSet to store candidates
1 parent 8d9a4f0 commit a3cd1dc

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7964,8 +7964,9 @@ NamedDecl *Sema::ActOnVariableDeclarator(
79647964
D.setRedeclaration(CheckVariableDeclaration(NewVD, Previous));
79657965
} else {
79667966
// If this is an explicit specialization of a static data member, check it.
7967-
if (IsMemberSpecialization && !IsVariableTemplateSpecialization &&
7968-
!NewVD->isInvalidDecl() && CheckMemberSpecialization(NewVD, Previous))
7967+
if (IsMemberSpecialization && !IsVariableTemplate &&
7968+
!IsVariableTemplateSpecialization && !NewVD->isInvalidDecl() &&
7969+
CheckMemberSpecialization(NewVD, Previous))
79697970
NewVD->setInvalidDecl();
79707971

79717972
// Merge the decl with the existing one if appropriate.
@@ -10466,7 +10467,8 @@ Sema::ActOnFunctionDeclarator(Scope *S, Declarator &D, DeclContext *DC,
1046610467
Previous))
1046710468
NewFD->setInvalidDecl();
1046810469
}
10469-
} else if (isMemberSpecialization && isa<CXXMethodDecl>(NewFD)) {
10470+
} else if (isMemberSpecialization && !FunctionTemplate &&
10471+
isa<CXXMethodDecl>(NewFD)) {
1047010472
if (CheckMemberSpecialization(NewFD, Previous))
1047110473
NewFD->setInvalidDecl();
1047210474
}

clang/lib/Sema/SemaTemplate.cpp

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9051,7 +9051,8 @@ bool Sema::CheckFunctionTemplateSpecialization(
90519051

90529052
bool
90539053
Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
9054-
assert(!isa<TemplateDecl>(Member) && "Only for non-template members");
9054+
assert(!Member->isTemplateDecl() && !Member->getDescribedTemplate() &&
9055+
"Only for non-template members");
90559056

90569057
// Try to find the member we are instantiating.
90579058
NamedDecl *FoundInstantiation = nullptr;
@@ -9062,50 +9063,46 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
90629063
if (Previous.empty()) {
90639064
// Nowhere to look anyway.
90649065
} else if (FunctionDecl *Function = dyn_cast<FunctionDecl>(Member)) {
9065-
LookupResult::Filter Filter = Previous.makeFilter();
9066-
while (Filter.hasNext()) {
9067-
auto *Method =
9068-
dyn_cast<CXXMethodDecl>(Filter.next()->getUnderlyingDecl());
9069-
// Discard any candidates that aren't member functions.
9070-
if (!Method) {
9071-
Filter.erase();
9066+
UnresolvedSet<8> Candidates;
9067+
for (NamedDecl *Candidate : Previous) {
9068+
auto *Method = dyn_cast<CXXMethodDecl>(Candidate->getUnderlyingDecl());
9069+
// Ignore any candidates that aren't member functions.
9070+
if (!Method)
90729071
continue;
9073-
}
90749072

90759073
QualType Adjusted = Function->getType();
90769074
if (!hasExplicitCallingConv(Adjusted))
90779075
Adjusted = adjustCCAndNoReturn(Adjusted, Method->getType());
9078-
// Discard any candidates with the wrong type.
9076+
// Ignore any candidates with the wrong type.
90799077
// This doesn't handle deduced return types, but both function
90809078
// declarations should be undeduced at this point.
9081-
if (!Context.hasSameType(Adjusted, Method->getType())) {
9082-
Filter.erase();
9079+
// FIXME: The exception specification should probably be ignored when
9080+
// comparing the types.
9081+
if (!Context.hasSameType(Adjusted, Method->getType()))
90839082
continue;
9084-
}
90859083

9086-
// Discard any candidates with unsatisfied constraints.
9084+
// Ignore any candidates with unsatisfied constraints.
90879085
if (ConstraintSatisfaction Satisfaction;
90889086
Method->getTrailingRequiresClause() &&
90899087
(CheckFunctionConstraints(Method, Satisfaction,
90909088
/*UsageLoc=*/Member->getLocation(),
90919089
/*ForOverloadResolution=*/true) ||
9092-
!Satisfaction.IsSatisfied)) {
9093-
Filter.erase();
9090+
!Satisfaction.IsSatisfied))
90949091
continue;
9095-
}
9092+
9093+
Candidates.addDecl(Candidate);
90969094
}
9097-
Filter.done();
90989095

9099-
// If we have no candidates left after filtering, we are done.
9100-
if (Previous.empty())
9096+
// If we have no viable candidates left after filtering, we are done.
9097+
if (Candidates.empty())
91019098
return false;
91029099

91039100
// Find the function that is more constrained than every other function it
91049101
// has been compared to.
9105-
UnresolvedSetIterator Best = Previous.begin();
9102+
UnresolvedSetIterator Best = Candidates.begin();
91069103
CXXMethodDecl *BestMethod = nullptr;
9107-
for (UnresolvedSetIterator I = Previous.begin(), E = Previous.end(); I != E;
9108-
++I) {
9104+
for (UnresolvedSetIterator I = Candidates.begin(), E = Candidates.end();
9105+
I != E; ++I) {
91099106
auto *Method = cast<CXXMethodDecl>(I->getUnderlyingDecl());
91109107
if (I == Best ||
91119108
getMoreConstrainedFunction(Method, BestMethod) == Method) {
@@ -9119,10 +9116,10 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
91199116
InstantiatedFrom = BestMethod->getInstantiatedFromMemberFunction();
91209117
MSInfo = BestMethod->getMemberSpecializationInfo();
91219118

9122-
// Make sure the best candidate is more specialized than all of the others.
9119+
// Make sure the best candidate is more constrained than all of the others.
91239120
bool Ambiguous = false;
9124-
for (UnresolvedSetIterator I = Previous.begin(), E = Previous.end(); I != E;
9125-
++I) {
9121+
for (UnresolvedSetIterator I = Candidates.begin(), E = Candidates.end();
9122+
I != E; ++I) {
91269123
auto *Method = cast<CXXMethodDecl>(I->getUnderlyingDecl());
91279124
if (I != Best &&
91289125
getMoreConstrainedFunction(Method, BestMethod) != BestMethod) {
@@ -9134,7 +9131,7 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
91349131
if (Ambiguous) {
91359132
Diag(Member->getLocation(), diag::err_function_member_spec_ambiguous)
91369133
<< Member << (InstantiatedFrom ? InstantiatedFrom : Instantiation);
9137-
for (NamedDecl *Candidate : Previous) {
9134+
for (NamedDecl *Candidate : Candidates) {
91389135
Candidate = Candidate->getUnderlyingDecl();
91399136
Diag(Candidate->getLocation(), diag::note_function_member_spec_matched)
91409137
<< Candidate;

0 commit comments

Comments
 (0)