@@ -8957,7 +8957,8 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
8957
8957
// A member function [...] of a class template can be explicitly
8958
8958
// instantiated from the member definition associated with its class
8959
8959
// template.
8960
- UnresolvedSet<8 > Matches;
8960
+ UnresolvedSet<8 > TemplateMatches;
8961
+ FunctionDecl *NonTemplateMatch = nullptr ;
8961
8962
AttributeList *Attr = D.getDeclSpec ().getAttributes ().getList ();
8962
8963
TemplateSpecCandidateSet FailedCandidates (D.getIdentifierLoc ());
8963
8964
for (LookupResult::iterator P = Previous.begin (), PEnd = Previous.end ();
@@ -8968,11 +8969,13 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
8968
8969
QualType Adjusted = adjustCCAndNoReturn (R, Method->getType (),
8969
8970
/* AdjustExceptionSpec*/ true );
8970
8971
if (Context.hasSameUnqualifiedType (Method->getType (), Adjusted)) {
8971
- Matches.clear ();
8972
-
8973
- Matches.addDecl (Method, P.getAccess ());
8974
- if (Method->getTemplateSpecializationKind () == TSK_Undeclared)
8975
- break ;
8972
+ if (Method->getPrimaryTemplate ()) {
8973
+ TemplateMatches.addDecl (Method, P.getAccess ());
8974
+ } else {
8975
+ // FIXME: Can this assert ever happen? Needs a test.
8976
+ assert (!NonTemplateMatch && " Multiple NonTemplateMatches" );
8977
+ NonTemplateMatch = Method;
8978
+ }
8976
8979
}
8977
8980
}
8978
8981
}
@@ -9011,22 +9014,25 @@ DeclResult Sema::ActOnExplicitInstantiation(Scope *S,
9011
9014
continue ;
9012
9015
}
9013
9016
9014
- Matches .addDecl (Specialization, P.getAccess ());
9017
+ TemplateMatches .addDecl (Specialization, P.getAccess ());
9015
9018
}
9016
9019
9017
- // Find the most specialized function template specialization.
9018
- UnresolvedSetIterator Result = getMostSpecialized (
9019
- Matches.begin (), Matches.end (), FailedCandidates,
9020
- D.getIdentifierLoc (),
9021
- PDiag (diag::err_explicit_instantiation_not_known) << Name,
9022
- PDiag (diag::err_explicit_instantiation_ambiguous) << Name,
9023
- PDiag (diag::note_explicit_instantiation_candidate));
9024
-
9025
- if (Result == Matches.end ())
9026
- return true ;
9020
+ FunctionDecl *Specialization = NonTemplateMatch;
9021
+ if (!Specialization) {
9022
+ // Find the most specialized function template specialization.
9023
+ UnresolvedSetIterator Result = getMostSpecialized (
9024
+ TemplateMatches.begin (), TemplateMatches.end (), FailedCandidates,
9025
+ D.getIdentifierLoc (),
9026
+ PDiag (diag::err_explicit_instantiation_not_known) << Name,
9027
+ PDiag (diag::err_explicit_instantiation_ambiguous) << Name,
9028
+ PDiag (diag::note_explicit_instantiation_candidate));
9029
+
9030
+ if (Result == TemplateMatches.end ())
9031
+ return true ;
9027
9032
9028
- // Ignore access control bits, we don't need them for redeclaration checking.
9029
- FunctionDecl *Specialization = cast<FunctionDecl>(*Result);
9033
+ // Ignore access control bits, we don't need them for redeclaration checking.
9034
+ Specialization = cast<FunctionDecl>(*Result);
9035
+ }
9030
9036
9031
9037
// C++11 [except.spec]p4
9032
9038
// In an explicit instantiation an exception-specification may be specified,
0 commit comments