diff --git a/opm/core/linalg/ParallelIstlInformation.hpp b/opm/core/linalg/ParallelIstlInformation.hpp index 49504dff4..9dae2c4f7 100644 --- a/opm/core/linalg/ParallelIstlInformation.hpp +++ b/opm/core/linalg/ParallelIstlInformation.hpp @@ -578,18 +578,32 @@ private: namespace detail { - /// \brief Computes the maximum of theabsolute values of two values. - template - struct MaxAbsFunctor - { - typedef T result_type; - - result_type operator()(const T& t1, const T& t2) + /// \brief Computes the maximum of the absolute values of two values. + template + struct MaxAbsFunctor { - return std::max(std::abs(t1),std::abs(t2)); - } - }; + typedef T result_type; + + result_type operator()(const T& t1, const T& t2) + { + return std::max(std::abs(t1),std::abs(t2)); + } + }; + + + /// \brief Specialization to avoid ambiguous abs() for unsigned integers. + template <> + struct MaxAbsFunctor + { + typedef std::size_t result_type; + + result_type operator()(const std::size_t& t1, const std::size_t& t2) + { + return std::max(t1, t2); + } + }; } + /// \brief Create a functor for computing a global L infinity norm /// /// To be used with ParallelISTLInformation::computeReduction. diff --git a/tests/test_parallelistlinformation.cpp b/tests/test_parallelistlinformation.cpp index 8258ad329..f0a07283e 100644 --- a/tests/test_parallelistlinformation.cpp +++ b/tests/test_parallelistlinformation.cpp @@ -33,6 +33,7 @@ #include #ifdef HAVE_DUNE_ISTL + template void runSumMaxMinTest(const T offset) { @@ -60,7 +61,9 @@ void runSumMaxMinTest(const T offset) BOOST_CHECK(std::get<1>(values)==std::max(N+offset-1, std::get<1>(oldvalues))); BOOST_CHECK(std::get<2>(values)==std::min(offset, std::get<2>(oldvalues))); BOOST_CHECK(std::get<3>(values)==((end-1)*end*(2*end-1)-(start-1)*start*(2*start-1))/6+std::get<3>(oldvalues)); - BOOST_CHECK(std::get<4>(values)==std::max(std::abs(offset),std::abs(N+offset-1))); + // Must avoid std::abs() directly to prevent ambiguity with unsigned integers. + Opm::Reduction::detail::MaxAbsFunctor maxabsfunc; + BOOST_CHECK(std::get<4>(values)==maxabsfunc(offset, N+offset-1)); } BOOST_AUTO_TEST_CASE(tupleReductionTestInt)