[PATCH] Unions with References

Reid Kleckner rnk at google.com
Thu May 30 07:26:23 PDT 2013


LGTM with nits fixed.

--- lib/Sema/SemaDecl.cpp (revision 182601)
+++ lib/Sema/SemaDecl.cpp (working copy)
@@ -10680,10 +10680,14 @@
       // C++ [class.union]p1: If a union contains a member of reference
type,
-      // the program is ill-formed.
+      // the program is ill-formed.  Except when compiling with MSVC
extensions
+      // enabled.

This should be a complete sentence.

       if (EltTy->isReferenceType()) {
-        Diag(NewFD->getLocation(),
diag::err_union_member_of_reference_type)
+        Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ?

^ trailing space

+
 diag::ext_union_member_of_reference_type :
+
 diag::err_union_member_of_reference_type)
           << NewFD->getDeclName() << EltTy;
+        if (!getLangOpts().MicrosoftExt)
         NewFD->setInvalidDecl();

NewFD->setInvalidDecl() needs to be indented.

       }
     }



On Thu, May 30, 2013 at 9:36 AM, Aaron Ballman <aaron at aaronballman.com>wrote:

> Microsoft has a language extension which allows union members to be
> references.  What's more, they use this language extension in their
> ATL header files (which come as part of MFC and the Win32 SDK).
> Basically, they have code like this:
>
> struct s {
>   union {
>      foo *fp;
>      foo &fr;
>     };
>
>     s( foo &f ) : fr( f ) {}
>     s( foo *f ) : fp( f ) {}
> };
>
> This patch enables support for union members to be references when
> compiling with Microsoft extensions, and addresses PR13737.
>
> ~Aaron
>
> _______________________________________________
> 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/20130530/aa44dc9b/attachment.html>


More information about the cfe-commits mailing list