]> granicus.if.org Git - clang/commitdiff
Microsoft friend acting as a forward declaration; try#2. Now only 2 lines.
authorFrancois Pichet <pichet2000@gmail.com>
Wed, 1 Jun 2011 04:14:20 +0000 (04:14 +0000)
committerFrancois Pichet <pichet2000@gmail.com>
Wed, 1 Jun 2011 04:14:20 +0000 (04:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@132387 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 5a3f6328cac95d5ab7d0441173c4e2da6c855ccf..f5b642191c6b4c1e6b2acfc90d45f6d692b28a8c 100644 (file)
@@ -7016,8 +7016,8 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
           // for the consumer of this Decl to know it doesn't own it.
           // For our current ASTs this shouldn't be a problem, but will
           // need to be changed with DeclGroups.
-          if ((TUK == TUK_Reference && !PrevTagDecl->getFriendObjectKind()) ||
-              TUK == TUK_Friend)
+          if ((TUK == TUK_Reference && (!PrevTagDecl->getFriendObjectKind() ||
+               getLangOptions().Microsoft)) || TUK == TUK_Friend)
             return PrevTagDecl;
 
           // Diagnose attempts to redefine a tag.
@@ -7259,8 +7259,12 @@ CreateNewDecl:
   New->setLexicalDeclContext(CurContext);
 
   // Mark this as a friend decl if applicable.
+  // In Microsoft mode, a friend declaration also acts as a forward
+  // declaration so we always pass true to setObjectOfFriendDecl to make
+  // the tag name visible.
   if (TUK == TUK_Friend)
-    New->setObjectOfFriendDecl(/* PreviouslyDeclared = */ !Previous.empty());
+    New->setObjectOfFriendDecl(/* PreviouslyDeclared = */ !Previous.empty() ||
+                               getLangOptions().Microsoft);
 
   // Set the access specifier.
   if (!Invalid && SearchDC->isRecord())
index 22a06673b951689d8bc99caf6ba59e57e65581b8..9b03feb5390951eb9093a3b4a201ea07c12b8fb4 100644 (file)
@@ -226,4 +226,29 @@ private:
   using B::f; // expected-warning {{using declaration refers to inaccessible member 'ms_using_declaration_bug::B::f', which refers to accessible member 'ms_using_declaration_bug::A::f', accepted for Microsoft compatibility}}
 };
 
-}
\ No newline at end of file
+}
+
+
+
+namespace friend_as_a_forward_decl {
+
+class A {
+  class Nested {
+    friend class B;
+    B* b;
+  };
+  B* b;
+};
+B* global_b;
+
+
+void f()
+{
+  class Local {
+    friend class Z;
+    Z* b;
+  };
+  Z* b;
+}
+
+ }
\ No newline at end of file