include/o3tl/unreachable.hxx |   19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

New commits:
commit 87369ad7b82da6904e889614c88617e610d4506b
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Mon Feb 28 08:03:06 2022 +0100
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Mon Feb 28 09:38:07 2022 +0100

    Use std::unreachable if available
    
    Change-Id: I686e36cf3e77a94293ef6923ba00181eb3e02c81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130661
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

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: */

Reply via email to