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:
Martin Hořeňovský
2017-09-06 14:42:44 +02:00
parent aef2e4d9e7
commit b000411434
6 changed files with 56 additions and 58 deletions

View File

@@ -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);
}