<div dir="ltr">Hey Doug, is this really appropriate for -fms-extensions? This seems like more of an -fms-compatibility change.<div><br></div><div>Looking at <a href="http://llvm.org/PR20259" target="_blank">http://llvm.org/PR20259</a>, it seems like we need to completely disable the logic of r177473 in order to compile WRL system headers.</div>
<div><br></div><div>MSVC accepts this code which we reject:</div><div><br></div><div><div>struct B;</div><div>namespace ns {</div><div>struct A {</div><div> friend struct B; // Declares 'struct ::ns::A::B' instead of friending ::B.</div>
<div>protected:</div><div> A();</div><div>};</div><div>}</div><div>struct B {</div><div> static void f() { ns::A x; }</div><div>};</div></div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 27, 2013 at 1:42 PM, Douglas Gregor <span dir="ltr"><<a href="mailto:dgregor@apple.com" target="_blank">dgregor@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: dgregor<br>
Date: Thu Jun 27 15:42:30 2013<br>
New Revision: 185100<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=185100&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=185100&view=rev</a><br>
Log:<br>
Under -fms-extensions, only inject a friend tag name when we didn't see a tag with that name in an enclosing scope.<br>
<br>
r177473 made us correctly consider only those declarations in the<br>
enclosing namespace scope when looking for a friend declaration. Under<br>
ms-extensions mode, where we do some level of friend injection, this<br>
meant that we were introducing a new tag type into a different scope<br>
than what Microsoft actually does. Address this by only doing the<br>
friend injection when we didn't see any tag with that name in any<br>
outer scope. Fixes <rdar://problem/14250378>.<br>
<br>
Modified:<br>
cfe/trunk/lib/Sema/SemaDecl.cpp<br>
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=185100&r1=185099&r2=185100&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=185100&r1=185099&r2=185100&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Jun 27 15:42:30 2013<br>
@@ -9614,7 +9614,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned<br>
Redecl = NotForRedeclaration;<br>
<br>
LookupResult Previous(*this, Name, NameLoc, LookupTagName, Redecl);<br>
-<br>
+ bool FriendSawTagOutsideEnclosingNamespace = false;<br>
if (Name && SS.isNotEmpty()) {<br>
// We have a nested-name tag ('struct foo::bar').<br>
<br>
@@ -9707,8 +9707,11 @@ Decl *Sema::ActOnTag(Scope *S, unsigned<br>
while (F.hasNext()) {<br>
NamedDecl *ND = F.next();<br>
DeclContext *DC = ND->getDeclContext()->getRedeclContext();<br>
- if (DC->isFileContext() && !EnclosingNS->Encloses(ND->getDeclContext()))<br>
+ if (DC->isFileContext() &&<br>
+ !EnclosingNS->Encloses(ND->getDeclContext())) {<br>
F.erase();<br>
+ FriendSawTagOutsideEnclosingNamespace = true;<br>
+ }<br>
}<br>
F.done();<br>
}<br>
@@ -10208,7 +10211,8 @@ CreateNewDecl:<br>
// the tag name visible.<br>
if (TUK == TUK_Friend)<br>
New->setObjectOfFriendDecl(/* PreviouslyDeclared = */ !Previous.empty() ||<br>
- getLangOpts().MicrosoftExt);<br>
+ (!FriendSawTagOutsideEnclosingNamespace &&<br>
+ getLangOpts().MicrosoftExt));<br>
<br>
// Set the access specifier.<br>
if (!Invalid && SearchDC->isRecord())<br>
<br>
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=185100&r1=185099&r2=185100&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=185100&r1=185099&r2=185100&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)<br>
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Thu Jun 27 15:42:30 2013<br>
@@ -365,3 +365,23 @@ void SP11::UseV() {<br>
struct StructWithUnnamedMember {<br>
__declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}<br>
};<br>
+<br>
+namespace rdar14250378 {<br>
+ class Bar {};<br>
+<br>
+ namespace NyNamespace {<br>
+ class Foo {<br>
+ public:<br>
+ Bar* EnsureBar();<br>
+ };<br>
+<br>
+ class Baz : public Foo {<br>
+ public:<br>
+ friend class Bar;<br>
+ };<br>
+<br>
+ Bar* Foo::EnsureBar() {<br>
+ return 0;<br>
+ }<br>
+ }<br>
+}<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div>