[llvm] 6333e05 - [ADT] Simplify CheckedInt::from with llvm::to_underlying (NFC) (#163038)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 12 08:50:36 PDT 2025
Author: Kazu Hirata
Date: 2025-10-12T08:50:32-07:00
New Revision: 6333e05751a3b278347166f0ff8d720217881cde
URL: https://github.com/llvm/llvm-project/commit/6333e05751a3b278347166f0ff8d720217881cde
DIFF: https://github.com/llvm/llvm-project/commit/6333e05751a3b278347166f0ff8d720217881cde.diff
LOG: [ADT] Simplify CheckedInt::from with llvm::to_underlying (NFC) (#163038)
llvm::to_underlying, forward ported from C++23, conveniently packages
static_cast and std::underlying_type_t like so:
static_cast<std::underlying_type_t<EnumTy>>(E)
Added:
Modified:
llvm/include/llvm/ADT/Sequence.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/Sequence.h b/llvm/include/llvm/ADT/Sequence.h
index ce969ef280b39..ae446df345ee0 100644
--- a/llvm/include/llvm/ADT/Sequence.h
+++ b/llvm/include/llvm/ADT/Sequence.h
@@ -86,6 +86,7 @@
#include <type_traits> // std::is_integral, std::is_enum, std::underlying_type,
// std::enable_if
+#include "llvm/ADT/STLForwardCompat.h" // llvm::to_underlying
#include "llvm/Support/MathExtras.h" // AddOverflow / SubOverflow
namespace llvm {
@@ -139,8 +140,7 @@ struct CheckedInt {
template <typename Enum,
std::enable_if_t<std::is_enum<Enum>::value, bool> = 0>
static CheckedInt from(Enum FromValue) {
- using type = std::underlying_type_t<Enum>;
- return from<type>(static_cast<type>(FromValue));
+ return from(llvm::to_underlying(FromValue));
}
// Equality
More information about the llvm-commits
mailing list