]> granicus.if.org Git - clang/commitdiff
Under -fms-extensions, only inject a friend tag name when we didn't see a tag with...
authorDouglas Gregor <dgregor@apple.com>
Thu, 27 Jun 2013 20:42:30 +0000 (20:42 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 27 Jun 2013 20:42:30 +0000 (20:42 +0000)
r177473 made us correctly consider only those declarations in the
enclosing namespace scope when looking for a friend declaration. Under
ms-extensions mode, where we do some level of friend injection, this
meant that we were introducing a new tag type into a different scope
than what Microsoft actually does. Address this by only doing the
friend injection when we didn't see any tag with that name in any
outer scope. Fixes <rdar://problem/14250378>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@185100 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 08e8cb798acb53cfc9e7607c217f01495e2b822e..a87cf61ccfe1d5ef0e7b1e2f2c59a18f148eb836 100644 (file)
@@ -9614,7 +9614,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
     Redecl = NotForRedeclaration;
 
   LookupResult Previous(*this, Name, NameLoc, LookupTagName, Redecl);
-
+  bool FriendSawTagOutsideEnclosingNamespace = false;
   if (Name && SS.isNotEmpty()) {
     // We have a nested-name tag ('struct foo::bar').
 
@@ -9707,8 +9707,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK,
       while (F.hasNext()) {
         NamedDecl *ND = F.next();
         DeclContext *DC = ND->getDeclContext()->getRedeclContext();
-        if (DC->isFileContext() && !EnclosingNS->Encloses(ND->getDeclContext()))
+        if (DC->isFileContext() &&
+            !EnclosingNS->Encloses(ND->getDeclContext())) {
           F.erase();
+          FriendSawTagOutsideEnclosingNamespace = true;
+        }
       }
       F.done();
     }
@@ -10208,7 +10211,8 @@ CreateNewDecl:
   // the tag name visible.
   if (TUK == TUK_Friend)
     New->setObjectOfFriendDecl(/* PreviouslyDeclared = */ !Previous.empty() ||
-                               getLangOpts().MicrosoftExt);
+                               (!FriendSawTagOutsideEnclosingNamespace &&
+                                getLangOpts().MicrosoftExt));
 
   // Set the access specifier.
   if (!Invalid && SearchDC->isRecord())
index e82c47eb586d9e5e39eb43ab71f7c9942bca31f8..723beb4efca70106c95a2b66dc2d5042f82d4c6b 100644 (file)
@@ -365,3 +365,23 @@ void SP11::UseV() {
 struct StructWithUnnamedMember {
   __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}
 };
+
+namespace rdar14250378 {
+  class Bar {};
+  
+  namespace NyNamespace {
+    class Foo {
+    public:
+      Bar* EnsureBar();
+    };
+    
+    class Baz : public Foo {
+    public:
+      friend class Bar;
+    };
+    
+    Bar* Foo::EnsureBar() {
+      return 0;
+    }
+  }
+}