From 3d01f3ae3279b806739936f0ffd44598bf20245c Mon Sep 17 00:00:00 2001 From: Rupert Nash Date: Fri, 17 Sep 2021 11:03:25 +0100 Subject: [PATCH] Backport changes from 7bea1e2ac36ac54b648ae5c9d381a59bc69db912 to fix #2273 for 2.x --- include/internal/catch_approx.h | 2 +- projects/SelfTest/UsageTests/Approx.tests.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/internal/catch_approx.h b/include/internal/catch_approx.h index 4522e5ad..2d12efe4 100644 --- a/include/internal/catch_approx.h +++ b/include/internal/catch_approx.h @@ -33,7 +33,7 @@ namespace Detail { Approx operator-() const; template ::value>::type> - 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/projects/SelfTest/UsageTests/Approx.tests.cpp b/projects/SelfTest/UsageTests/Approx.tests.cpp index 4029223a..6280599e 100644 --- a/projects/SelfTest/UsageTests/Approx.tests.cpp +++ b/projects/SelfTest/UsageTests/Approx.tests.cpp @@ -212,4 +212,11 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" ) } +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)); +} + }} // namespace ApproxTests