From d89c6530fdb57da31f4750bf941a0e4a090c4474 Mon Sep 17 00:00:00 2001 From: Shafik Yaghmour Date: Fri, 7 Apr 2023 08:57:24 -0700 Subject: [PATCH] [Clang] Fix filtering of inline namespaces for friend functions PR D135370 implemented a performance improvement but it restricted the filtering of declaration from inline namespace too much. In particular it did not filter for the function template case. This led to a regression and this PR removes that check. This fixes: https://github.com/llvm/llvm-project/issues/61851 Differential Revision: https://reviews.llvm.org/D147762 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 2 +- clang/test/SemaTemplate/friend.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index ba64591..f941882 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2293,7 +2293,7 @@ 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. - 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 index 1427db0..b039f10 100644 --- a/clang/test/SemaTemplate/friend.cpp +++ b/clang/test/SemaTemplate/friend.cpp @@ -148,3 +148,21 @@ namespace PR42513_comment3 { 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; +} +} -- 2.7.4