Skip to content

Commit 51b0532

Browse files
committed
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
1 parent 2ec64d1 commit 51b0532

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/catch2/internal/catch_compiler_capabilities.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@
114114
_Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
115115
# endif
116116

117+
# if ( __clang_major__ >= 22 )
118+
# define CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS \
119+
_Pragma( "clang diagnostic ignored \"-Wc2y-extensions\"" )
120+
# endif
121+
117122
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
118123
_Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
119124

@@ -429,6 +434,9 @@
429434
#if !defined( CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS )
430435
# define CATCH_INTERNAL_SUPPRESS_SHADOW_WARNINGS
431436
#endif
437+
#if !defined( CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS )
438+
# define CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS
439+
#endif
432440

433441
#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
434442
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS

src/catch2/internal/catch_unique_name.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,22 @@
88
#ifndef CATCH_UNIQUE_NAME_HPP_INCLUDED
99
#define CATCH_UNIQUE_NAME_HPP_INCLUDED
1010

11+
#include <catch2/internal/catch_compiler_capabilities.hpp>
1112
#include <catch2/internal/catch_config_counter.hpp>
13+
14+
// Fixme: Clang 22 has an annoying bug where the localized suppression
15+
// below does not actually suppress the extension warning from
16+
// using __COUNTER__, so we have to leak the suppression for the
17+
// whole TU. Hopefully Clang 23 fixes this before full release.
18+
// As AppleClang does its own thing version-wise, we ignore it
19+
// completely.
20+
#if defined( __clang__ ) && ( __clang_major__ >= 22 ) && !defined( __APPLE__ )
21+
CATCH_INTERNAL_SUPPRESS_COUNTER_WARNINGS
22+
#endif
23+
1224
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
1325
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
26+
1427
#ifdef CATCH_CONFIG_COUNTER
1528
# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
1629
#else

0 commit comments

Comments
 (0)