From: Alexey Kozhevnikov Date: Wed, 13 Mar 2019 02:48:11 +0000 (-0700) Subject: Fix Windows build (#17917) X-Git-Tag: accepted/tizen/6.5/unified/20211028.231830~845 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f7b70a69e5095a59dcec755cace5016bf2ad9c9e;p=platform%2Fupstream%2Fpytorch.git Fix Windows build (#17917) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/17917 D14375995 introduced instantiation of the following templates with `bool` type (more specifically `To` is `int64_t`, `From` is `bool`): ``` template typename std::enable_if::value, bool>::type overflows( From f) { using limit = std::numeric_limits::type>; if (!limit::is_signed && std::numeric_limits::is_signed) { // allow for negative numbers to wrap using two's complement arithmetic. // For example, with uint8, this allows for `a - b` to be treated as // `a + 255 * b`. return f > limit::max() || (f < 0 && -static_cast(f) > limit::max()); } else { return f < limit::lowest() || f > limit::max(); } } template typename std::enable_if::value, bool>::type overflows(From f) { using limit = std::numeric_limits::type>; if (limit::has_infinity && std::isinf(static_cast(f))) { return false; } if (!limit::has_quiet_NaN && (f != f)) { return true; } return f < limit::lowest() || f > limit::max(); } ``` MSVC gives C4804 warning and because "treat warnings as errors" is on it fails to build on Windows. Disabling such warning for those 2 templates. Reviewed By: mingzhe09088 Differential Revision: D14421157 fbshipit-source-id: e72ba34406628c84da48518b32a46f851819bad1 --- diff --git a/c10/util/Half.h b/c10/util/Half.h index 37d12b1..3bb6f48 100644 --- a/c10/util/Half.h +++ b/c10/util/Half.h @@ -419,10 +419,12 @@ struct Converter< // In some versions of MSVC, there will be a compiler error when building. // C4146: unary minus operator applied to unsigned type, result still unsigned +// C4804: unsafe use of type 'bool' in operation // It can be addressed by disabling the following warning. #ifdef _MSC_VER #pragma warning( push ) #pragma warning( disable : 4146 ) +#pragma warning( disable : 4804 ) #endif // skip isnan and isinf check for integral types @@ -441,10 +443,6 @@ typename std::enable_if::value, bool>::type overflows( } } -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - template typename std::enable_if::value, bool>::type overflows(From f) { @@ -458,6 +456,10 @@ overflows(From f) { return f < limit::lowest() || f > limit::max(); } +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + template typename std::enable_if::value, bool>::type overflows( From f) {