mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 05:15:39 +02:00
Support decomposing types that only compare with literal 0
This is primarily done to support new `std::*_ordering` types, but the refactoring also supports any other type with this property. The compilation overhead is surprisingly low. Testing it with clang on a Linux machine, compiling our SelfTest project takes only 2-3% longer with these changes than it takes otherwise. Closes #2555
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
|
||||
// SPDX-License-Identifier: BSL-1.0
|
||||
|
||||
#include <helpers/type_with_lit_0_comparisons.hpp>
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
// Setup for #1403 -- look for global overloads of operator << for classes
|
||||
@@ -310,3 +312,20 @@ TEST_CASE("ADL universal operators don't hijack expression deconstruction", "[co
|
||||
REQUIRE(0 & adl::always_true{});
|
||||
REQUIRE(0 ^ adl::always_true{});
|
||||
}
|
||||
|
||||
TEST_CASE( "#2555 - types that can only be compared with 0 literal (not int/long) are supported", "[compilation][approvals]" ) {
|
||||
REQUIRE( TypeWithLit0Comparisons{} < 0 );
|
||||
REQUIRE_FALSE( 0 < TypeWithLit0Comparisons{} );
|
||||
REQUIRE( TypeWithLit0Comparisons{} <= 0 );
|
||||
REQUIRE_FALSE( 0 > TypeWithLit0Comparisons{} );
|
||||
|
||||
REQUIRE( TypeWithLit0Comparisons{} > 0 );
|
||||
REQUIRE_FALSE( 0 > TypeWithLit0Comparisons{} );
|
||||
REQUIRE( TypeWithLit0Comparisons{} >= 0 );
|
||||
REQUIRE_FALSE( 0 >= TypeWithLit0Comparisons{} );
|
||||
|
||||
REQUIRE( TypeWithLit0Comparisons{} == 0 );
|
||||
REQUIRE_FALSE( 0 == TypeWithLit0Comparisons{} );
|
||||
REQUIRE( TypeWithLit0Comparisons{} != 0 );
|
||||
REQUIRE_FALSE( 0 != TypeWithLit0Comparisons{} );
|
||||
}
|
||||
|
Reference in New Issue
Block a user