From 0af27ac017d19f8c20e05522d1337ac0e2c2880d Mon Sep 17 00:00:00 2001 From: Corentin Schreiber Date: Thu, 2 Feb 2023 16:29:44 +0000 Subject: [PATCH] Fix CI with MSVC and fix #70 --- include/snitch/snitch.hpp | 16 ++++++++++++++++ tests/runtime_tests/macros.cpp | 2 +- tests/testing.hpp | 4 ---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/include/snitch/snitch.hpp b/include/snitch/snitch.hpp index 510cc1af..9b26c0bc 100644 --- a/include/snitch/snitch.hpp +++ b/include/snitch/snitch.hpp @@ -1373,21 +1373,25 @@ bool operator==(const M& m, const T& value) noexcept { # define SNITCH_WARNING_POP _Pragma("clang diagnostic pop") # define SNITCH_WARNING_DISABLE_PARENTHESES _Pragma("clang diagnostic ignored \"-Wparentheses\"") # define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON +# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("clang diagnostic ignored \"-Wunreachable-code\"") #elif defined(__GNUC__) # define SNITCH_WARNING_PUSH _Pragma("GCC diagnostic push") # define SNITCH_WARNING_POP _Pragma("GCC diagnostic pop") # define SNITCH_WARNING_DISABLE_PARENTHESES _Pragma("GCC diagnostic ignored \"-Wparentheses\"") # define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON +# define SNITCH_WARNING_DISABLE_UNREACHABLE #elif defined(_MSC_VER) # define SNITCH_WARNING_PUSH _Pragma("warning(push)") # define SNITCH_WARNING_POP _Pragma("warning(pop)") # define SNITCH_WARNING_DISABLE_PARENTHESES # define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON _Pragma("warning(disable: 4127)") +# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("warning(disable: 4702)") #else # define SNITCH_WARNING_PUSH # define SNITCH_WARNING_POP # define SNITCH_WARNING_DISABLE_PARENTHESES # define SNITCH_WARNING_DISABLE_CONSTANT_COMPARISON +# define SNITCH_WARNING_DISABLE_UNREACHABLE #endif // clang-format on @@ -1692,6 +1696,8 @@ bool operator==(const M& m, const T& value) noexcept { # define SNITCH_REQUIRE_THROWS_AS(EXPRESSION, ...) \ do { \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_UNREACHABLE \ auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \ try { \ ++SNITCH_CURRENT_TEST.asserts; \ @@ -1717,10 +1723,13 @@ bool operator==(const M& m, const T& value) noexcept { } \ SNITCH_TESTING_ABORT; \ } \ + SNITCH_WARNING_POP \ } while (0) # define SNITCH_CHECK_THROWS_AS(EXPRESSION, ...) \ do { \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_UNREACHABLE \ auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \ try { \ ++SNITCH_CURRENT_TEST.asserts; \ @@ -1744,10 +1753,13 @@ bool operator==(const M& m, const T& value) noexcept { #__VA_ARGS__ " expected but other unknown exception thrown"); \ } \ } \ + SNITCH_WARNING_POP \ } while (0) # define SNITCH_REQUIRE_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ do { \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_UNREACHABLE \ auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \ try { \ ++SNITCH_CURRENT_TEST.asserts; \ @@ -1781,10 +1793,13 @@ bool operator==(const M& m, const T& value) noexcept { } \ SNITCH_TESTING_ABORT; \ } \ + SNITCH_WARNING_POP \ } while (0) # define SNITCH_CHECK_THROWS_MATCHES(EXPRESSION, EXCEPTION, ...) \ do { \ + SNITCH_WARNING_PUSH \ + SNITCH_WARNING_DISABLE_UNREACHABLE \ auto& SNITCH_CURRENT_TEST = snitch::impl::get_current_test(); \ try { \ ++SNITCH_CURRENT_TEST.asserts; \ @@ -1815,6 +1830,7 @@ bool operator==(const M& m, const T& value) noexcept { #EXCEPTION " expected but other unknown exception thrown"); \ } \ } \ + SNITCH_WARNING_POP \ } while (0) // clang-format off diff --git a/tests/runtime_tests/macros.cpp b/tests/runtime_tests/macros.cpp index 56c98e30..76434a13 100644 --- a/tests/runtime_tests/macros.cpp +++ b/tests/runtime_tests/macros.cpp @@ -70,7 +70,7 @@ struct test_exception : std::exception { template int foo() { - if (i != j || i != k) { + if constexpr (i != j || i != k) { return 0; } else { #if SNITCH_WITH_EXCEPTIONS diff --git a/tests/testing.hpp b/tests/testing.hpp index cafbb113..8e6c9d01 100644 --- a/tests/testing.hpp +++ b/tests/testing.hpp @@ -41,23 +41,19 @@ struct filldata { #endif #if defined(__clang__) -# define SNITCH_WARNING_DISABLE_UNREACHABLE # define SNITCH_WARNING_DISABLE_INT_BOOLEAN # define SNITCH_WARNING_DISABLE_PRECEDENCE # define SNITCH_WARNING_DISABLE_ASSIGNMENT #elif defined(__GNUC__) -# define SNITCH_WARNING_DISABLE_UNREACHABLE # define SNITCH_WARNING_DISABLE_INT_BOOLEAN \ _Pragma("GCC diagnostic ignored \"-Wint-in-bool-context\"") # define SNITCH_WARNING_DISABLE_PRECEDENCE # define SNITCH_WARNING_DISABLE_ASSIGNMENT #elif defined(_MSC_VER) -# define SNITCH_WARNING_DISABLE_UNREACHABLE _Pragma("warning(disable: 4702)") # define SNITCH_WARNING_DISABLE_INT_BOOLEAN # define SNITCH_WARNING_DISABLE_PRECEDENCE _Pragma("warning(disable: 4554)") # define SNITCH_WARNING_DISABLE_ASSIGNMENT _Pragma("warning(disable: 4706)") #else -# define SNITCH_WARNING_DISABLE_UNREACHABLE # define SNITCH_WARNING_DISABLE_INT_BOOLEAN # define SNITCH_WARNING_DISABLE_PRECEDENCE # define SNITCH_WARNING_DISABLE_ASSIGNMENT