Commit b5e4bc03 authored by Andrew Krieger's avatar Andrew Krieger Committed by Facebook Github Bot

Suppress more warnings for MSVC

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.
- Use more careful bit twiddling instead of negating unsigned types
- Enable a simpler overload for bool->float conversion than one which attempts float->bool.
- Delete one unneeded undef.

Reviewed By: yfeldblum

Differential Revision: D4891583

fbshipit-source-id: 4d2efda1fe720abcb083bf29b578c065127cda24
parent bfdfe5e4
...@@ -558,7 +558,8 @@ toAppend(Src value, Tgt * result) { ...@@ -558,7 +558,8 @@ toAppend(Src value, Tgt * result) {
if (value < 0) { if (value < 0) {
result->push_back('-'); result->push_back('-');
result->append( result->append(
buffer, uint64ToBufferUnsafe(uint64_t(-uint64_t(value)), buffer)); buffer,
uint64ToBufferUnsafe(~static_cast<uint64_t>(value) + 1, buffer));
} else { } else {
result->append(buffer, uint64ToBufferUnsafe(uint64_t(value), buffer)); result->append(buffer, uint64ToBufferUnsafe(uint64_t(value), buffer));
} }
...@@ -1179,13 +1180,14 @@ parseTo(StringPiece src, Tgt& out) { ...@@ -1179,13 +1180,14 @@ parseTo(StringPiece src, Tgt& out) {
namespace detail { 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 * overload means we aren't trying to see if a bool is less than
* an integer. * an integer.
*/ */
template <class Tgt> template <class Tgt>
typename std::enable_if< 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 Expected<Tgt, ConversionCode>>::type
convertTo(const bool& value) noexcept { convertTo(const bool& value) noexcept {
return static_cast<Tgt>(value ? 1 : 0); return static_cast<Tgt>(value ? 1 : 0);
......
...@@ -233,6 +233,11 @@ struct ExpectedStorage { ...@@ -233,6 +233,11 @@ struct ExpectedStorage {
Value&& value() && { Value&& value() && {
return std::move(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() & { Error& error() & {
return error_; return error_;
} }
...@@ -242,6 +247,7 @@ struct ExpectedStorage { ...@@ -242,6 +247,7 @@ struct ExpectedStorage {
Error&& error() && { Error&& error() && {
return std::move(error_); return std::move(error_);
} }
FOLLY_POP_WARNING
}; };
template <class Value, class Error> template <class Value, class Error>
...@@ -527,6 +533,11 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> { ...@@ -527,6 +533,11 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> {
Value&& value() && { Value&& value() && {
return std::move(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() & { Error& error() & {
return error_; return error_;
} }
...@@ -536,6 +547,7 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> { ...@@ -536,6 +547,7 @@ struct ExpectedStorage<Value, Error, StorageType::ePODStruct> {
Error&& error() && { Error&& error() && {
return std::move(error_); return std::move(error_);
} }
FOLLY_POP_WARNING
}; };
namespace expected_detail_ExpectedHelper { namespace expected_detail_ExpectedHelper {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <cstdint> #include <cstdint>
#include <cstring> #include <cstring>
#include <limits>
#include <string> #include <string>
#include <tuple> #include <tuple>
#include <type_traits> #include <type_traits>
...@@ -365,7 +366,7 @@ template <> ...@@ -365,7 +366,7 @@ template <>
struct hasher<bool> { struct hasher<bool> {
size_t operator()(bool key) const { size_t operator()(bool key) const {
// Make sure that all the output bits depend on the input. // Make sure that all the output bits depend on the input.
return -static_cast<size_t>(key); return key ? std::numeric_limits<size_t>::max() : 0;
} }
}; };
......
...@@ -44,11 +44,6 @@ ...@@ -44,11 +44,6 @@
#undef CAL_GREGORIAN #undef CAL_GREGORIAN
#endif #endif
// Defined in winnt.h
#ifdef DELETE
#undef DELETE
#endif
// Defined in the GDI interface. // Defined in the GDI interface.
#ifdef ERROR #ifdef ERROR
#undef ERROR #undef ERROR
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment