r185100 - Under -fms-extensions, only inject a friend tag name when we didn't see a tag with that name in an enclosing scope.
Douglas Gregor
dgregor at apple.com
Thu Jun 27 13:42:30 PDT 2013
Author: dgregor
Date: Thu Jun 27 15:42:30 2013
New Revision: 185100
URL: http://llvm.org/viewvc/llvm-project?rev=185100&view=rev
Log:
Under -fms-extensions, only inject a friend tag name when we didn't see a tag with that name in an enclosing scope.
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>.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=185100&r1=185099&r2=185100&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jun 27 15:42:30 2013
@@ -9614,7 +9614,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned
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
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())
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=185100&r1=185099&r2=185100&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Thu Jun 27 15:42:30 2013
@@ -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;
+ }
+ }
+}
More information about the cfe-commits
mailing list