Skip to content

Commit f2db3e0

Browse files
committed
Work around GCC co_await bugs in test macros
Related GCC issues: * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101027 * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116775 Related Catch2 issues: * #2591 * #2925
1 parent 11a96e1 commit f2db3e0

3 files changed

Lines changed: 9 additions & 32 deletions

File tree

src/catch2/internal/catch_compiler_capabilities.hpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,6 @@
130130

131131
#endif // __clang__
132132

133-
// As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
134-
// which results in calls to destructors being emitted for each temporary,
135-
// without a matching initialization. In practice, this can result in something
136-
// like `std::string::~string` being called on an uninitialized value.
137-
//
138-
// For example, this code will likely segfault under IBM XL:
139-
// ```
140-
// REQUIRE(std::string("12") + "34" == "1234")
141-
// ```
142-
//
143-
// Similarly, NVHPC's implementation of `__builtin_constant_p` has a bug which
144-
// results in calls to the immediately evaluated lambda expressions to be
145-
// reported as unevaluated lambdas.
146-
// https://developer.nvidia.com/nvidia_bug/3321845.
147-
//
148-
// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
149-
#if defined( __ibmxl__ ) || defined( __CUDACC__ ) || defined( __NVCOMPILER )
150-
# define CATCH_INTERNAL_CONFIG_NO_USE_BUILTIN_CONSTANT_P
151-
#endif
152-
153133

154134

155135
////////////////////////////////////////////////////////////////////////////////
@@ -390,15 +370,6 @@
390370
#define CATCH_CONFIG_USE_BUILTIN_CONSTANT_P
391371
#endif
392372

393-
#if defined( CATCH_CONFIG_USE_BUILTIN_CONSTANT_P ) && \
394-
!defined( CATCH_CONFIG_NO_USE_BUILTIN_CONSTANT_P )
395-
# define CATCH_INTERNAL_IGNORE_BUT_WARN( ... ) \
396-
(void)__builtin_constant_p( __VA_ARGS__ ) /* NOLINT(cppcoreguidelines-pro-type-vararg, \
397-
hicpp-vararg) */
398-
#else
399-
# define CATCH_INTERNAL_IGNORE_BUT_WARN( ... )
400-
#endif
401-
402373
// Even if we do not think the compiler has that warning, we still have
403374
// to provide a macro that can be used by the code.
404375
#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)

src/catch2/internal/catch_run_context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ namespace Catch {
328328

329329
bool lastAssertionPassed() { return Detail::g_lastAssertionPassed; }
330330

331+
volatile bool volatileFalse = false;
332+
331333
} // namespace Detail
332334

333335
RunContext::RunContext(IConfig const* _config, IEventListenerPtr&& reporter)

src/catch2/internal/catch_test_macro_impl.hpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ namespace Catch {
1818
namespace Detail {
1919
// Defined in catch_run_context.cpp, where the thread-local data lives.
2020
bool lastAssertionPassed();
21+
22+
// A technically non-constant false. Prevents the compiler from warning
23+
// about or eliminating constant branch conditions.
24+
extern volatile bool volatileFalse;
2125
}
2226
}
2327

@@ -48,7 +52,8 @@ namespace Catch {
4852
#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
4953
do { /* NOLINT(bugprone-infinite-loop) */ \
5054
/* The expression should not be evaluated, but warnings should hopefully be checked */ \
51-
CATCH_INTERNAL_IGNORE_BUT_WARN(__VA_ARGS__); \
55+
if(::Catch::Detail::volatileFalse) \
56+
(void)(__VA_ARGS__); \
5257
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
5358
INTERNAL_CATCH_TRY { \
5459
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
@@ -57,8 +62,7 @@ namespace Catch {
5762
CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
5863
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
5964
catchAssertionHandler.complete(); \
60-
} while( (void)0, (false) && static_cast<const bool&>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
61-
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
65+
} while(false)
6266

6367
///////////////////////////////////////////////////////////////////////////////
6468
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \

0 commit comments

Comments
 (0)