r185100 - Under -fms-extensions, only inject a friend tag name when we didn't see a tag with that name in an enclosing scope.

Reid Kleckner rnk at google.com
Wed Jul 9 14:23:55 PDT 2014


Hey Doug, is this really appropriate for -fms-extensions?  This seems like
more of an -fms-compatibility change.

Looking at http://llvm.org/PR20259, it seems like we need to completely
disable the logic of r177473 in order to compile WRL system headers.

MSVC accepts this code which we reject:

struct B;
namespace ns {
struct A {
  friend struct B;  // Declares 'struct ::ns::A::B' instead of friending
::B.
protected:
  A();
};
}
struct B {
  static void f() { ns::A x; }
};


On Thu, Jun 27, 2013 at 1:42 PM, Douglas Gregor <dgregor at apple.com> wrote:

> 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;
> +    }
> +  }
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140709/e5ec730a/attachment.html>


More information about the cfe-commits mailing list