[PATCH] MSVC compat: Allow lookup of friend types in enclosing namespaces
Reid Kleckner
rnk at google.com
Thu Jul 10 14:40:20 PDT 2014
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1000-1002
@@ -999,2 +999,5 @@
InGroup<UnsupportedFriend>;
-
+def ext_friend_tag_redecl_outside_namespace : ExtWarn<
+ "unqualified friend declarations referring to types outside of the nearest "
+ "enclosing namespace is a Microsoft extension; add a nested name specifier to fix">,
+ InGroup<Microsoft>;
----------------
Richard Smith wrote:
> Please add a bit more information here: which NNS should be added? What is the enclosing namespace that we looked in? Which type did we actually find? A fixit adding the NNS would help.
Done. It's a very nice diagnostic now, although maybe this is overkill for a fairly pedantic portion of the standard where implementations disagree. :)
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1001
@@ +1000,3 @@
+def ext_friend_tag_redecl_outside_namespace : ExtWarn<
+ "unqualified friend declarations referring to types outside of the nearest "
+ "enclosing namespace is a Microsoft extension; add a nested name specifier to fix">,
----------------
Richard Smith wrote:
> Singular/plural mismatch ("declarations ... is a MS extension"). Please make this singular.
done
================
Comment at: include/clang/Basic/DiagnosticSemaKinds.td:1002
@@ +1001,3 @@
+ "unqualified friend declarations referring to types outside of the nearest "
+ "enclosing namespace is a Microsoft extension; add a nested name specifier to fix">,
+ InGroup<Microsoft>;
----------------
Richard Smith wrote:
> Maybe drop the "to fix"?
done
================
Comment at: lib/Sema/SemaDecl.cpp:11467
@@ -11453,3 +11466,3 @@
if (TUK == TUK_Friend)
New->setObjectOfFriendDecl(!FriendSawTagOutsideEnclosingNamespace &&
getLangOpts().MicrosoftExt);
----------------
Richard Smith wrote:
> This was a prior attempt to get ~half of the same effect. In particular, for:
>
> struct X {};
> namespace N {
> struct Y { friend struct X; };
> X x;
> }
>
> ... we need to not inject `X` into `N`, or the lookup for `N::x`'s type will find the wrong struct.
>
> Perhaps we should remove this hack (for `MicrosoftExt`) now that we have a more faithful hack (for `MSVCCompat`)? It's not a conforming extension. That is, replace this with just
>
> New->setObjectOfFriendDecl(getLangOpts().MSVCCompat);
I agree, I'd rather have just one faithful hack, but presumably Doug put this under -fms-extensions for a reason. Hopefully we can raise him. :)
I'll make the change, since I think we both agree this shouldn't be under -fms-extensions.
http://reviews.llvm.org/D4443
More information about the cfe-commits
mailing list