forked from OSchip/llvm-project
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
This commit is contained in:
parent
54cd84861e
commit
ed0ae1d70b
|
@ -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<
|
||||
|
|
|
@ -10684,10 +10684,14 @@ 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;
|
||||
if (!getLangOpts().MicrosoftExt)
|
||||
NewFD->setInvalidDecl();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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}}
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue