From a1c7ee115f17c1e83b382f33ef2614070974626f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 28 Jul 2025 11:03:40 +0200 Subject: [PATCH] Don't follow __assume(false) with std::terminate in NDEBUG builds Having `std::terminate` as the backstop after `__assume(false)` would trigger W4702 (unreachable code) with MSVC. As we want to keep `__assume(false)` for the optimization hint in NDEBUG builds, we have to avoid mixing in `std::terminate` for those builds. Fixes #3007 --- src/catch2/internal/catch_unreachable.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/catch2/internal/catch_unreachable.hpp b/src/catch2/internal/catch_unreachable.hpp index 02cca494..fc3f75b5 100644 --- a/src/catch2/internal/catch_unreachable.hpp +++ b/src/catch2/internal/catch_unreachable.hpp @@ -39,9 +39,13 @@ namespace Catch { __assume( false ); # elif defined( __GNUC__ ) __builtin_unreachable(); -# endif -# endif // ^^ NDEBUG +# else // vv platform without known optimization hint std::terminate(); +# endif +# else // ^^ NDEBUG + // For non-release builds, we prefer termination on bug over UB + std::terminate(); +# endif // } } // namespace Detail