[llvm] [STLExtras] Backport std::to_underlying from C++23 (PR #70681)

via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 30 09:32:19 PDT 2023


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff f95b2f1acf1171abb0d00089fd4c9238753847e3 a83117aaf066cb89237d51dec4d9fb23e356fd9c -- llvm/include/llvm/ADT/STLExtras.h llvm/unittests/ADT/STLExtrasTest.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h
index 98342bfc36e9..513837582072 100644
--- a/llvm/include/llvm/ADT/STLExtras.h
+++ b/llvm/include/llvm/ADT/STLExtras.h
@@ -1537,7 +1537,8 @@ constexpr decltype(auto) makeVisitor(CallableTs &&...Callables) {
 
 /// Backport of C++23 std::to_underlying.
 template <typename Enum>
-[[nodiscard]] constexpr typename std::underlying_type_t<Enum> to_underlying(Enum E) {
+[[nodiscard]] constexpr typename std::underlying_type_t<Enum>
+to_underlying(Enum E) {
   return static_cast<typename std::underlying_type_t<Enum>>(E);
 }
 
diff --git a/llvm/unittests/ADT/STLExtrasTest.cpp b/llvm/unittests/ADT/STLExtrasTest.cpp
index 213b3e4b3d06..7bf7a7d22670 100644
--- a/llvm/unittests/ADT/STLExtrasTest.cpp
+++ b/llvm/unittests/ADT/STLExtrasTest.cpp
@@ -1333,22 +1333,16 @@ static_assert(is_incomplete_v<Foo>, "Foo is incomplete");
 static_assert(!is_incomplete_v<Bar>, "Bar is defined");
 
 TEST(STLExtrasTest, ToUnderlying) {
-  enum E {
-    A1 = 0, B1 = -1
-  };
+  enum E { A1 = 0, B1 = -1 };
   static_assert(to_underlying(A1) == 0);
   static_assert(to_underlying(B1) == -1);
 
-  enum E2 : unsigned char {
-    A2 = 0, B2
-  };
+  enum E2 : unsigned char { A2 = 0, B2 };
   static_assert(std::is_same_v<unsigned char, decltype(to_underlying(A2))>);
   static_assert(to_underlying(A2) == 0);
   static_assert(to_underlying(B2) == 1);
 
-  enum class E3 {
-    A3 = -1, B3
-  };
+  enum class E3 { A3 = -1, B3 };
   static_assert(std::is_same_v<int, decltype(to_underlying(E3::A3))>);
   static_assert(to_underlying(E3::A3) == -1);
   static_assert(to_underlying(E3::B3) == 0);

``````````

</details>


https://github.com/llvm/llvm-project/pull/70681


More information about the llvm-commits mailing list