Skip to content

Commit a1c7ee1

Browse files
committed
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
1 parent d547cae commit a1c7ee1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/catch2/internal/catch_unreachable.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ namespace Catch {
3939
__assume( false );
4040
# elif defined( __GNUC__ )
4141
__builtin_unreachable();
42+
# else // vv platform without known optimization hint
43+
std::terminate();
4244
# endif
43-
# endif // ^^ NDEBUG
45+
# else // ^^ NDEBUG
46+
// For non-release builds, we prefer termination on bug over UB
4447
std::terminate();
48+
# endif //
4549
}
4650

4751
} // namespace Detail

0 commit comments

Comments
 (0)