diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2293,7 +2293,7 @@ // 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. - if (isFriend && !QualifierLoc && !FunctionTemplate) { + if (isFriend && !QualifierLoc) { SemaRef.FilterLookupForScope(Previous, DC, /*Scope=*/ nullptr, /*ConsiderLinkage=*/ true, QualifierLoc.hasQualifier()); diff --git a/clang/test/SemaTemplate/friend.cpp b/clang/test/SemaTemplate/friend.cpp --- a/clang/test/SemaTemplate/friend.cpp +++ b/clang/test/SemaTemplate/friend.cpp @@ -148,3 +148,21 @@ template struct T; int n = f((X1*)nullptr); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'std::nullptr_t'}} } + +namespace GH61851 { +namespace A { +inline namespace B { + inline constexpr struct {} foo; +} + +template +class Bar { + template + friend void foo(U &&arg) {} // no diagnostic expected +}; +} + +void foobar() { + A::Bar b; +} +}