From d71ad3f744a0de0c09ff624e6d5d5e605dbff22f Mon Sep 17 00:00:00 2001 From: Manman Ren Date: Wed, 23 Mar 2016 16:28:28 +0000 Subject: [PATCH] ObjC: Handle boolean fixed type for enum. Before this commit, we assert failure in ImplicitCastExpr "unheralded conversion to bool". This commit fixes the assertion by using the correct cast type when the fixed type is boolean. This commit also fixes the behavior for Microsoft mode as well, since Obj-C and Microsoft mode share the same code path. rdar://24999533 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@264167 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 5 ++++- test/SemaObjC/enum-fixed-type.m | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 1abd7d0ae6..c8a9b9ac80 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -14146,7 +14146,10 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum, } else Diag(IdLoc, diag::err_enumerator_too_large) << EltTy; } else - Val = ImpCastExprToType(Val, EltTy, CK_IntegralCast).get(); + Val = ImpCastExprToType(Val, EltTy, + EltTy->isBooleanType() ? + CK_IntegralToBoolean : CK_IntegralCast) + .get(); } else if (getLangOpts().CPlusPlus) { // C++11 [dcl.enum]p5: // If the underlying type is not fixed, the type of each enumerator diff --git a/test/SemaObjC/enum-fixed-type.m b/test/SemaObjC/enum-fixed-type.m index c00e45a03e..37d2810a50 100644 --- a/test/SemaObjC/enum-fixed-type.m +++ b/test/SemaObjC/enum-fixed-type.m @@ -38,3 +38,8 @@ int arr3[(long long)Bar == (long long)-1 ? 1 : -1]; typedef enum : Integer { BaseElem } BaseEnum; typedef enum : BaseEnum { DerivedElem } DerivedEnum; // expected-error {{non-integral type 'BaseEnum' is an invalid underlying type}} + +// +enum MyEnum : _Bool { + MyThing = 0 +}; -- 2.40.0