diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index c428a58f3..100650c07 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -2097,7 +2097,15 @@ struct expm1_impl> { template struct rsqrt_impl { +// C4804: unsafe use of type 'bool' in operation. Unavoidable when instantiated with T=bool. +#if EIGEN_COMP_MSVC +#pragma warning(push) +#pragma warning(disable : 4804) +#endif EIGEN_DEVICE_FUNC static EIGEN_ALWAYS_INLINE T run(const T& x) { return T(1) / numext::sqrt(x); } +#if EIGEN_COMP_MSVC +#pragma warning(pop) +#endif }; #if defined(EIGEN_GPU_COMPILE_PHASE) diff --git a/Eigen/src/Core/ProductEvaluators.h b/Eigen/src/Core/ProductEvaluators.h index e02e669cc..834c2326b 100644 --- a/Eigen/src/Core/ProductEvaluators.h +++ b/Eigen/src/Core/ProductEvaluators.h @@ -15,6 +15,13 @@ // IWYU pragma: private #include "./InternalHeaderCheck.h" +// C4804: unsafe use of type 'bool' in operation. Unavoidable in generic code +// instantiated with bool scalars (e.g. += and * on bool). +#if EIGEN_COMP_MSVC +#pragma warning(push) +#pragma warning(disable : 4804) +#endif + namespace Eigen { namespace internal { @@ -1260,4 +1267,8 @@ struct generic_product_impl void test_clz_ctz() { - T step = sizeof(T) <= 2 ? 1 : (Eigen::NumTraits::highest() / (T(1) << 16)); + T step = sizeof(T) <= 2 ? T(1) : (Eigen::NumTraits::highest() / (T(1) << 16)); T iters = Eigen::NumTraits::highest() / step; for (T i = 0; i < iters; ++i) { T val = i * step; diff --git a/test/mixingtypes.cpp b/test/mixingtypes.cpp index 1deae95da..047f57422 100644 --- a/test/mixingtypes.cpp +++ b/test/mixingtypes.cpp @@ -89,9 +89,9 @@ void mixingtypes(int size = SizeAtCompileType) { VERIFY_MIX_SCALAR(scd * vd, scd * vd.template cast >()); VERIFY_MIX_SCALAR(vcf * 2, vcf * complex(2)); - VERIFY_MIX_SCALAR(vcf * 2.1, vcf * complex(2.1)); + VERIFY_MIX_SCALAR(vcf * 2.1, vcf * complex(2.1f)); VERIFY_MIX_SCALAR(2 * vcf, vcf * complex(2)); - VERIFY_MIX_SCALAR(2.1 * vcf, vcf * complex(2.1)); + VERIFY_MIX_SCALAR(2.1 * vcf, vcf * complex(2.1f)); // check scalar quotients VERIFY_MIX_SCALAR(vcf / sf, vcf / complex(sf)); diff --git a/test/nullary.cpp b/test/nullary.cpp index a54c61842..2025c83f4 100644 --- a/test/nullary.cpp +++ b/test/nullary.cpp @@ -155,11 +155,11 @@ void testVectorType(const VectorType& base) { VERIFY(m.size() == n0); if (VectorType::SizeAtCompileTime == Dynamic) { - VERIFY_IS_EQUAL(VectorType::LinSpaced(n0, 0, Scalar(n0 - 1)).sum(), Scalar(0)); + VERIFY_IS_EQUAL(VectorType::LinSpaced(n0, 0, Scalar(RealScalar(n0 - 1))).sum(), Scalar(0)); VERIFY_IS_EQUAL(VectorType::LinSpaced(n0, low, low - RealScalar(1)).sum(), Scalar(0)); } - m.setLinSpaced(n0, 0, Scalar(n0 - 1)); + m.setLinSpaced(n0, 0, Scalar(RealScalar(n0 - 1))); VERIFY(m.size() == n0); m.setLinSpaced(n0, low, low - RealScalar(1)); VERIFY(m.size() == n0); @@ -170,18 +170,18 @@ void testVectorType(const VectorType& base) { VERIFY_IS_APPROX(m, VectorType::Constant(size, low)); if (NumTraits::IsInteger) { - VERIFY_IS_APPROX(VectorType::LinSpaced(size, low, low + Scalar(size - 1)), - VectorType::LinSpaced(size, low + Scalar(size - 1), low).reverse()); + VERIFY_IS_APPROX(VectorType::LinSpaced(size, low, low + Scalar(RealScalar(size - 1))), + VectorType::LinSpaced(size, low + Scalar(RealScalar(size - 1)), low).reverse()); if (VectorType::SizeAtCompileTime == Dynamic) { // Check negative multiplicator path: for (Index k = 1; k < 5; ++k) - VERIFY_IS_APPROX(VectorType::LinSpaced(size, low, low + Scalar((size - 1) * k)), - VectorType::LinSpaced(size, low + Scalar((size - 1) * k), low).reverse()); + VERIFY_IS_APPROX(VectorType::LinSpaced(size, low, low + Scalar(RealScalar((size - 1) * k))), + VectorType::LinSpaced(size, low + Scalar(RealScalar((size - 1) * k)), low).reverse()); // Check negative divisor path: for (Index k = 1; k < 5; ++k) - VERIFY_IS_APPROX(VectorType::LinSpaced(size * k, low, low + Scalar(size - 1)), - VectorType::LinSpaced(size * k, low + Scalar(size - 1), low).reverse()); + VERIFY_IS_APPROX(VectorType::LinSpaced(size * k, low, low + Scalar(RealScalar(size - 1))), + VectorType::LinSpaced(size * k, low + Scalar(RealScalar(size - 1)), low).reverse()); } } } diff --git a/test/numext.cpp b/test/numext.cpp index 98ffdcc4f..32e9dcadc 100644 --- a/test/numext.cpp +++ b/test/numext.cpp @@ -45,10 +45,17 @@ void check_negate() { } template -std::enable_if_t::IsInteger, T> random_abs2_input() { +std::enable_if_t::IsInteger && NumTraits::IsSigned, T> random_abs2_input() { const T safeAbs2Input = static_cast(std::sqrt(static_cast(NumTraits::highest()))); - return NumTraits::IsSigned ? internal::random(-safeAbs2Input, safeAbs2Input) - : internal::random(T(0), safeAbs2Input); + return internal::random(-safeAbs2Input, safeAbs2Input); +} + +// Note: bool resolves here (IsInteger && !IsSigned), but check_abs is fully +// specialized and never calls random_abs2_input(). +template +std::enable_if_t::IsInteger && !NumTraits::IsSigned, T> random_abs2_input() { + const T safeAbs2Input = static_cast(std::sqrt(static_cast(NumTraits::highest()))); + return internal::random(T(0), safeAbs2Input); } template diff --git a/test/packetmath.cpp b/test/packetmath.cpp index 38c27d709..b8a7f4321 100644 --- a/test/packetmath.cpp +++ b/test/packetmath.cpp @@ -721,6 +721,11 @@ void packetmath() { } } +// C4804: unsafe use of type 'bool' in operation. Unavoidable when Scalar=bool. +#if EIGEN_COMP_MSVC +#pragma warning(push) +#pragma warning(disable : 4804) +#endif ref[0] = Scalar(0); for (int i = 0; i < PacketSize; ++i) ref[0] += data1[i]; VERIFY(test::isApproxAbs(ref[0], internal::predux(internal::pload(data1)), refvalue) && "internal::predux"); @@ -732,6 +737,9 @@ void packetmath() { internal::pstore(data2, internal::predux_half(internal::pload(data1))); VERIFY(test::areApprox(ref, data2, HalfPacketSize) && "internal::predux_half"); } +#if EIGEN_COMP_MSVC +#pragma warning(pop) +#endif // Avoid overflows. if (NumTraits::IsInteger && NumTraits::IsSigned &&