Fix & extend tests for comparing const instances of zero lit types

This commit is contained in:
Martin Hořeňovský 2024-04-08 13:15:31 +02:00
parent 71b11c4e33
commit 05fb437cbb
No known key found for this signature in database
GPG Key ID: DE48307B8B0D381A
2 changed files with 34 additions and 16 deletions

View File

@ -405,6 +405,17 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal implemented a
// have the ambiguity issue) for `==` and `!=`.
TEST_CASE( "Comparing const instances of type registered with capture_by_value",
"[regression][approvals][compilation]" ) {
SECTION("Type with consteval-int constructor") {
auto const const_Lit0Type_1 = TypeWithConstevalLit0Comparison{};
auto const const_Lit0Type_2 = TypeWithConstevalLit0Comparison{};
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
}
SECTION("Type with constexpr-int constructor") {
auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
@ -412,7 +423,8 @@ TEST_CASE( "Comparing const instances of type registered with capture_by_value",
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
REQUIRE_FALSE( const_Lit0Type_1 != const_Lit0Type_2 );
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
}
}
#endif // C++20 consteval

View File

@ -34,6 +34,12 @@ struct TypeWithLit0Comparisons {
constexpr friend bool operator op( ZeroLiteralAsPointer, \
TypeWithLit0Comparisons ) { \
return false; \
} \
/* std::orderings only have these for ==, but we add them for all \
operators so we can test all overloads for decomposer */ \
constexpr friend bool operator op( TypeWithLit0Comparisons, \
TypeWithLit0Comparisons ) { \
return true; \
}
DEFINE_COMP_OP( < )