[llvm] [ADT] Backport std::to_underlying from C++23 (PR #70681)
Vlad Serebrennikov via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 11:34:31 PDT 2023
================
@@ -119,4 +119,20 @@ TEST(TransformTest, MoveTransformLlvm) {
EXPECT_EQ(0u, MoveOnly::Destructions);
}
+TEST(TransformTest, ToUnderlying) {
+ enum E { A1 = 0, B1 = -1 };
+ static_assert(llvm::to_underlying(A1) == 0);
+ static_assert(llvm::to_underlying(B1) == -1);
+
+ enum E2 : unsigned char { A2 = 0, B2 };
+ static_assert(std::is_same_v<unsigned char, decltype(llvm::to_underlying(A2))>);
+ static_assert(llvm::to_underlying(A2) == 0);
+ static_assert(llvm::to_underlying(B2) == 1);
+
+ enum class E3 { A3 = -1, B3 };
+ static_assert(std::is_same_v<int, decltype(llvm::to_underlying(E3::A3))>);
----------------
Endilll wrote:
Clause 5 above states that *For a scoped enumeration type, the underlying type is int if it is not explicitly specified.*
https://github.com/llvm/llvm-project/pull/70681
More information about the llvm-commits
mailing list