From 6b1182df898b01aab333c24db2fb8f6c748f11b8 Mon Sep 17 00:00:00 2001 From: scuzqy Date: Fri, 21 Jun 2024 15:10:25 +0800 Subject: [PATCH] [struct_pack] update rule for enabling [[likely]] MSVC intentionally defined __cplusplus to 199711L, ignoring the actual standard, hence MACRO definitions of `SP_LIKELY` and `SP_UNLIKELY` go to wrong branches in MSVC build. --- include/ylt/struct_pack/marco.h | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/include/ylt/struct_pack/marco.h b/include/ylt/struct_pack/marco.h index 546ac6e9e..86d610b68 100644 --- a/include/ylt/struct_pack/marco.h +++ b/include/ylt/struct_pack/marco.h @@ -31,19 +31,14 @@ #define STRUCT_PACK_MAY_INLINE inline #endif -#if __has_cpp_attribute(likely) && __cplusplus >= 202002L +#if __has_cpp_attribute(likely) && __has_cpp_attribute(unlikely) #define SP_LIKELY(expr) (expr) [[likely]] -#elif __GNUC__ -#define SP_LIKELY(expr) (__builtin_expect(!!(expr), 1)) -#else -#define SP_LIKELY(expr) (expr) -#endif - -#if __has_cpp_attribute(unlikely) && __cplusplus >= 202002L #define SP_UNLIKELY(expr) (expr) [[unlikely]] #elif __GNUC__ +#define SP_LIKELY(expr) (__builtin_expect(!!(expr), 1)) #define SP_UNLIKELY(expr) (__builtin_expect(!!(expr), 0)) #else +#define SP_LIKELY(expr) (expr) #define SP_UNLIKELY(expr) (expr) #endif