@@ -9051,7 +9051,8 @@ bool Sema::CheckFunctionTemplateSpecialization(
9051
9051
9052
9052
bool
9053
9053
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" );
9055
9056
9056
9057
// Try to find the member we are instantiating.
9057
9058
NamedDecl *FoundInstantiation = nullptr ;
@@ -9062,50 +9063,46 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
9062
9063
if (Previous.empty ()) {
9063
9064
// Nowhere to look anyway.
9064
9065
} 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)
9072
9071
continue ;
9073
- }
9074
9072
9075
9073
QualType Adjusted = Function->getType ();
9076
9074
if (!hasExplicitCallingConv (Adjusted))
9077
9075
Adjusted = adjustCCAndNoReturn (Adjusted, Method->getType ());
9078
- // Discard any candidates with the wrong type.
9076
+ // Ignore any candidates with the wrong type.
9079
9077
// This doesn't handle deduced return types, but both function
9080
9078
// 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 ()))
9083
9082
continue ;
9084
- }
9085
9083
9086
- // Discard any candidates with unsatisfied constraints.
9084
+ // Ignore any candidates with unsatisfied constraints.
9087
9085
if (ConstraintSatisfaction Satisfaction;
9088
9086
Method->getTrailingRequiresClause () &&
9089
9087
(CheckFunctionConstraints (Method, Satisfaction,
9090
9088
/* UsageLoc=*/ Member->getLocation (),
9091
9089
/* ForOverloadResolution=*/ true ) ||
9092
- !Satisfaction.IsSatisfied )) {
9093
- Filter.erase ();
9090
+ !Satisfaction.IsSatisfied ))
9094
9091
continue ;
9095
- }
9092
+
9093
+ Candidates.addDecl (Candidate);
9096
9094
}
9097
- Filter.done ();
9098
9095
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 ())
9101
9098
return false ;
9102
9099
9103
9100
// Find the function that is more constrained than every other function it
9104
9101
// has been compared to.
9105
- UnresolvedSetIterator Best = Previous .begin ();
9102
+ UnresolvedSetIterator Best = Candidates .begin ();
9106
9103
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) {
9109
9106
auto *Method = cast<CXXMethodDecl>(I->getUnderlyingDecl ());
9110
9107
if (I == Best ||
9111
9108
getMoreConstrainedFunction (Method, BestMethod) == Method) {
@@ -9119,10 +9116,10 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
9119
9116
InstantiatedFrom = BestMethod->getInstantiatedFromMemberFunction ();
9120
9117
MSInfo = BestMethod->getMemberSpecializationInfo ();
9121
9118
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.
9123
9120
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) {
9126
9123
auto *Method = cast<CXXMethodDecl>(I->getUnderlyingDecl ());
9127
9124
if (I != Best &&
9128
9125
getMoreConstrainedFunction (Method, BestMethod) != BestMethod) {
@@ -9134,7 +9131,7 @@ Sema::CheckMemberSpecialization(NamedDecl *Member, LookupResult &Previous) {
9134
9131
if (Ambiguous) {
9135
9132
Diag (Member->getLocation (), diag::err_function_member_spec_ambiguous)
9136
9133
<< Member << (InstantiatedFrom ? InstantiatedFrom : Instantiation);
9137
- for (NamedDecl *Candidate : Previous ) {
9134
+ for (NamedDecl *Candidate : Candidates ) {
9138
9135
Candidate = Candidate->getUnderlyingDecl ();
9139
9136
Diag (Candidate->getLocation (), diag::note_function_member_spec_matched)
9140
9137
<< Candidate;
0 commit comments