diff options
author | Alexey Kozhevnikov <akozhevnikov@fb.com> | 2019-03-12 19:48:11 -0700 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-03-12 19:53:56 -0700 |
commit | f7b70a69e5095a59dcec755cace5016bf2ad9c9e (patch) | |
tree | bf77c53b1651ccf7406608861362a3f1f4004975 /c10 | |
parent | 92e35ac0a76b9f07052120a95d6c573a020c626d (diff) | |
download | pytorch-f7b70a69e5095a59dcec755cace5016bf2ad9c9e.tar.gz pytorch-f7b70a69e5095a59dcec755cace5016bf2ad9c9e.tar.bz2 pytorch-f7b70a69e5095a59dcec755cace5016bf2ad9c9e.zip |
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 To, typename From>
typename std::enable_if<std::is_integral<From>::value, bool>::type overflows(
From f) {
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
if (!limit::is_signed && std::numeric_limits<From>::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<uint64_t>(f) > limit::max());
} else {
return f < limit::lowest() || f > limit::max();
}
}
template <typename To, typename From>
typename std::enable_if<std::is_floating_point<From>::value, bool>::type
overflows(From f) {
using limit = std::numeric_limits<typename scalar_value_type<To>::type>;
if (limit::has_infinity && std::isinf(static_cast<double>(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
Diffstat (limited to 'c10')
-rw-r--r-- | c10/util/Half.h | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/c10/util/Half.h b/c10/util/Half.h index 37d12b162c..3bb6f48056 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<std::is_integral<From>::value, bool>::type overflows( } } -#ifdef _MSC_VER -#pragma warning( pop ) -#endif - template <typename To, typename From> typename std::enable_if<std::is_floating_point<From>::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 To, typename From> typename std::enable_if<is_complex_t<From>::value, bool>::type overflows( From f) { |