From c2b7bd15c092e2528f52bf26046e3c55ca629392 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Fri, 13 Oct 2017 14:16:14 +0100 Subject: [PATCH] Changed rhs expression capture from universal ref to const ref. - addresses #1027 --- include/internal/catch_decomposer.h | 26 +++++++++---------- .../Baselines/console.std.approved.txt | 4 +-- .../Baselines/console.sw.approved.txt | 22 ++++++++++++++-- .../SelfTest/Baselines/junit.sw.approved.txt | 3 ++- .../SelfTest/Baselines/xml.sw.approved.txt | 23 ++++++++++++++-- projects/SelfTest/TrickyTests.cpp | 11 +++++++- 6 files changed, 68 insertions(+), 21 deletions(-) diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index 786a052e..fee24e72 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -77,7 +77,7 @@ namespace Catch { // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) template - auto compareEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs == rhs; }; + auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; }; template auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); } template @@ -106,36 +106,36 @@ namespace Catch { ExprLhs( LhsT lhs ) : m_lhs( lhs ) {} template - auto operator == ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( compareEqual( m_lhs, rhs ), m_lhs, "==", rhs ); + auto operator == ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( compareEqual( m_lhs, rhs ), m_lhs, "==", rhs ); } auto operator == ( bool rhs ) -> BinaryExpr const { return BinaryExpr( m_lhs == rhs, m_lhs, "==", rhs ); } template - auto operator != ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs ); + auto operator != ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs ); } auto operator != ( bool rhs ) -> BinaryExpr const { return BinaryExpr( m_lhs != rhs, m_lhs, "!=", rhs ); } template - auto operator > ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( m_lhs > rhs, m_lhs, ">", rhs ); + auto operator > ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( m_lhs > rhs, m_lhs, ">", rhs ); } template - auto operator < ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( m_lhs < rhs, m_lhs, "<", rhs ); + auto operator < ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( m_lhs < rhs, m_lhs, "<", rhs ); } template - auto operator >= ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( m_lhs >= rhs, m_lhs, ">=", rhs ); + auto operator >= ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( m_lhs >= rhs, m_lhs, ">=", rhs ); } template - auto operator <= ( RhsT&& rhs ) -> BinaryExpr const { - return BinaryExpr( m_lhs <= rhs, m_lhs, "<=", rhs ); + auto operator <= ( RhsT const& rhs ) -> BinaryExpr const { + return BinaryExpr( m_lhs <= rhs, m_lhs, "<=", rhs ); } auto makeUnaryExpr() const -> UnaryExpr { diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 6aaa7ed1..939d0d89 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1003,6 +1003,6 @@ with expansion: "{?}" == "1" =============================================================================== -test cases: 179 | 128 passed | 47 failed | 4 failed as expected -assertions: 884 | 767 passed | 96 failed | 21 failed as expected +test cases: 180 | 129 passed | 47 failed | 4 failed as expected +assertions: 886 | 769 passed | 96 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 10b6fc35..1d64df20 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -738,6 +738,24 @@ PASSED: with expansion: true +------------------------------------------------------------------------------- +Bitfields can be captured (#1027) +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + REQUIRE( y.v == 0 ) +with expansion: + 0 == 0 + +TrickyTests.cpp:: +PASSED: + REQUIRE( 0 == y.v ) +with expansion: + 0 == 0 + ------------------------------------------------------------------------------- Capture and info messages Capture should stringify like assertions @@ -7490,6 +7508,6 @@ MiscTests.cpp:: PASSED: =============================================================================== -test cases: 179 | 126 passed | 49 failed | 4 failed as expected -assertions: 883 | 763 passed | 99 failed | 21 failed as expected +test cases: 180 | 127 passed | 49 failed | 4 failed as expected +assertions: 885 | 765 passed | 99 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index b306b393..508b9206 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -109,6 +109,7 @@ ExceptionTests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index da12285d..72b7c1b6 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -750,6 +750,25 @@ + + + + y.v == 0 + + + 0 == 0 + + + + + 0 == y.v + + + 0 == 0 + + + +
@@ -8268,7 +8287,7 @@ loose text artifact
- + - + diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 78f7052f..820d2fbd 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -168,7 +168,7 @@ namespace ObjectWithConversions { struct Object { - operator unsigned int() {return 0xc0000000;} + operator unsigned int() const {return 0xc0000000;} }; /////////////////////////////////////////////////////////////////////////////// @@ -436,3 +436,12 @@ TEST_CASE("#925: comparing function pointer to function address failed to compil TestClass test; REQUIRE(utility::synchronizing_callback != test.testMethod_uponComplete_arg); } + +TEST_CASE( "Bitfields can be captured (#1027)" ) { + struct Y { + uint32_t v : 1; + }; + Y y{ 0 }; + REQUIRE( y.v == 0 ); + REQUIRE( 0 == y.v ); +}