]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Add MSVC support for Z_UNREACHABLE macro
authorMathias Berchtold <mberchtold@gmail.com>
Sat, 21 Feb 2026 22:01:11 +0000 (15:01 -0700)
committerHans Kristian Rosbach <hk-github@circlestorm.org>
Fri, 6 Mar 2026 13:50:13 +0000 (14:50 +0100)
Add Z_UNREACHABLE fallback for MSVC, as the C23 unreachable macro is not yet defined in the Windows SDK's <stddef.h>.

zbuild.h

index 39903d21761edb4f0bd37b404733e36d3c282777..c6a54e0f1e32bb8d1657c2a954e116055c08e8db 100644 (file)
--- a/zbuild.h
+++ b/zbuild.h
 /* Hint to compiler that a block of code is unreachable, typically in a switch default condition */
 #ifndef Z_UNREACHABLE
 #  if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
-#    define Z_UNREACHABLE() unreachable()           // C23 approach
+#    if !defined(unreachable) && defined(_MSC_VER)
+#      define Z_UNREACHABLE() __assume(0)
+#    else
+#      define Z_UNREACHABLE() unreachable()           // C23 approach
+#    endif
 #  elif (defined(__GNUC__) && (__GNUC__ >= 5)) || defined(__clang__)
 #    define Z_UNREACHABLE() __builtin_unreachable()
 #  else