From: Marc Horowitz Date: Tue, 18 Apr 2017 22:21:35 +0000 (-0700) Subject: Fail on implicit convert from BOOL on ObjC in folly::dynamic X-Git-Tag: v2017.04.24.00~10 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=c31d639e15ceb2a1fab05f1318f886df7c18bbcb Fail on implicit convert from BOOL on ObjC in folly::dynamic Summary: On some platforms (iPhone 5C at least), ObjC/Objc++ BOOL is really signed char. There is code which expects this to be a boolean when converted to dynamic (and then to JSON and into JS), but the old code treated it as a number. This makes such code (like [mobileConfig getBool:]) fail to compile, so the developer needs to resolve the ambiguity one way or the other. Reviewed By: yfeldblum Differential Revision: D4648133 fbshipit-source-id: 76ece7803a1e966dca08bdb857af7990035544a0 --- diff --git a/folly/Portability.h b/folly/Portability.h index 1792abf5..51032fda 100644 --- a/folly/Portability.h +++ b/folly/Portability.h @@ -331,6 +331,12 @@ using namespace FOLLY_GFLAGS_NAMESPACE; namespace folly { +#if __OBJC__ +constexpr auto kIsObjC = true; +#else +constexpr auto kIsObjC = false; +#endif + #if defined(__linux__) && !FOLLY_MOBILE constexpr auto kIsLinux = true; #else diff --git a/folly/dynamic-inl.h b/folly/dynamic-inl.h index dbe36b5d..3c85ee4b 100644 --- a/folly/dynamic-inl.h +++ b/folly/dynamic-inl.h @@ -310,6 +310,9 @@ inline dynamic::~dynamic() noexcept { destroy(); } template struct dynamic::NumericTypeHelper< T, typename std::enable_if::value>::type> { + static_assert( + !kIsObjC || sizeof(T) > sizeof(char), + "char-sized types are ambiguous in objc; cast to bool or wider type"); using type = int64_t; }; template <>