Skip to content

Commit 773caac

Browse files
[ADT] Use llvm::to_underlying (NFC)
1 parent 3c727a9 commit 773caac

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

llvm/include/llvm/ADT/BitmaskEnum.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <type_traits>
1414
#include <utility>
1515

16+
#include "llvm/ADT/STLForwardCompat.h"
1617
#include "llvm/Support/MathExtras.h"
1718

1819
/// LLVM_MARK_AS_BITMASK_ENUM lets you opt in an individual enum type so you can
@@ -125,7 +126,7 @@ template <typename E> constexpr std::underlying_type_t<E> Mask() {
125126
/// Check that Val is in range for E, and return Val cast to E's underlying
126127
/// type.
127128
template <typename E> constexpr std::underlying_type_t<E> Underlying(E Val) {
128-
auto U = static_cast<std::underlying_type_t<E>>(Val);
129+
auto U = llvm::to_underlying(Val);
129130
assert(U >= 0 && "Negative enum values are not allowed.");
130131
assert(U <= Mask<E>() && "Enum value too large (or largest val too small?)");
131132
return U;
@@ -181,9 +182,8 @@ E &operator^=(E &LHS, E RHS) {
181182
// Enable bitmask enums in namespace ::llvm and all nested namespaces.
182183
LLVM_ENABLE_BITMASK_ENUMS_IN_NAMESPACE();
183184
template <typename E, typename = std::enable_if_t<is_bitmask_enum<E>::value>>
184-
constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(uint64_t{
185-
static_cast<std::underlying_type_t<E>>(
186-
E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
185+
constexpr unsigned BitWidth = BitmaskEnumDetail::bitWidth(
186+
uint64_t{llvm::to_underlying(E::LLVM_BITMASK_LARGEST_ENUMERATOR)});
187187

188188
} // namespace llvm
189189

llvm/include/llvm/ADT/FoldingSet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define LLVM_ADT_FOLDINGSET_H
1818

1919
#include "llvm/ADT/Hashing.h"
20+
#include "llvm/ADT/STLForwardCompat.h"
2021
#include "llvm/ADT/SmallVector.h"
2122
#include "llvm/ADT/iterator.h"
2223
#include "llvm/Support/Allocator.h"
@@ -832,7 +833,7 @@ struct FoldingSetTrait<std::pair<T1, T2>> {
832833
template <typename T>
833834
struct FoldingSetTrait<T, std::enable_if_t<std::is_enum<T>::value>> {
834835
static void Profile(const T &X, FoldingSetNodeID &ID) {
835-
ID.AddInteger(static_cast<std::underlying_type_t<T>>(X));
836+
ID.AddInteger(llvm::to_underlying(X));
836837
}
837838
};
838839

0 commit comments

Comments
 (0)