From f671f1a3e55e2ca26e77a625560e681f9a43b528 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 13 Oct 2025 09:13:19 -0700 Subject: [PATCH] [ADT] Simplify ResolveUnderlyingType (NFC) We have three implementations of ResolveUnderlyingType: - enum - bool - neither This patch combines the latter two with std::conditional_t. Without this patch, we use "void" to trigger a compilation failure downstream when sizeof(bool) != 1, which is not very friendly. This patch instead uses static_assert to catch the case where the user chooses to use bool but sizeof(bool) != 1. --- llvm/include/llvm/ADT/Bitfields.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/ADT/Bitfields.h b/llvm/include/llvm/ADT/Bitfields.h index 1af276145ba48..1fbc41c472581 100644 --- a/llvm/include/llvm/ADT/Bitfields.h +++ b/llvm/include/llvm/ADT/Bitfields.h @@ -154,12 +154,9 @@ struct ResolveUnderlyingType { using type = std::underlying_type_t; }; template struct ResolveUnderlyingType { - using type = T; -}; -template <> struct ResolveUnderlyingType { - /// In case sizeof(bool) != 1, replace `void` by an additionnal - /// std::conditional. - using type = std::conditional_t; + static_assert(!std::is_same_v || sizeof(bool) == 1, + "T being bool requires sizeof(bool) == 1."); + using type = std::conditional_t, uint8_t, T>; }; } // namespace bitfields_details