From 4b2cebade8512abe05e94fd08ef901d818d8912b Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Wed, 21 Nov 2018 15:53:37 +0100 Subject: [PATCH] Workaround weird MSVC bug --- Eigen/src/SVD/SVDBase.h | 4 +++- test/jacobi.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Eigen/src/SVD/SVDBase.h b/Eigen/src/SVD/SVDBase.h index 429414797..1aede5ab0 100644 --- a/Eigen/src/SVD/SVDBase.h +++ b/Eigen/src/SVD/SVDBase.h @@ -180,8 +180,10 @@ public: RealScalar threshold() const { eigen_assert(m_isInitialized || m_usePrescribedThreshold); + // this temporary is needed to workaround a MSVC issue + Index diagSize = (std::max)(1,m_diagSize); return m_usePrescribedThreshold ? m_prescribedThreshold - : (std::max)(1,m_diagSize)*NumTraits::epsilon(); + : diagSize*NumTraits::epsilon(); } /** \returns true if \a U (full or thin) is asked for in this SVD decomposition */ diff --git a/test/jacobi.cpp b/test/jacobi.cpp index 5604797f5..27b6e46d9 100644 --- a/test/jacobi.cpp +++ b/test/jacobi.cpp @@ -57,6 +57,19 @@ void jacobi(const MatrixType& m = MatrixType()) } } +namespace Foo { +class Bar {}; +bool operator<(const Bar&, const Bar&) { return true; } +} +// regression test for a very strange MSVC issue for which simply +// including SVDBase.h messes up with std::max and custom scalar type +void msvc_workaround() +{ + const Foo::Bar a; + const Foo::Bar b; + std::max EIGEN_NOT_A_MACRO (a,b); +} + EIGEN_DECLARE_TEST(jacobi) { for(int i = 0; i < g_repeat; i++) { @@ -77,4 +90,6 @@ EIGEN_DECLARE_TEST(jacobi) TEST_SET_BUT_UNUSED_VARIABLE(r); TEST_SET_BUT_UNUSED_VARIABLE(c); } + + msvc_workaround(); }