[PATCH] D147762: [Clang] Fix filtering of inline namespaces for friend functions

Shafik Yaghmour via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 6 21:10:25 PDT 2023


shafik created this revision.
shafik added reviewers: aaron.ballman, erichkeane, troyj, rsmith, bruno.
Herald added a project: All.
shafik requested review of this revision.

PR D135370 <https://reviews.llvm.org/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


https://reviews.llvm.org/D147762

Files:
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/SemaTemplate/friend.cpp


Index: clang/test/SemaTemplate/friend.cpp
===================================================================
--- clang/test/SemaTemplate/friend.cpp
+++ clang/test/SemaTemplate/friend.cpp
@@ -148,3 +148,21 @@
   template struct T<X1>;
   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 <typename T>
+class Bar {
+  template <typename U>
+  friend void foo(U &&arg) {} // no diagnostic expected
+};
+}
+
+void foobar() {
+  A::Bar<int> b;
+}
+}
Index: clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ 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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147762.511603.patch
Type: text/x-patch
Size: 1392 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230407/2501856d/attachment.bin>


More information about the cfe-commits mailing list