From 03e2a945e0a30aa477d4c747f594d3cbd86b5fa0 Mon Sep 17 00:00:00 2001 From: Gabriel Agamennoni Date: Wed, 4 Sep 2024 03:19:19 -0700 Subject: [PATCH] Add FOLLY_ASSUME_UNREACHABLE Summary: Add a macro that informs the compiler that a statement is unreachable, and at the same time suppresses `-Wunreachable-code` warnings that Clang throws up when. Reviewed By: ohcnivek Differential Revision: D62024037 fbshipit-source-id: 7c180952e6846a9881940fdb618a5388c467727c --- folly/lang/Assume.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/folly/lang/Assume.h b/folly/lang/Assume.h index 8352881ba8b..8943c648695 100644 --- a/folly/lang/Assume.h +++ b/folly/lang/Assume.h @@ -70,3 +70,13 @@ FOLLY_ALWAYS_INLINE void assume(bool cond) { } } // namespace folly + +/** + * Inform the compiler that the statement is not reachable at runtime, and + * disable compiler warnings. + */ +#define FOLLY_ASSUME_UNREACHABLE() \ + FOLLY_PUSH_WARNING \ + FOLLY_CLANG_DISABLE_WARNING("-Wunreachable-code") \ + ::folly::assume_unreachable(); \ + FOLLY_POP_WARNING