diff options
| author | Martin Hořeňovský | 2026-05-10 23:05:46 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-05-12 11:05:02 +0200 |
| commit | 651247c7f40eda6846fec736d2f9edac8949dacb (patch) | |
| tree | 76b4ef9f6d100c787f6b8af93779c43ea9524f67 /tests/ExtraTests/X05-DeferredStaticChecks.cpp | |
| parent | 15b9393f0f32327e28833c5032b2c4e02c31d82c (diff) | |
| download | catch3-651247c7f40eda6846fec736d2f9edac8949dacb.tar.gz | |
Support for constexpr matchers in C++20 (P0784)
To make this all work, I had to remove the stringification cache
from matchers. In theory, this can cause performance penalty in
cases where single matcher instance is stringified multiple times,
but in practice this does not happen much, and the difference is
surprisingly small anyway, because the performance of stringification
is already horrible and full of allocating strings just to throw
them away.
The matcher combinators need P2738 from C++26 to be `constexpr`.
Closes #3091
Diffstat (limited to 'tests/ExtraTests/X05-DeferredStaticChecks.cpp')
| -rw-r--r-- | tests/ExtraTests/X05-DeferredStaticChecks.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ExtraTests/X05-DeferredStaticChecks.cpp b/tests/ExtraTests/X05-DeferredStaticChecks.cpp index 8005dbcf..79ff35cc 100644 --- a/tests/ExtraTests/X05-DeferredStaticChecks.cpp +++ b/tests/ExtraTests/X05-DeferredStaticChecks.cpp @@ -12,10 +12,36 @@ */ #include <catch2/catch_test_macros.hpp> +#include <catch2/matchers/catch_matchers_templated.hpp> + +#if defined( CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED ) + +namespace { + struct MatchNoneMatcher final : public Catch::Matchers::MatcherGenericBase { + public: + template <typename Any> + constexpr bool match( Any&& ) const { + return false; + } + + std::string describe() const override { + using namespace std::string_literals; + return "Matches anything"s; + } + }; + + constexpr MatchNoneMatcher MatchNone() { return MatchNoneMatcher(); } + +} // namespace + +#endif TEST_CASE("Deferred static checks") { STATIC_CHECK(1 == 2); STATIC_CHECK_FALSE(1 != 2); +#if defined(CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED) + STATIC_CHECK_THAT(1, MatchNone()); +#endif // This last assertion must be executed too CHECK(1 == 2); } |