diff --git a/src/catch2/catch_approx.hpp b/src/catch2/catch_approx.hpp index 8f0e6327..7c3a17c0 100644 --- a/src/catch2/catch_approx.hpp +++ b/src/catch2/catch_approx.hpp @@ -30,7 +30,7 @@ namespace Catch { Approx operator-() const; template ::value>> - Approx operator()( T const& value ) { + Approx operator()( T const& value ) const { Approx approx( static_cast(value) ); approx.m_epsilon = m_epsilon; approx.m_margin = m_margin; diff --git a/tests/SelfTest/UsageTests/Approx.tests.cpp b/tests/SelfTest/UsageTests/Approx.tests.cpp index 96f9706d..1ae5fe04 100644 --- a/tests/SelfTest/UsageTests/Approx.tests.cpp +++ b/tests/SelfTest/UsageTests/Approx.tests.cpp @@ -209,3 +209,10 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" ) REQUIRE(Approx(11.0) >= td); } + +TEST_CASE("Approx::operator() is const correct", "[Approx][.approvals]") { + const Approx ap = Approx(0.0).margin(0.01); + + // As long as this compiles, the test should be considered passing + REQUIRE(1.0 == ap(1.0)); +}