[cfe-commits] r80745 - in /cfe/trunk: lib/AST/DeclBase.cpp lib/AST/DeclPrinter.cpp lib/Sema/SemaDecl.cpp test/CXX/class/class.friend/p1.cpp test/SemaCXX/friend-class-nodecl.cpp

John McCall rjmccall at apple.com
Tue Sep 1 17:55:31 PDT 2009


Author: rjmccall
Date: Tue Sep  1 19:55:30 2009
New Revision: 80745

URL: http://llvm.org/viewvc/llvm-project?rev=80745&view=rev
Log:
Ensure that the tag decls of friend decls aren't added to the friending class's
decl list, and remove some workarounds that were due to this.  Thanks to Eli for
pointing this out and providing the test case.


Added:
    cfe/trunk/test/SemaCXX/friend-class-nodecl.cpp
Modified:
    cfe/trunk/lib/AST/DeclBase.cpp
    cfe/trunk/lib/AST/DeclPrinter.cpp
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/CXX/class/class.friend/p1.cpp

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=80745&r1=80744&r2=80745&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Sep  1 19:55:30 2009
@@ -385,11 +385,6 @@
       !isa<CXXRecordDecl>(getDeclContext()))
     return;
   
-  // FIXME: This check should not be necessary - If a friend decl refers to an
-  // undeclared decl, then that decl shouldn't be in any decl context.
-  if (getFriendObjectKind() == FOK_Undeclared)
-    return;
-  
   assert(Access != AS_none && 
          "Access specifier is AS_none inside a record decl");
 }

Modified: cfe/trunk/lib/AST/DeclPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclPrinter.cpp?rev=80745&r1=80744&r2=80745&view=diff

==============================================================================
--- cfe/trunk/lib/AST/DeclPrinter.cpp (original)
+++ cfe/trunk/lib/AST/DeclPrinter.cpp Tue Sep  1 19:55:30 2009
@@ -203,9 +203,7 @@
     if (PrintAccess) {
       AccessSpecifier AS = D->getAccess();
 
-      if (AS != CurAS && 
-          // FIXME: This check shouldn't be necessary.
-          D->getFriendObjectKind() == Decl::FOK_Undeclared) {
+      if (AS != CurAS) {
         Print(AS);
         Out << ":\n";
         CurAS = AS;

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=80745&r1=80744&r2=80745&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Sep  1 19:55:30 2009
@@ -4328,7 +4328,15 @@
     New->startDefinition();
   
   // If this has an identifier, add it to the scope stack.
-  if (Name && TUK != TUK_Friend) {
+  if (TUK == TUK_Friend) {
+    // Friend tag decls are visible in fairly strange ways.
+    if (!CurContext->isDependentContext()) {
+      DeclContext *DC = New->getDeclContext()->getLookupContext();
+      DC->makeDeclVisibleInContext(New, /* Recoverable = */ false);
+      if (Scope *EnclosingScope = getScopeForDeclContext(S, DC))
+        PushOnScopeChains(New, EnclosingScope, /* AddToContext = */ false);
+    }
+  } else if (Name) {
     S = getNonFieldDeclScope(S);
     PushOnScopeChains(New, S);
   } else {

Modified: cfe/trunk/test/CXX/class/class.friend/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/class/class.friend/p1.cpp?rev=80745&r1=80744&r2=80745&view=diff

==============================================================================
--- cfe/trunk/test/CXX/class/class.friend/p1.cpp (original)
+++ cfe/trunk/test/CXX/class/class.friend/p1.cpp Tue Sep  1 19:55:30 2009
@@ -63,8 +63,6 @@
   friend ftypedef typedeffed_function; // okay (because it's not declared as a member)
 };
 
-class UndeclaredSoFar { };
-
 A::UndeclaredSoFar y; // expected-error {{ unknown type name 'UndeclaredSoFar' }}
 
 class PreDeclared;

Added: cfe/trunk/test/SemaCXX/friend-class-nodecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/friend-class-nodecl.cpp?rev=80745&view=auto

==============================================================================
--- cfe/trunk/test/SemaCXX/friend-class-nodecl.cpp (added)
+++ cfe/trunk/test/SemaCXX/friend-class-nodecl.cpp Tue Sep  1 19:55:30 2009
@@ -0,0 +1,10 @@
+// RUN: clang-cc -ast-print %s -o %t &&
+// RUN: not grep '^ *class B' %t
+
+// Tests that the tag decls in friend declarations aren't added to the
+// declaring class's decl chain.
+
+class A {
+  friend class B;
+};
+





More information about the cfe-commits mailing list