From 726e3abbf5a27ba37f38404e01b271828e50a5b5 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sat, 11 Oct 2025 20:28:38 -0700 Subject: [PATCH] [ADT] Simplify addEnumValues with llvm::to_underlying (NFC) llvm::to_underlying, forward ported from C++23, conveniently packages static_cast and std::underlying_type_t like so: static_cast>(E) --- llvm/include/llvm/ADT/STLExtras.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h index 5b20d6bd38262..658f26249122a 100644 --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -161,12 +161,10 @@ using TypeAtIndex = std::tuple_element_t>; /// Helper which adds two underlying types of enumeration type. /// Implicit conversion to a common type is accepted. template ::value, - std::underlying_type_t>, - typename UT2 = std::enable_if_t::value, - std::underlying_type_t>> + typename = std::enable_if_t && + std::is_enum_v>> constexpr auto addEnumValues(EnumTy1 LHS, EnumTy2 RHS) { - return static_cast(LHS) + static_cast(RHS); + return llvm::to_underlying(LHS) + llvm::to_underlying(RHS); } //===----------------------------------------------------------------------===//