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 /src/catch2/internal | |
| 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 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_compiler_capabilities.hpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp index d0c79243..2d6d0c75 100644 --- a/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/src/catch2/internal/catch_compiler_capabilities.hpp @@ -35,6 +35,18 @@ # define CATCH_CPP20_OR_GREATER #endif +// Matchers are only constexpr-able in C++20 +#if defined( CATCH_CPP20_OR_GREATER ) && \ + defined( __cpp_constexpr_dynamic_alloc ) && \ + __cpp_constexpr_dynamic_alloc >= 201907L && \ + /* GCC < 13 define the feature macro, but compiler bugs stop us from using it */ \ + ( !defined( __GNUC__ ) || __GNUC__ >= 13 || defined(__clang__) ) +# define CATCH_INTERNAL_CONSTEXPR_MATCHERS_ENABLED +# define CATCH_DESTRUCTOR_CONSTEXPR constexpr +#else +# define CATCH_DESTRUCTOR_CONSTEXPR +#endif + // Only GCC compiler should be used in this block, so other compilers trying to // mask themselves as GCC should be ignored. #if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) && !defined(__NVCOMPILER) |