[clang] 04ba185 - PR37556: Don't diagnose conflicts between instantiated unqualified

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 23:26:41 PDT 2020


Author: Richard Smith
Date: 2020-08-24T23:26:15-07:00
New Revision: 04ba18563390ec87400fa068a9b4981b235ebaa6

URL: https://github.com/llvm/llvm-project/commit/04ba18563390ec87400fa068a9b4981b235ebaa6
DIFF: https://github.com/llvm/llvm-project/commit/04ba18563390ec87400fa068a9b4981b235ebaa6.diff

LOG: PR37556: Don't diagnose conflicts between instantiated unqualified
friend declarations and declarations found in inline namespaces within
the target context.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 965f1626ff2e..a5100dc99fcd 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -2053,6 +2053,13 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(
     // typedef (C++ [dcl.typedef]p4).
     if (Previous.isSingleTagDecl())
       Previous.clear();
+
+    // 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());
   }
 
   SemaRef.CheckFunctionDeclaration(/*Scope*/ nullptr, Function, Previous,

diff  --git a/clang/test/SemaTemplate/friend.cpp b/clang/test/SemaTemplate/friend.cpp
index 777682be3f1b..283c7732ccff 100644
--- a/clang/test/SemaTemplate/friend.cpp
+++ b/clang/test/SemaTemplate/friend.cpp
@@ -122,3 +122,22 @@ namespace qualified_friend_finds_nothing {
   namespace N { void f(int); }
   B<int> bi; // ok?!
 }
+
+namespace PR37556 {
+  inline namespace N { int x1, x2, y1, y2; } // expected-note 2{{previous}}
+  struct X {
+    friend void x1(int);
+    friend void PR37556::x2(int); // expected-error {{
diff erent kind}}
+  };
+  template<typename T> struct Y {
+    friend void y1(T);
+    friend void PR37556::y2(T); // expected-error {{
diff erent kind}}
+  };
+  template struct Y<int>;
+  template<typename T> struct Z {
+    friend void z1(T);
+    friend void PR37556::z2(T); // expected-error {{does not match any}}
+  };
+  inline namespace N { int z1, z2; }
+  template struct Z<int>;
+}


        


More information about the cfe-commits mailing list