diff options
| author | Martin Hořeňovský | 2026-04-01 10:34:54 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2026-04-01 10:34:58 +0200 |
| commit | 51b0532d1fba061d0802ccfd906cc87fc2dd49c2 (patch) | |
| tree | 32823a525df8b959722e32c6d23b2a304887c0bf /src/catch2 | |
| parent | 2ec64d12b198cd25a9ca84230a2be7cfd24494fa (diff) | |
| download | catch3-51b0532d1fba061d0802ccfd906cc87fc2dd49c2.tar.gz | |
Suppress __COUNTER__ warning from newest Clang versions
Ideally we could suppress the warning locally in the `UNIQUE_NAME` macro,
but that runs into at least 2 issues:
1) Clang actually does not consider the warning as coming from inside the
`UNIQUE_NAME` macro, even though it correctly points to its expansion
as the problem. This means that adding `_Pragma`s inside the macro
around the __COUNTER__ usage does not actually silence the warning.
2) Adding the local suppressions anyway breaks the expansion of
`MAKE_NAMESPACE` macro inside the templated test case macros. This can
be fixed for the newest clang version by removing its use and using
the uniqued `TestName` for the namespace name directly, but this breaks
compilation on GCC, and older Clang versions.
Because of these issues, we introduce global warning suppression for
`-Wc2y-extensions` to be done with it. We should revisit this if Clang 23
fixes the local pragma based suppression, when it might be worth the effort
to rework the templated test case macros to support it.
Closes #3076
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/internal/catch_compiler_capabilities.hpp | 8 | ||||
| -rw-r--r-- | src/catch2/internal/catch_unique_name.hpp | 13 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp index 59839c17..2bbee6bc 100644 --- a/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/src/catch2/internal/catch_compiler_capabilities.hpp @@ -114,6 +114,11 @@ _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) # endif +# if ( __clang_major__ >= 22 ) +# define CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wc2y-extensions\"" ) +# endif + # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) @@ -429,6 +434,9 @@ #if !defined( CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS ) # define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS #endif +#if !defined( CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS ) +# define CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS +#endif #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS diff --git a/src/catch2/internal/catch_unique_name.hpp b/src/catch2/internal/catch_unique_name.hpp index c6e1c2ca..b8c08fa2 100644 --- a/src/catch2/internal/catch_unique_name.hpp +++ b/src/catch2/internal/catch_unique_name.hpp @@ -8,9 +8,22 @@ #ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED #define CATCH_UNIQUE_NAME_HPP_INCLUDED +#include <catch2/internal/catch_compiler_capabilities.hpp> #include <catch2/internal/catch_config_counter.hpp> + +// Fixme: Clang 22 has an annoying bug where the localized suppression +// below does not actually suppress the extension warning from +// using __COUNTER__, so we have to leak the suppression for the +// whole TU. Hopefully Clang 23 fixes this before full release. +// As AppleClang does its own thing version-wise, we ignore it +// completely. +#if defined( __clang__ ) && ( __clang_major__ >= 22 ) && !defined( __APPLE__ ) +CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS +#endif + #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) + #ifdef CATCH_CONFIG_COUNTER # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) #else |