Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/tests/SelfTest/UsageTests/Compilation.tests.cpp
diff options
context:
space:
mode:
authorMartin Hořeňovský2024-04-08 11:02:22 +0200
committerMartin Hořeňovský2024-04-08 11:33:43 +0200
commit71b11c4e3328090d2ec72268299e3fb9e0ac3f8e (patch)
tree0b835cc8369eedd19f6861988f8885b0ed490187 /tests/SelfTest/UsageTests/Compilation.tests.cpp
parent0a6a2ce88764cc8c01411fee68834571a5b9a0a1 (diff)
downloadcatch3-71b11c4e3328090d2ec72268299e3fb9e0ac3f8e.tar.gz
Fix assertion for const instance of std::ordering
The issue was that `capture_by_value` was meant to be specialized by plain type, e.g. `capture_by_value<std::weak_ordering>`, but the TMP in Decomposer did not properly throw away `const` (and `volatile`) qualifiers, before taking the value of `capture_by_value`.
Diffstat (limited to 'tests/SelfTest/UsageTests/Compilation.tests.cpp')
-rw-r--r--tests/SelfTest/UsageTests/Compilation.tests.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp
index 46ccb8b7..ebb2add6 100644
--- a/tests/SelfTest/UsageTests/Compilation.tests.cpp
+++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp
@@ -357,6 +357,12 @@ namespace {
constexpr friend bool operator op( ZeroLiteralConsteval, \
TypeWithConstevalLit0Comparison ) { \
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( TypeWithConstevalLit0Comparison, \
+ TypeWithConstevalLit0Comparison ) { \
+ return true; \
}
DEFINE_COMP_OP( < )
@@ -394,6 +400,21 @@ TEST_CASE( "#2555 - types that can only be compared with 0 literal implemented a
REQUIRE_FALSE( 0 != TypeWithConstevalLit0Comparison{} );
}
+// We check all comparison ops to test, even though orderings, the primary
+// motivation for this functionality, only have self-comparison (and thus
+// have the ambiguity issue) for `==` and `!=`.
+TEST_CASE( "Comparing const instances of type registered with capture_by_value",
+ "[regression][approvals][compilation]" ) {
+ auto const const_Lit0Type_1 = TypeWithLit0Comparisons{};
+ auto const const_Lit0Type_2 = TypeWithLit0Comparisons{};
+ 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_FALSE( const_Lit0Type_1 != const_Lit0Type_2 );
+}
+
#endif // C++20 consteval
@@ -420,3 +441,17 @@ TEST_CASE("#2571 - tests compile types that have multiple implicit constructors
REQUIRE( mic1 > mic2 );
REQUIRE( mic1 >= mic2 );
}
+
+#if defined( CATCH_CONFIG_CPP20_COMPARE_OVERLOADS )
+// This test does not test all the related codepaths, but it is the original
+// reproducer
+TEST_CASE( "Comparing const std::weak_ordering instances must compile",
+ "[compilation][approvals][regression]" ) {
+ auto const const_ordering_1 = std::weak_ordering::less;
+ auto const const_ordering_2 = std::weak_ordering::less;
+ auto plain_ordering_1 = std::weak_ordering::less;
+ REQUIRE( const_ordering_1 == plain_ordering_1 );
+ REQUIRE( const_ordering_1 == const_ordering_2 );
+ REQUIRE( plain_ordering_1 == const_ordering_1 );
+}
+#endif