Suppress more warnings for MSVC
authorAndrew Krieger <andrew.krieger@oculus.com>
Fri, 14 Apr 2017 07:06:53 +0000 (00:06 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Apr 2017 07:24:45 +0000 (00:24 -0700)
Summary:
Several other warnings that aren't reasonable to disable globally occur in folly headers.
- Wrap the unreachable code warnings in MSVC specific disable blocks to prevent problems for users.
- Cast to signed types to perform integral negation before casting back to unsigned for bit operations.
- Enable a simpler overload for bool->float conversion than one which attempts float->bool.
- Delete one unneeded undef.

(Note: this ignores all push blocking failures!)

Reviewed By: yfeldblum

Differential Revision: D4805628

fbshipit-source-id: 9574ea984e1e3daca01101259687f46effcf3a9f

folly/Conv.h
folly/Expected.h
folly/Hash.h
folly/portability/Windows.h

index 20cf3d51b2fe84c208014bf30732e129a211c95a..17b2fc67df434ba177755f78e3dd5ea0703cd692 100644 (file)
@@ -557,8 +557,11 @@ toAppend(Src value, Tgt * result) {
   char buffer[20];
   if (value < 0) {
     result->push_back('-');
+    using u = std::make_signed<size_t>::type;
     result->append(
-        buffer, uint64ToBufferUnsafe(uint64_t(-uint64_t(value)), buffer));
+        buffer,
+        uint64ToBufferUnsafe(
+            static_cast<size_t>(-static_cast<u>(value)), buffer));
   } else {
     result->append(buffer, uint64ToBufferUnsafe(uint64_t(value), buffer));
   }
@@ -1179,13 +1182,14 @@ parseTo(StringPiece src, Tgt& out) {
 namespace detail {
 
 /**
- * Bool to integral doesn't need any special checks, and this
+ * Bool to integral/float doesn't need any special checks, and this
  * overload means we aren't trying to see if a bool is less than
  * an integer.
  */
 template <class Tgt>
 typename std::enable_if<
-    !std::is_same<Tgt, bool>::value && std::is_integral<Tgt>::value,
+    !std::is_same<Tgt, bool>::value &&
+        (std::is_integral<Tgt>::value || std::is_floating_point<Tgt>::value),
     Expected<Tgt, ConversionCode>>::type
 convertTo(const bool& value) noexcept {
   return static_cast<Tgt>(value ? 1 : 0);
index ee765cc92a154fcac6f9f8fe77202b6cd203c025..2b791c117810d73f6772e18645c90de2287d7546 100644 (file)
@@ -233,6 +233,11 @@ struct ExpectedStorage {
   Value&& value() && {
     return std::move(value_);
   }
+  // TODO (t17322426): remove when VS2015 support is deprecated
+  // VS2015 static analyzer incorrectly flags these as unreachable in certain
+  // circumstances. VS2017 does not have this problem on the same code.
+  FOLLY_PUSH_WARNING
+  FOLLY_MSVC_DISABLE_WARNING(4702) // unreachable code
   Error& error() & {
     return error_;
   }
@@ -242,6 +247,7 @@ struct ExpectedStorage {
   Error&& error() && {
     return std::move(error_);
   }
+  FOLLY_POP_WARNING
 };
 
 template <class Value, class Error>
@@ -527,6 +533,11 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> {
   Value&& value() && {
     return std::move(value_);
   }
+  // TODO (t17322426): remove when VS2015 support is deprecated
+  // VS2015 static analyzer incorrectly flags these as unreachable in certain
+  // circumstances. VS2017 does not have this problem on the same code.
+  FOLLY_PUSH_WARNING
+  FOLLY_MSVC_DISABLE_WARNING(4702) // unreachable code
   Error& error() & {
     return error_;
   }
@@ -536,6 +547,7 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> {
   Error&& error() && {
     return std::move(error_);
   }
+  FOLLY_POP_WARNING
 };
 
 namespace expected_detail_ExpectedHelper {
index 0f0afc5baf71ac4c4ca301becf5f84e98fca6da5..314a98d0fdc6c0556f8f6455ae2582179c685bfc 100644 (file)
@@ -365,7 +365,8 @@ template <>
 struct hasher<bool> {
   size_t operator()(bool key) const {
     // Make sure that all the output bits depend on the input.
-    return -static_cast<size_t>(key);
+    using u = std::make_signed<size_t>::type;
+    return static_cast<size_t>(-static_cast<u>(key));
   }
 };
 
index f10c428a5a3c6cdfbe22d33fbca35a08aa925282..2cb0bda86769d89cfbf9c35457635ba66394348c 100755 (executable)
 #undef CAL_GREGORIAN
 #endif
 
-// Defined in winnt.h
-#ifdef DELETE
-#undef DELETE
-#endif
-
 // Defined in the GDI interface.
 #ifdef ERROR
 #undef ERROR