From b00041143483949b35f3670ba9ceb5452bf5102d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Wed, 6 Sep 2017 14:42:44 +0200 Subject: [PATCH] Stop accepting non-const comparison operators A) non-const comparison operators should not exist and should not be encouraged B) The logic breaks comparing function pointers certain way C) It was inconsistent anyway, as it only applied to `==` and `!=` Closes #925 --- include/internal/catch_decomposer.h | 8 +--- .../Baselines/console.sw.approved.txt | 24 +++++------ .../Baselines/console.swa4.approved.txt | 16 ++++++- .../SelfTest/Baselines/junit.sw.approved.txt | 2 +- .../SelfTest/Baselines/xml.sw.approved.txt | 22 +++++----- projects/SelfTest/TrickyTests.cpp | 42 +++++++------------ 6 files changed, 56 insertions(+), 58 deletions(-) diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index 03c11568..c61ca856 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -76,7 +76,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 const_cast( lhs ) == rhs; }; + auto compareEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs == rhs; }; template auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast( rhs ); }; template @@ -87,7 +87,7 @@ namespace Catch { auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast( lhs ) == rhs; }; template - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return const_cast( lhs ) != rhs; }; + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; }; template auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast( rhs ); }; template @@ -150,10 +150,6 @@ namespace Catch { } struct Decomposer { - template - auto operator <= ( T& lhs ) -> ExprLhs { - return ExprLhs( lhs ); - } template auto operator <= ( T const& lhs ) -> ExprLhs { return ExprLhs( lhs ); diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index ea723223..76a0819d 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -156,6 +156,18 @@ with expansion: with message: dummy := 0 +------------------------------------------------------------------------------- +#925: comparing function pointer to function address failed to compile +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + REQUIRE( utility::synchronizing_callback != test.testMethod_uponComplete_arg ) +with expansion: + 1 != 0 + ------------------------------------------------------------------------------- #961 -- Dynamically created sections should all be reported Looped section 0 @@ -1215,18 +1227,6 @@ ExceptionTests.cpp:: FAILED: due to unexpected exception with message: custom std exception -------------------------------------------------------------------------------- -Demonstrate that a non-const == is not used -------------------------------------------------------------------------------- -TrickyTests.cpp: -............................................................................... - -TrickyTests.cpp:: -PASSED: - REQUIRE( t == 1u ) -with expansion: - {?} == 1 - ------------------------------------------------------------------------------- EndsWith string matcher ------------------------------------------------------------------------------- diff --git a/projects/SelfTest/Baselines/console.swa4.approved.txt b/projects/SelfTest/Baselines/console.swa4.approved.txt index 06c24e86..ef9fd05f 100644 --- a/projects/SelfTest/Baselines/console.swa4.approved.txt +++ b/projects/SelfTest/Baselines/console.swa4.approved.txt @@ -156,6 +156,18 @@ with expansion: with message: dummy := 0 +------------------------------------------------------------------------------- +#925: comparing function pointer to function address failed to compile +------------------------------------------------------------------------------- +TrickyTests.cpp: +............................................................................... + +TrickyTests.cpp:: +PASSED: + REQUIRE( utility::synchronizing_callback != test.testMethod_uponComplete_arg ) +with expansion: + 1 != 0 + ------------------------------------------------------------------------------- #961 -- Dynamically created sections should all be reported Looped section 0 @@ -237,6 +249,6 @@ ConditionTests.cpp:: FAILED: CHECK_FALSE( true ) =============================================================================== -test cases: 9 | 6 passed | 1 failed | 2 failed as expected -assertions: 26 | 19 passed | 4 failed | 3 failed as expected +test cases: 10 | 7 passed | 1 failed | 2 failed as expected +assertions: 27 | 20 passed | 4 failed | 3 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index d0026667..88abcd9c 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -27,6 +27,7 @@ MiscTests.cpp: + @@ -143,7 +144,6 @@ custom std exception ExceptionTests.cpp: - MatchersTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 310e3e0a..5e1312ca 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -169,6 +169,17 @@ + + + + utility::synchronizing_callback != test.testMethod_uponComplete_arg + + + 1 != 0 + + + +
@@ -1336,17 +1347,6 @@ - - - - t == 1u - - - {?} == 1 - - - - diff --git a/projects/SelfTest/TrickyTests.cpp b/projects/SelfTest/TrickyTests.cpp index 90abb4a8..312638f2 100644 --- a/projects/SelfTest/TrickyTests.cpp +++ b/projects/SelfTest/TrickyTests.cpp @@ -183,32 +183,6 @@ namespace ObjectWithConversions } } -namespace ObjectWithNonConstEqualityOperator -{ - struct Test - { - Test( unsigned int v ) - : m_value(v) - {} - - bool operator==( const Test&rhs ) - { - return (m_value == rhs.m_value); - } - bool operator==( const Test&rhs ) const - { - return (m_value != rhs.m_value); - } - unsigned int m_value; - }; - - TEST_CASE("Demonstrate that a non-const == is not used", "[Tricky]" ) - { - Test t( 1 ); - REQUIRE( t == 1u ); - } -} - namespace EnumBitFieldTests { enum Bits : uint32_t { @@ -448,3 +422,19 @@ TEST_CASE( "non-copyable objects", "[.][failing]" ) { std::type_info const& ti = typeid(int); CHECK( ti == typeid(int) ); } + +// #925 +using signal_t = void (*) (void*); + +struct TestClass { + signal_t testMethod_uponComplete_arg = nullptr; +}; + +namespace utility { + inline static void synchronizing_callback( void * ) { } +} + +TEST_CASE("#925: comparing function pointer to function address failed to compile") { + TestClass test; + REQUIRE(utility::synchronizing_callback != test.testMethod_uponComplete_arg); +}