mirror of
https://github.com/mutouyun/cpp-ipc.git
synced 2025-12-07 01:06:45 +08:00
add: [imp] LIBIMP_ASSUME
This commit is contained in:
parent
f8fdfb0f57
commit
ee04080e29
@ -44,6 +44,9 @@
|
|||||||
# define LIBIMP_CC_MSVC_2019 1920
|
# define LIBIMP_CC_MSVC_2019 1920
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
# define LIBIMP_CC_GNUC __GNUC__
|
# define LIBIMP_CC_GNUC __GNUC__
|
||||||
|
# if defined(__clang__)
|
||||||
|
# define LIBIMP_CC_CLANG
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
# error "This compiler is unsupported."
|
# error "This compiler is unsupported."
|
||||||
#endif
|
#endif
|
||||||
@ -103,6 +106,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// \brief C++ attributes.
|
/// \brief C++ attributes.
|
||||||
|
/// \see https://en.cppreference.com/w/cpp/language/attributes
|
||||||
|
|
||||||
#if defined(__has_cpp_attribute)
|
#if defined(__has_cpp_attribute)
|
||||||
# if __has_cpp_attribute(fallthrough)
|
# if __has_cpp_attribute(fallthrough)
|
||||||
@ -120,6 +124,9 @@
|
|||||||
# if __has_cpp_attribute(nodiscard)
|
# if __has_cpp_attribute(nodiscard)
|
||||||
# define LIBIMP_NODISCARD [[nodiscard]]
|
# define LIBIMP_NODISCARD [[nodiscard]]
|
||||||
# endif
|
# endif
|
||||||
|
# if __has_cpp_attribute(assume)
|
||||||
|
# define LIBIMP_ASSUME(...) [[assume(__VA_ARGS__)]]
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(LIBIMP_FALLTHROUGH)
|
#if !defined(LIBIMP_FALLTHROUGH)
|
||||||
@ -175,6 +182,21 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(LIBIMP_ASSUME)
|
||||||
|
# if defined(LIBIMP_CC_CLANG) && __has_builtin(__builtin_assume)
|
||||||
|
/// \see https://clang.llvm.org/docs/LanguageExtensions.html#langext-builtin-assume
|
||||||
|
# define LIBIMP_ASSUME(...) __builtin_assume(__VA_ARGS__)
|
||||||
|
# elif defined(LIBIMP_CC_GNUC) && __has_builtin(__builtin_unreachable)
|
||||||
|
/// \see https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html#index-_005f_005fbuiltin_005funreachable
|
||||||
|
# define LIBIMP_ASSUME(...) do { if (!(__VA_ARGS__)) __builtin_unreachable(); } while (false)
|
||||||
|
# elif defined(LIBIMP_CC_MSVC)
|
||||||
|
/// \see https://learn.microsoft.com/en-us/cpp/intrinsics/assume?view=msvc-140
|
||||||
|
# define LIBIMP_ASSUME(...) __assume(__VA_ARGS__)
|
||||||
|
# else
|
||||||
|
# define LIBIMP_ASSUME(...)
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/// \see https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
|
/// \see https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_exceptions.html
|
||||||
/// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
|
/// https://learn.microsoft.com/en-us/cpp/preprocessor/predefined-macros
|
||||||
/// https://stackoverflow.com/questions/6487013/programmatically-determine-whether-exceptions-are-enabled
|
/// https://stackoverflow.com/questions/6487013/programmatically-determine-whether-exceptions-are-enabled
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user