Skip to content

Commit 05fb437

Browse files
committed
Fix & extend tests for comparing const instances of zero lit types
1 parent 71b11c4 commit 05fb437

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

tests/SelfTest/UsageTests/Compilation.tests.cpp

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,14 +405,26 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal implemented a
405405
// have the ambiguity issue) for `==` and `!=`.
406406
TEST_CASE( "Comparing const instances of type registered with capture_by_value",
407407
"[regression][approvals][compilation]" ) {
408-
auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
409-
auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
410-
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
411-
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
412-
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
413-
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
414-
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
415-
REQUIRE_FALSE( const_Lit0Type_1 != const_Lit0Type_2 );
408+
SECTION("Type with consteval-int constructor") {
409+
auto const const_Lit0Type_1 = TypeWithConstevalLit0Comparison{};
410+
auto const const_Lit0Type_2 = TypeWithConstevalLit0Comparison{};
411+
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
412+
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
413+
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
414+
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
415+
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
416+
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
417+
}
418+
SECTION("Type with constexpr-int constructor") {
419+
auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
420+
auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
421+
REQUIRE( const_Lit0Type_1 == const_Lit0Type_2 );
422+
REQUIRE( const_Lit0Type_1 <= const_Lit0Type_2 );
423+
REQUIRE( const_Lit0Type_1 < const_Lit0Type_2 );
424+
REQUIRE( const_Lit0Type_1 >= const_Lit0Type_2 );
425+
REQUIRE( const_Lit0Type_1 > const_Lit0Type_2 );
426+
REQUIRE( const_Lit0Type_1 != const_Lit0Type_2 );
427+
}
416428
}
417429

418430
#endif // C++20 consteval

tests/SelfTest/helpers/type_with_lit_0_comparisons.hpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,20 @@ struct ZeroLiteralAsPointer {
2626

2727

2828
struct TypeWithLit0Comparisons {
29-
#define DEFINE_COMP_OP( op ) \
30-
constexpr friend bool operator op( TypeWithLit0Comparisons, \
31-
ZeroLiteralAsPointer ) { \
32-
return true; \
33-
} \
34-
constexpr friend bool operator op( ZeroLiteralAsPointer, \
35-
TypeWithLit0Comparisons ) { \
36-
return false; \
29+
#define DEFINE_COMP_OP( op ) \
30+
constexpr friend bool operator op( TypeWithLit0Comparisons, \
31+
ZeroLiteralAsPointer ) { \
32+
return true; \
33+
} \
34+
constexpr friend bool operator op( ZeroLiteralAsPointer, \
35+
TypeWithLit0Comparisons ) { \
36+
return false; \
37+
} \
38+
/* std::orderings only have these for ==, but we add them for all \
39+
operators so we can test all overloads for decomposer */ \
40+
constexpr friend bool operator op( TypeWithLit0Comparisons, \
41+
TypeWithLit0Comparisons ) { \
42+
return true; \
3743
}
3844

3945
DEFINE_COMP_OP( < )

0 commit comments

Comments
 (0)