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-support

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/163087.diff

1 Files Affected:

  • (modified) llvm/include/llvm/Support/BinaryStreamWriter.h (+2-2)
diff --git a/llvm/include/llvm/Support/BinaryStreamWriter.h b/llvm/include/llvm/Support/BinaryStreamWriter.h
index dddf53bd5483c..39ce0b6e4c110 100644
--- a/llvm/include/llvm/Support/BinaryStreamWriter.h
+++ b/llvm/include/llvm/Support/BinaryStreamWriter.h
@@ -10,6 +10,7 @@
 #define LLVM_SUPPORT_BINARYSTREAMWRITER_H
 
 #include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLForwardCompat.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/BinaryStreamArray.h"
 #include "llvm/Support/BinaryStreamError.h"
@@ -69,8 +70,7 @@ class BinaryStreamWriter {
     static_assert(std::is_enum<T>::value,
                   "Cannot call writeEnum with non-Enum type");
 
-    using U = std::underlying_type_t<T>;
-    return writeInteger<U>(static_cast<U>(Num));
+    return writeInteger(llvm::to_underlying(Num));
   }
 
   /// Write the unsigned integer Value to the underlying stream using ULEB128

@kazutakahirata kazutakahirata merged commit 59ac5b7 into llvm:main Oct 13, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251012_Support_BinaryStreamWriter branch October 13, 2025 03:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants