From: Eli Friedman Date: Thu, 16 Feb 2012 05:20:44 +0000 (+0000) Subject: Shift Microsoft enum extensions from -fms-extensions to -fms-compatibility, so -fms... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a2d7dfab309375fbf016b650fa74f9b5d03a9752;p=clang Shift Microsoft enum extensions from -fms-extensions to -fms-compatibility, so -fms-extensions doesn't affect enum semantics in incompatible ways. . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150663 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 304304b776..9fa0349723 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -7820,7 +7820,7 @@ Decl *Sema::ActOnTag(Scope *S, unsigned TagSpec, TagUseKind TUK, UPPC_FixedUnderlyingType)) EnumUnderlying = Context.IntTy.getTypePtr(); - } else if (getLangOptions().MicrosoftExt) + } else if (getLangOptions().MicrosoftMode) // Microsoft enums are always of int type. EnumUnderlying = Context.IntTy.getTypePtr(); } @@ -8281,7 +8281,7 @@ CreateNewDecl: Diag(Def->getLocation(), diag::note_previous_definition); } else { unsigned DiagID = diag::ext_forward_ref_enum; - if (getLangOptions().MicrosoftExt) + if (getLangOptions().MicrosoftMode) DiagID = diag::ext_ms_forward_ref_enum; else if (getLangOptions().CPlusPlus) DiagID = diag::err_forward_ref_enum; @@ -9682,7 +9682,7 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, // we perform a non-narrowing conversion as part of converted constant // expression checking. if (!isRepresentableIntegerValue(Context, EnumVal, EltTy)) { - if (getLangOptions().MicrosoftExt) { + if (getLangOptions().MicrosoftMode) { Diag(IdLoc, diag::ext_enumerator_too_large) << EltTy; Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).take(); } else diff --git a/test/Sema/MicrosoftCompatibility.c b/test/Sema/MicrosoftCompatibility.c new file mode 100644 index 0000000000..c26c3039fd --- /dev/null +++ b/test/Sema/MicrosoftCompatibility.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-compatibility + +enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} +enum ENUM1 var1 = 3; +enum ENUM1* var2 = 0; + + +enum ENUM2 { + ENUM2_a = (enum ENUM2) 4, + ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} + ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} +}; diff --git a/test/Sema/MicrosoftExtensions.c b/test/Sema/MicrosoftExtensions.c index a08aeab99b..a4a8acd78e 100644 --- a/test/Sema/MicrosoftExtensions.c +++ b/test/Sema/MicrosoftExtensions.c @@ -21,16 +21,6 @@ struct D { }; -enum ENUM1; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} -enum ENUM1 var1 = 3; -enum ENUM1* var2 = 0; - - -enum ENUM2 { - ENUM2_a = (enum ENUM2) 4, - ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} - ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} -}; diff --git a/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp b/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp new file mode 100644 index 0000000000..0c7d354c30 --- /dev/null +++ b/test/SemaCXX/MicrosoftCompatibility-cxx98.cpp @@ -0,0 +1,8 @@ +// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++98 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions + + +//MSVC allows forward enum declaration +enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} +ENUM *var = 0; +ENUM var2 = (ENUM)3; +enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}} diff --git a/test/SemaCXX/MicrosoftExtensions.cpp b/test/SemaCXX/MicrosoftExtensions.cpp index 93da08f1f2..0b72cd3e1f 100644 --- a/test/SemaCXX/MicrosoftExtensions.cpp +++ b/test/SemaCXX/MicrosoftExtensions.cpp @@ -92,11 +92,6 @@ void m1() { h1(&M::subtractP); } -//MSVC allows forward enum declaration -enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} -ENUM *var = 0; -ENUM var2 = (ENUM)3; -enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}} diff --git a/test/SemaTemplate/enum-forward.cpp b/test/SemaTemplate/enum-forward.cpp index 3a4f05c0ba..b25c21fc46 100644 --- a/test/SemaTemplate/enum-forward.cpp +++ b/test/SemaTemplate/enum-forward.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsyntax-only -fms-extensions %s +// RUN: %clang_cc1 -fsyntax-only -fms-compatibility %s template struct X {