From 063450b8f47e3ca8af87afdc3f3df5ae766e1805 Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Tue, 29 Nov 2022 13:26:32 -0600 Subject: [PATCH] Update likely/unlikely macros to avoid double negation I believe this should be identical to the previous code and handle the same cases (I'm guessing going by the comment that this came from a C codebase without `bool` types). The problem with the previous code is that it tripped up the `clangd` analyzer into thinking `assert()` expressions can/should be simplified via DeMorgan's to improve readability (because it was seeing the fully expanded macro). --- src/common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common.h b/src/common.h index ae0cfe8a9..0ba47f3bc 100644 --- a/src/common.h +++ b/src/common.h @@ -310,8 +310,8 @@ void wcs2string_appending(const wchar_t *in, size_t len, std::string *receiver); bool should_suppress_stderr_for_tests(); /// Branch prediction hints. Idea borrowed from Linux kernel. Just used for asserts. -#define likely(x) __builtin_expect(!!(x), 1) -#define unlikely(x) __builtin_expect(!!(x), 0) +#define likely(x) __builtin_expect(bool(x), 1) +#define unlikely(x) __builtin_expect(bool(x), 0) void assert_is_main_thread(const char *who); #define ASSERT_IS_MAIN_THREAD_TRAMPOLINE(x) assert_is_main_thread(x)