[cfe-commits] r116529 - in /cfe/trunk: lib/Sema/SemaDeclCXX.cpp test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp

John McCall rjmccall at apple.com
Thu Oct 14 15:22:28 PDT 2010


Author: rjmccall
Date: Thu Oct 14 17:22:28 2010
New Revision: 116529

URL: http://llvm.org/viewvc/llvm-project?rev=116529&view=rev
Log:
template-ids are looked up differently in friend declarations.


Modified:
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=116529&r1=116528&r2=116529&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Oct 14 17:22:28 2010
@@ -6384,6 +6384,7 @@
     //   declaration, if there is no prior declaration, the program is
     //   ill-formed.
     bool isLocal = cast<CXXRecordDecl>(CurContext)->isLocalClass();
+    bool isTemplateId = D.getName().getKind() == UnqualifiedId::IK_TemplateId;
 
     // Find the appropriate context according to the above.
     DC = CurContext;
@@ -6404,7 +6405,11 @@
       if (isLocal || !Previous.empty())
         break;
 
-      if (DC->isFileContext()) break;
+      if (isTemplateId) {
+        if (isa<TranslationUnitDecl>(DC)) break;
+      } else {
+        if (DC->isFileContext()) break;
+      }
       DC = DC->getParent();
     }
 

Modified: cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp?rev=116529&r1=116528&r2=116529&view=diff
==============================================================================
--- cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp (original)
+++ cfe/trunk/test/CXX/dcl.dcl/basic.namespace/namespace.def/namespace.memdef/p3.cpp Thu Oct 14 17:22:28 2010
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only %s -verify
 
 // C++'0x [namespace.memdef] p3:
 //   Every name first declared in a namespace is a member of that namespace. If
@@ -66,3 +66,28 @@
 }
 
 // FIXME: Woefully inadequate for testing
+
+// Friends declared as template-ids aren't subject to the restriction
+// on innermost namespaces.
+// rdar://problem/8552377
+namespace test5 {
+  template <class T> void f(T);  
+  namespace ns {
+    class A {
+      friend void f<int>(int);
+      static void foo(); // expected-note 2 {{declared private here}}
+    };
+
+    // Note that this happens without instantiation.
+    template <class T> void f(T) {
+      A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
+    }
+  }
+
+  template <class T> void f(T) {
+    ns::A::foo(); // expected-error {{'foo' is a private member of 'test5::ns::A'}}
+  }
+
+  template void f<int>(int);
+  template void f<long>(long); //expected-note {{instantiation}}
+}





More information about the cfe-commits mailing list