]> granicus.if.org Git - clang/commitdiff
Microsoft has a language extension which allows union members to be
authorAaron Ballman <aaron@aaronballman.com>
Thu, 30 May 2013 16:20:00 +0000 (16:20 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 30 May 2013 16:20:00 +0000 (16:20 +0000)
references.  What's more, they use this language extension in their
ATL header files (which come as part of MFC and the Win32 SDK).  This patch implements support for the Microsoft extension, and addresses PR13737.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@182936 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDecl.cpp
test/SemaCXX/MicrosoftExtensions.cpp

index 46351da12f2380098190e62bde4ebf92919caff5..aff02f30fc853acab50a7fd5c31f1764fbaa6714 100644 (file)
@@ -1179,6 +1179,9 @@ def ext_static_data_member_in_union : ExtWarn<
 def warn_cxx98_compat_static_data_member_in_union : Warning<
   "static data member %0 in union is incompatible with C++98">,
   InGroup<CXX98Compat>, DefaultIgnore;
+def ext_union_member_of_reference_type : ExtWarn<
+  "union member %0 has reference type %1, which is a Microsoft extension">,
+  InGroup<Microsoft>;
 def err_union_member_of_reference_type : Error<
   "union member %0 has reference type %1">;
 def ext_anonymous_struct_union_qualified : Extension<
index 05748f72f4737e2ed9973f67842fc3cf883e7a42..7be376e60f07d165a2ac15c6dc69c5baf2971b5d 100644 (file)
@@ -10684,11 +10684,15 @@ FieldDecl *Sema::CheckFieldDecl(DeclarationName Name, QualType T,
       }
 
       // 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.
       if (EltTy->isReferenceType()) {
-        Diag(NewFD->getLocation(), diag::err_union_member_of_reference_type)
+        Diag(NewFD->getLocation(), getLangOpts().MicrosoftExt ?
+                                    diag::ext_union_member_of_reference_type :
+                                    diag::err_union_member_of_reference_type)
           << NewFD->getDeclName() << EltTy;
-        NewFD->setInvalidDecl();
+        if (!getLangOpts().MicrosoftExt)
+          NewFD->setInvalidDecl();
       }
     }
   }
index ab3ff69f27be0a442d7f983ed047f41f789ef8b5..93a6d302ef31b185d980963111c34a9e49f41e4b 100644 (file)
@@ -333,3 +333,8 @@ void TestSP9() {
   c3.g(); // Overloaded incdec op operand
   c3.h(); // Overloaded unary op operand
 }
+
+union u {
+  int *i1;
+  int &i2;  // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
+};