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

Douglas Gregor dgregor at apple.com
Sun Apr 18 10:37:40 PDT 2010


Author: dgregor
Date: Sun Apr 18 12:37:40 2010
New Revision: 101724

URL: http://llvm.org/viewvc/llvm-project?rev=101724&view=rev
Log:
C++ [namespace.memdef]p3 only applies when the friend is not named via
a qualified name. We weren't checking for an empty
nested-name-specifier when dealing with friend class templates
(although we were checking in the other places where we deal with this
paragraph). Fixes a Boost.Serialization showstopper.

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

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=101724&r1=101723&r2=101724&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Sun Apr 18 12:37:40 2010
@@ -801,22 +801,24 @@
     //   declared as a friend, and when the name of the friend class or 
     //   function is neither a qualified name nor a template-id, scopes outside
     //   the innermost enclosing namespace scope are not considered.
-    DeclContext *OutermostContext = CurContext;
-    while (!OutermostContext->isFileContext())
-      OutermostContext = OutermostContext->getLookupParent();
-
-    if (PrevDecl &&
-        (OutermostContext->Equals(PrevDecl->getDeclContext()) ||
-         OutermostContext->Encloses(PrevDecl->getDeclContext()))) {
-      SemanticContext = PrevDecl->getDeclContext();
-    } else {
-      // Declarations in outer scopes don't matter. However, the outermost
-      // context we computed is the semantic context for our new 
-      // declaration.
-      PrevDecl = PrevClassTemplate = 0;
-      SemanticContext = OutermostContext;
+    if (!SS.isSet()) {
+      DeclContext *OutermostContext = CurContext;
+      while (!OutermostContext->isFileContext())
+        OutermostContext = OutermostContext->getLookupParent();
+
+      if (PrevDecl &&
+          (OutermostContext->Equals(PrevDecl->getDeclContext()) ||
+           OutermostContext->Encloses(PrevDecl->getDeclContext()))) {
+        SemanticContext = PrevDecl->getDeclContext();
+      } else {
+        // Declarations in outer scopes don't matter. However, the outermost
+        // context we computed is the semantic context for our new 
+        // declaration.
+        PrevDecl = PrevClassTemplate = 0;
+        SemanticContext = OutermostContext;
+      }
     }
-    
+
     if (CurContext->isDependentContext()) {
       // If this is a dependent context, we don't want to link the friend
       // class template to the template in scope, because that would perform

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=101724&r1=101723&r2=101724&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 Sun Apr 18 12:37:40 2010
@@ -53,4 +53,16 @@
   friend union X1;
 };
 
+namespace N {
+  namespace M {
+    template<typename T> class X;
+  }
+}
+
+namespace N3 {
+  class Y {
+    template<typename T> friend class N::M::X;
+  };
+}
+
 // FIXME: Woefully inadequate for testing





More information about the cfe-commits mailing list