summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorManman Ren <manman.ren@gmail.com>2016-03-23 16:28:28 +0000
committerManman Ren <manman.ren@gmail.com>2016-03-23 16:28:28 +0000
commit6d93ad844a5b81e36d67596ffa055f0f3d00d1f5 (patch)
treedae539a94d8a2e659224d43c1de4b9582742084d /clang
parentb7d30cbc7ec8fbaf21d005468ae6d26f41e3a329 (diff)
downloadbcm5719-llvm-6d93ad844a5b81e36d67596ffa055f0f3d00d1f5.tar.gz
bcm5719-llvm-6d93ad844a5b81e36d67596ffa055f0f3d00d1f5.zip
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 llvm-svn: 264167
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp5
-rw-r--r--clang/test/SemaObjC/enum-fixed-type.m5
2 files changed, 9 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1abd7d0ae6b..c8a9b9ac807 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/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/clang/test/SemaObjC/enum-fixed-type.m b/clang/test/SemaObjC/enum-fixed-type.m
index c00e45a03ed..37d2810a504 100644
--- a/clang/test/SemaObjC/enum-fixed-type.m
+++ b/clang/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}}
+
+// <rdar://problem/24999533>
+enum MyEnum : _Bool {
+ MyThing = 0
+};
OpenPOWER on IntegriCloud