diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index b50ed6478e4b48..dfae7020921078 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2273,9 +2273,11 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl( // Filter out previous declarations that don't match the scope. The only // effect this has is to remove declarations found in inline namespaces // for friend declarations with unqualified names. - SemaRef.FilterLookupForScope(Previous, DC, /*Scope*/ nullptr, - /*ConsiderLinkage*/ true, - QualifierLoc.hasQualifier()); + if (isFriend && !QualifierLoc && !FunctionTemplate) { + SemaRef.FilterLookupForScope(Previous, DC, /*Scope=*/ nullptr, + /*ConsiderLinkage=*/ true, + QualifierLoc.hasQualifier()); + } } // Per [temp.inst], default arguments in function declarations at local scope