diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2013-05-30 16:20:00 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2013-05-30 16:20:00 +0000 |
commit | ed0ae1d70bf872c28fb9036578ced6db57583bf1 (patch) | |
tree | dc4f585fbd3f5eefa7057875a20278582c9a9357 | |
parent | 54cd84861e757c676c7635186e925c5a11609faf (diff) | |
download | bcm5719-llvm-ed0ae1d70bf872c28fb9036578ced6db57583bf1.tar.gz bcm5719-llvm-ed0ae1d70bf872c28fb9036578ced6db57583bf1.zip |
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). This patch implements support for the Microsoft extension, and addresses PR13737.
llvm-svn: 182936
-rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 10 | ||||
-rw-r--r-- | clang/test/SemaCXX/MicrosoftExtensions.cpp | 5 |
3 files changed, 15 insertions, 3 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 46351da12f2..aff02f30fc8 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 05748f72f47..7be376e60f0 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -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(); } } } diff --git a/clang/test/SemaCXX/MicrosoftExtensions.cpp b/clang/test/SemaCXX/MicrosoftExtensions.cpp index ab3ff69f27b..93a6d302ef3 100644 --- a/clang/test/SemaCXX/MicrosoftExtensions.cpp +++ b/clang/test/SemaCXX/MicrosoftExtensions.cpp @@ -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}} +}; |