Jul 18, 2022

[C++23] std::unreachable

Reference:
(msvc) __assume
(gcc/clang) __builtin_unreachable()
(c++23) std::unreachable

folly code:
https://github.com/facebook/folly/blob/0713d3b213a2a2560065d479030da5769ea5f406/folly/lang/Hint-inl.h#L37


[[noreturn]] inline void unreachable()
{
    // Uses compiler specific extensions if possible.
    // Even if no extension is used, undefined behavior is still raised by
    // an empty function body and the noreturn attribute.
#ifdef __GNUC__ // GCC, Clang, ICC
    __builtin_unreachable();
#elifdef _MSC_VER // MSVC
    __assume(false);
#endif
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.