[llvm] cf8943a - [Support] Use llvm::to_underlying in ScopedPrinter.h (NFC) (#163088)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 12 20:49:37 PDT 2025
Author: Kazu Hirata
Date: 2025-10-12T20:49:33-07:00
New Revision: cf8943a0dc3c68bd1726540dd9d2bedd79c6e264
URL: https://github.com/llvm/llvm-project/commit/cf8943a0dc3c68bd1726540dd9d2bedd79c6e264
DIFF: https://github.com/llvm/llvm-project/commit/cf8943a0dc3c68bd1726540dd9d2bedd79c6e264.diff
LOG: [Support] Use llvm::to_underlying in ScopedPrinter.h (NFC) (#163088)
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/Support/ScopedPrinter.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/Support/ScopedPrinter.h b/llvm/include/llvm/Support/ScopedPrinter.h
index 94080e85a9048..7b87fdafd68ac 100644
--- a/llvm/include/llvm/Support/ScopedPrinter.h
+++ b/llvm/include/llvm/Support/ScopedPrinter.h
@@ -11,6 +11,7 @@
#include "llvm/ADT/APSInt.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
@@ -57,8 +58,7 @@ struct HexNumber {
HexNumber(unsigned long Value) : Value(Value) {}
HexNumber(unsigned long long Value) : Value(Value) {}
template <typename EnumT, typename = std::enable_if_t<std::is_enum_v<EnumT>>>
- HexNumber(EnumT Value)
- : HexNumber(static_cast<std::underlying_type_t<EnumT>>(Value)) {}
+ HexNumber(EnumT Value) : HexNumber(llvm::to_underlying(Value)) {}
uint64_t Value;
};
@@ -84,7 +84,7 @@ struct FlagEntry {
: Name(Name), Value(Value) {}
template <typename EnumT, typename = std::enable_if_t<std::is_enum_v<EnumT>>>
FlagEntry(StringRef Name, EnumT Value)
- : FlagEntry(Name, static_cast<std::underlying_type_t<EnumT>>(Value)) {}
+ : FlagEntry(Name, llvm::to_underlying(Value)) {}
StringRef Name;
uint64_t Value;
More information about the llvm-commits
mailing list