Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

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>(E)

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)
@llvmbot
Copy link
Member

llvmbot commented Oct 12, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

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)


Full diff: https://github.com/llvm/llvm-project/pull/163038.diff

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/Sequence.h (+2-2)
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

@kazutakahirata kazutakahirata merged commit 6333e05 into llvm:main Oct 12, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251011_ADT_Sequence branch October 12, 2025 15:51
DharuniRAcharya pushed a commit to DharuniRAcharya/llvm-project that referenced this pull request Oct 13, 2025
…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)
akadutta pushed a commit to akadutta/llvm-project that referenced this pull request Oct 14, 2025
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants