mirror of
https://github.com/catchorg/Catch2.git
synced 2025-11-03 16:42:00 +01:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user