[llvm] 5a20b72 - [ADT] Simplify ResolveUnderlyingType (NFC) (#164114)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 18 17:50:46 PDT 2025


Author: Kazu Hirata
Date: 2025-10-18T17:50:42-07:00
New Revision: 5a20b72fce52244e7c2de1c69c6cea36e00d8bb5

URL: https://github.com/llvm/llvm-project/commit/5a20b72fce52244e7c2de1c69c6cea36e00d8bb5
DIFF: https://github.com/llvm/llvm-project/commit/5a20b72fce52244e7c2de1c69c6cea36e00d8bb5.diff

LOG: [ADT] Simplify ResolveUnderlyingType (NFC) (#164114)

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.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/Bitfields.h

Removed: 
    


################################################################################
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<T>;
 };
 template <typename T> struct ResolveUnderlyingType<T, false> {
-  using type = T;
-};
-template <> struct ResolveUnderlyingType<bool, false> {
-  /// In case sizeof(bool) != 1, replace `void` by an additionnal
-  /// std::conditional.
-  using type = std::conditional_t<sizeof(bool) == 1, uint8_t, void>;
+  static_assert(!std::is_same_v<T, bool> || sizeof(bool) == 1,
+                "T being bool requires sizeof(bool) == 1.");
+  using type = std::conditional_t<std::is_same_v<T, bool>, uint8_t, T>;
 };
 
 } // namespace bitfields_details


        


More information about the llvm-commits mailing list