Make a few coersions to bool explicit
authorChristopher Dykes <cdykes@fb.com>
Tue, 7 Feb 2017 19:27:44 +0000 (11:27 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 7 Feb 2017 19:37:19 +0000 (11:37 -0800)
Summary: MSVC has warning 4800 which is triggered on implicit coercions to `bool` when not in use as the condition to a control-flow statement.

Reviewed By: yfeldblum

Differential Revision: D4518465

fbshipit-source-id: 858ab9e68215a2a667cb3ea55daf51b74368174d

folly/CpuId.h
folly/FormatArg.h
folly/dynamic-inl.h

index 24d4d97ee979d52f8048a80c991eb53c47245059..5e06513ccad44326d506c2e114d621fa70e79d84 100644 (file)
@@ -99,7 +99,7 @@ class CpuId {
 
 #define X(name, r, bit)                   \
   FOLLY_ALWAYS_INLINE bool name() const { \
-    return (r) & (1U << bit);             \
+    return ((r) & (1U << bit)) != 0;      \
   }
 
 // cpuid(1): Processor Info and Feature Bits.
index 5257285c00a23332cdeb5f00f1281a3c2bf96fed..48311e3d4e7cd18a77aeacb553dd0d4c98fc7ee9 100644 (file)
@@ -244,7 +244,7 @@ inline StringPiece FormatArg::doSplitKey() {
   if (e[-1] == ']') {
     --e;
     p = static_cast<const char*>(memchr(b, '[', size_t(e - b)));
-    enforce(p, "unmatched ']'");
+    enforce(p != nullptr, "unmatched ']'");
   } else {
     p = static_cast<const char*>(memchr(b, '.', size_t(e - b)));
   }
index 984b7a4cac9da7aa04c451ca67337673e612c0a5..41352ad070ac563ac7976a2c006a4065a9ec4e6c 100644 (file)
@@ -342,15 +342,29 @@ inline dynamic::IterableProxy<dynamic::const_item_iterator> dynamic::items()
 }
 
 inline bool dynamic::isString() const {
-  return get_nothrow<std::string>();
-}
-inline bool dynamic::isObject() const { return get_nothrow<ObjectImpl>(); }
-inline bool dynamic::isBool()   const { return get_nothrow<bool>(); }
-inline bool dynamic::isArray()  const { return get_nothrow<Array>(); }
-inline bool dynamic::isDouble() const { return get_nothrow<double>(); }
-inline bool dynamic::isInt()    const { return get_nothrow<int64_t>(); }
-inline bool dynamic::isNull()   const { return get_nothrow<void*>(); }
-inline bool dynamic::isNumber() const { return isInt() || isDouble(); }
+  return get_nothrow<std::string>() != nullptr;
+}
+inline bool dynamic::isObject() const {
+  return get_nothrow<ObjectImpl>() != nullptr;
+}
+inline bool dynamic::isBool() const {
+  return get_nothrow<bool>() != nullptr;
+}
+inline bool dynamic::isArray() const {
+  return get_nothrow<Array>() != nullptr;
+}
+inline bool dynamic::isDouble() const {
+  return get_nothrow<double>() != nullptr;
+}
+inline bool dynamic::isInt() const {
+  return get_nothrow<int64_t>() != nullptr;
+}
+inline bool dynamic::isNull() const {
+  return get_nothrow<void*>() != nullptr;
+}
+inline bool dynamic::isNumber() const {
+  return isInt() || isDouble();
+}
 
 inline dynamic::Type dynamic::type() const {
   return type_;