diff --git a/src/catch2/benchmark/catch_optimizer.hpp b/src/catch2/benchmark/catch_optimizer.hpp index b9af3ea1..30dd7594 100644 --- a/src/catch2/benchmark/catch_optimizer.hpp +++ b/src/catch2/benchmark/catch_optimizer.hpp @@ -14,13 +14,14 @@ # include // atomic_thread_fence #endif +#include #include #include namespace Catch { namespace Benchmark { -#if defined(__GNUC__) || defined(__clang__) +#if defined(CATCH_COMPILER_GCC) || defined(__clang__) template inline void keep_memory(T* p) { asm volatile("" : : "g"(p) : "memory"); diff --git a/src/catch2/catch_template_test_macros.hpp b/src/catch2/catch_template_test_macros.hpp index 66b1bc4d..df30ddd0 100644 --- a/src/catch2/catch_template_test_macros.hpp +++ b/src/catch2/catch_template_test_macros.hpp @@ -8,11 +8,13 @@ #ifndef CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED #define CATCH_TEMPLATE_TEST_MACROS_HPP_INCLUDED +#include + // We need this suppression to leak, because it took until GCC 10 // for the front end to handle local suppression via _Pragma properly // inside templates (so `TEMPLATE_TEST_CASE` and co). // **THIS IS DIFFERENT FOR STANDARD TESTS, WHERE GCC 9 IS SUFFICIENT** -#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 10 +#if defined(CATCH_COMPILER_GCC) && __GNUC__ < 10 #pragma GCC diagnostic ignored "-Wparentheses" #endif diff --git a/src/catch2/internal/catch_clara.hpp b/src/catch2/internal/catch_clara.hpp index 00761c0a..93be0469 100644 --- a/src/catch2/internal/catch_clara.hpp +++ b/src/catch2/internal/catch_clara.hpp @@ -15,7 +15,7 @@ # pragma clang diagnostic ignored "-Wdeprecated" #endif -#if defined( __GNUC__ ) +#if defined( CATCH_COMPILER_GCC ) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wsign-conversion" #endif @@ -702,7 +702,7 @@ namespace Catch { # pragma clang diagnostic pop #endif -#if defined( __GNUC__ ) +#if defined( CATCH_COMPILER_GCC ) # pragma GCC diagnostic pop #endif diff --git a/src/catch2/internal/catch_compiler_capabilities.hpp b/src/catch2/internal/catch_compiler_capabilities.hpp index 5c5c8f64..e2d44dc1 100644 --- a/src/catch2/internal/catch_compiler_capabilities.hpp +++ b/src/catch2/internal/catch_compiler_capabilities.hpp @@ -27,6 +27,10 @@ #include #include +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && !defined(__CUDACC__) && !defined(__LCC__) +#define CATCH_COMPILER_GCC +#endif + #ifdef __cplusplus # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) @@ -41,7 +45,7 @@ // 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__) +#if defined(CATCH_COMPILER_GCC) # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) diff --git a/src/catch2/internal/catch_debugger.hpp b/src/catch2/internal/catch_debugger.hpp index c300da72..9bb80194 100644 --- a/src/catch2/internal/catch_debugger.hpp +++ b/src/catch2/internal/catch_debugger.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_DEBUGGER_HPP_INCLUDED #define CATCH_DEBUGGER_HPP_INCLUDED +#include #include namespace Catch { @@ -39,7 +40,7 @@ namespace Catch { // If we can use inline assembler, do it because this allows us to break // directly at the location of the failing check instead of breaking inside // raise() called from it, i.e. one stack frame below. - #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64)) + #if defined(CATCH_COMPILER_GCC) && (defined(__i386) || defined(__x86_64)) #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */ #else // Fall back to the generic way. #include diff --git a/src/catch2/internal/catch_decomposer.hpp b/src/catch2/internal/catch_decomposer.hpp index e7dd1e9a..7f4dcc8f 100644 --- a/src/catch2/internal/catch_decomposer.hpp +++ b/src/catch2/internal/catch_decomposer.hpp @@ -26,7 +26,7 @@ #ifdef __clang__ # pragma clang diagnostic push # pragma clang diagnostic ignored "-Wsign-compare" -#elif defined __GNUC__ +#elif defined CATCH_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wsign-compare" #endif @@ -261,7 +261,7 @@ namespace Catch { #endif #ifdef __clang__ # pragma clang diagnostic pop -#elif defined __GNUC__ +#elif defined CATCH_COMPILER_GCC # pragma GCC diagnostic pop #endif diff --git a/src/catch2/internal/catch_fatal_condition_handler.cpp b/src/catch2/internal/catch_fatal_condition_handler.cpp index 410b9b8f..754d643b 100644 --- a/src/catch2/internal/catch_fatal_condition_handler.cpp +++ b/src/catch2/internal/catch_fatal_condition_handler.cpp @@ -26,6 +26,7 @@ #include +#include #include #include #include @@ -160,7 +161,7 @@ namespace Catch { // Older GCCs trigger -Wmissing-field-initializers for T foo = {} // which is zero initialization, but not explicit. We want to avoid // that. -#if defined(__GNUC__) +#if defined(CATCH_COMPILER_GCC) # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wmissing-field-initializers" #endif @@ -228,7 +229,7 @@ namespace Catch { } } -#if defined(__GNUC__) +#if defined(CATCH_COMPILER_GCC) # pragma GCC diagnostic pop #endif diff --git a/src/catch2/internal/catch_preprocessor.hpp b/src/catch2/internal/catch_preprocessor.hpp index 00859b15..80023a18 100644 --- a/src/catch2/internal/catch_preprocessor.hpp +++ b/src/catch2/internal/catch_preprocessor.hpp @@ -8,8 +8,9 @@ #ifndef CATCH_PREPROCESSOR_HPP_INCLUDED #define CATCH_PREPROCESSOR_HPP_INCLUDED +#include -#if defined(__GNUC__) +#if defined(CATCH_COMPILER_GCC) // We need to silence "empty __VA_ARGS__ warning", and using just _Pragma does not work #pragma GCC system_header #endif diff --git a/src/catch2/internal/catch_source_line_info.cpp b/src/catch2/internal/catch_source_line_info.cpp index 9a4fe74e..1f8c5966 100644 --- a/src/catch2/internal/catch_source_line_info.cpp +++ b/src/catch2/internal/catch_source_line_info.cpp @@ -22,7 +22,7 @@ namespace Catch { } std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { -#ifndef __GNUG__ +#if !defined(CATCH_COMPILER_GCC) || !defined(__cplusplus) os << info.file << '(' << info.line << ')'; #else os << info.file << ':' << info.line; diff --git a/src/catch2/internal/catch_stream.hpp b/src/catch2/internal/catch_stream.hpp index eab7161c..a3397a86 100644 --- a/src/catch2/internal/catch_stream.hpp +++ b/src/catch2/internal/catch_stream.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_STREAM_HPP_INCLUDED #define CATCH_STREAM_HPP_INCLUDED +#include #include #include @@ -65,7 +66,7 @@ namespace Catch { //! Sets internal state to `str` void str(std::string const& str); -#if defined(__GNUC__) && !defined(__clang__) +#if defined(CATCH_COMPILER_GCC) #pragma GCC diagnostic push // Old versions of GCC do not understand -Wnonnull-compare #pragma GCC diagnostic ignored "-Wpragmas" @@ -83,7 +84,7 @@ namespace Catch { return *this; } -#if defined(__GNUC__) && !defined(__clang__) +#if defined(CATCH_COMPILER_GCC) #pragma GCC diagnostic pop #endif auto get() -> std::ostream& { return *m_oss; } diff --git a/src/catch2/internal/catch_template_test_registry.hpp b/src/catch2/internal/catch_template_test_registry.hpp index bfac3bc8..e45ad952 100644 --- a/src/catch2/internal/catch_template_test_registry.hpp +++ b/src/catch2/internal/catch_template_test_registry.hpp @@ -18,7 +18,7 @@ // GCC 5 and older do not properly handle disabling unused-variable warning // with a _Pragma. This means that we have to leak the suppression to the // user code as well :-( -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 +#if defined(CATCH_COMPILER_GCC) && __GNUC__ <= 5 #pragma GCC diagnostic ignored "-Wunused-variable" #endif diff --git a/src/catch2/internal/catch_test_macro_impl.hpp b/src/catch2/internal/catch_test_macro_impl.hpp index 71812040..55a6534b 100644 --- a/src/catch2/internal/catch_test_macro_impl.hpp +++ b/src/catch2/internal/catch_test_macro_impl.hpp @@ -10,13 +10,14 @@ #include #include +#include #include #include #include // We need this suppression to leak, because it took until GCC 9 // for the front end to handle local suppression via _Pragma properly -#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) && __GNUC__ < 9 +#if defined(CATCH_COMPILER_GCC) && __GNUC__ < 9 #pragma GCC diagnostic ignored "-Wparentheses" #endif diff --git a/src/catch2/internal/catch_test_registry.hpp b/src/catch2/internal/catch_test_registry.hpp index 9a03e6db..1b0d099f 100644 --- a/src/catch2/internal/catch_test_registry.hpp +++ b/src/catch2/internal/catch_test_registry.hpp @@ -8,6 +8,7 @@ #ifndef CATCH_TEST_REGISTRY_HPP_INCLUDED #define CATCH_TEST_REGISTRY_HPP_INCLUDED +#include #include #include #include @@ -18,7 +19,7 @@ // GCC 5 and older do not properly handle disabling unused-variable warning // with a _Pragma. This means that we have to leak the suppression to the // user code as well :-( -#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 5 +#if defined(CATCH_COMPILER_GCC) && __GNUC__ <= 5 #pragma GCC diagnostic ignored "-Wunused-variable" #endif diff --git a/tests/SelfTest/UsageTests/Compilation.tests.cpp b/tests/SelfTest/UsageTests/Compilation.tests.cpp index d45f8e6c..b05e6ce0 100644 --- a/tests/SelfTest/UsageTests/Compilation.tests.cpp +++ b/tests/SelfTest/UsageTests/Compilation.tests.cpp @@ -12,6 +12,8 @@ // in a different namespace. #include +#include + namespace foo { struct helper_1403 { bool operator==(helper_1403) const { return true; } @@ -23,7 +25,7 @@ namespace bar { struct TypeList {}; } -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic ignored "-Wmissing-declarations" #endif std::ostream& operator<<(std::ostream& out, foo::helper_1403 const&) { @@ -79,7 +81,7 @@ struct B : private A { #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-function" #endif -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC // Note that because -~GCC~-, this warning cannot be silenced temporarily, by pushing diagnostic stack... // Luckily it is firing in test files and thus can be silenced for the whole file, without losing much. #pragma GCC diagnostic ignored "-Wunused-function" diff --git a/tests/SelfTest/UsageTests/Condition.tests.cpp b/tests/SelfTest/UsageTests/Condition.tests.cpp index 198b4cdb..59709caa 100644 --- a/tests/SelfTest/UsageTests/Condition.tests.cpp +++ b/tests/SelfTest/UsageTests/Condition.tests.cpp @@ -223,7 +223,7 @@ TEST_CASE( "Comparisons with int literals don't warn when mixing signed/ unsigne // Disable warnings about sign conversions for the next two tests // (as we are deliberately invoking them) // - Currently only disabled for GCC/ LLVM. Should add VC++ too -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wsign-conversion" @@ -277,7 +277,7 @@ TEST_CASE( "Comparisons between ints where one side is computed" ) CHECK( 54 == 6*9 ); } -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic pop #endif diff --git a/tests/SelfTest/UsageTests/Message.tests.cpp b/tests/SelfTest/UsageTests/Message.tests.cpp index 2ec71b49..23a8f5ea 100644 --- a/tests/SelfTest/UsageTests/Message.tests.cpp +++ b/tests/SelfTest/UsageTests/Message.tests.cpp @@ -216,7 +216,7 @@ TEST_CASE( "CAPTURE can deal with complex expressions", "[messages][capture]" ) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wunused-value" // In (1, 2), the "1" is unused ... #endif -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-value" // All the comma operators are side-effect free #endif @@ -243,7 +243,7 @@ std::ostream& operator<<(std::ostream& out, helper_1436 const& helper) { // Clang and gcc have different names for this warning, and clang also // warns about an unused value. This warning must be disabled for C++20. -#if defined(__GNUG__) && !defined(__clang__) +#if defined(CATCH_COMPILER_GCC) && __cplusplus #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpragmas" #pragma GCC diagnostic ignored "-Wcomma-subscript" @@ -265,7 +265,7 @@ TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messag SUCCEED(); } -#ifdef __GNUG__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic pop #endif @@ -279,7 +279,7 @@ TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]" #ifdef __clang__ #pragma clang diagnostic pop #endif -#ifdef __GNUC__ +#ifdef CATCH_COMPILER_GCC #pragma GCC diagnostic pop #endif #ifdef _MSC_VER diff --git a/tests/SelfTest/UsageTests/ToStringWhich.tests.cpp b/tests/SelfTest/UsageTests/ToStringWhich.tests.cpp index 7069734f..4f786338 100644 --- a/tests/SelfTest/UsageTests/ToStringWhich.tests.cpp +++ b/tests/SelfTest/UsageTests/ToStringWhich.tests.cpp @@ -8,9 +8,9 @@ #include +#include - -#if defined(__GNUC__) +#if defined(CATCH_COMPILER_GCC) // This has to be left enabled until end of the TU, because the GCC // frontend reports operator<<(std::ostream& os, const has_maker_and_operator&) // as unused anyway