summaryrefslogtreecommitdiff
path: root/include/o3tl
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-02-28 08:03:06 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-02-28 09:38:07 +0100
commit87369ad7b82da6904e889614c88617e610d4506b (patch)
tree52001ace9d0b2fa2d43e76a579f980bff10e9d95 /include/o3tl
parent5c6d142f7f1ebffcd5b2b220d0e672401a4178c7 (diff)
Use std::unreachable if available
Change-Id: I686e36cf3e77a94293ef6923ba00181eb3e02c81 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130661 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'include/o3tl')
-rw-r--r--include/o3tl/unreachable.hxx19
1 files changed, 14 insertions, 5 deletions
diff --git a/include/o3tl/unreachable.hxx b/include/o3tl/unreachable.hxx
index bc33d34b534e..d5a2e156b760 100644
--- a/include/o3tl/unreachable.hxx
+++ b/include/o3tl/unreachable.hxx
@@ -13,12 +13,19 @@
#include <sal/config.h>
#include <cassert>
+#include <utility>
-// A better replacement for assert(false) to indicate a place in the code that should not be
-// reachable. This should improve on the sometimes poor false-positive warnings emitted by
-// compilers when they cannot detect that some condition flagged by assert(false) cannot occur,
-// either because assert is reduced to a no-op by NDEBUG or because assert is not marked as noreturn
-// in the MSVC headers. This is inspired by LLVM's LLVM_BUILTIN_UNREACHABLE
+// An approximation of C++23 std::unreachable
+// (<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p0627r6.pdf> "Function to mark
+// unreachable code").
+
+#if defined __cpp_lib_unreachable
+
+#define O3TL_UNREACHABLE ::std::unreachable
+
+#else
+
+// This fallback implementation is inspired by LLVM's LLVM_BUILTIN_UNREACHABLE
// (llvm/include/llvm/Support/Compiler.h).
#if defined _MSC_VER
@@ -36,4 +43,6 @@
#endif
+#endif
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */