[libcxx-commits] [libcxx] [libcxx] Recalculate union-member sizes in basic_string (PR #168742)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Nov 19 09:33:29 PST 2025


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 origin/main HEAD --extensions ,cpp -- libcxx/test/std/strings/basic.string/awkward-char-types.pass.cpp libcxx/include/string libcxx/test/std/strings/basic.string/string.modifiers/string_append/push_back.pass.cpp --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

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

``````````diff
diff --git a/libcxx/include/string b/libcxx/include/string
index 81292f712..9eb04e233 100644
--- a/libcxx/include/string
+++ b/libcxx/include/string
@@ -721,7 +721,7 @@ struct __padding {
   char __padding_[_PaddingSize];
   constexpr void clear() {
     __padding __initialized = {0};
-    *this = __initialized;
+    *this                   = __initialized;
   }
 };
 
@@ -845,9 +845,12 @@ private:
   // up to the nearest multiple of the alignment. That's the total size of the
   // structure.
   static constexpr size_t __short_packed_size = sizeof(value_type) * __min_cap + 1;
-  union __union_alignment_check { __long_min __long_; value_type v; };
+  union __union_alignment_check {
+    __long_min __long_;
+    value_type v;
+  };
   static constexpr size_t __union_alignment = _LIBCPP_ALIGNOF(__union_alignment_check);
-  static constexpr size_t __full_size = (__short_packed_size + __union_alignment - 1) & -__union_alignment;
+  static constexpr size_t __full_size       = (__short_packed_size + __union_alignment - 1) & -__union_alignment;
 
   // Now define both structures for real, with padding to ensure they are both
   // exactly the calculated size.
diff --git a/libcxx/test/std/strings/basic.string/awkward-char-types.pass.cpp b/libcxx/test/std/strings/basic.string/awkward-char-types.pass.cpp
index a4e258680..a649cd8f5 100644
--- a/libcxx/test/std/strings/basic.string/awkward-char-types.pass.cpp
+++ b/libcxx/test/std/strings/basic.string/awkward-char-types.pass.cpp
@@ -5,7 +5,7 @@
 
 #include "test_macros.h"
 
-template<typename Char>
+template <typename Char>
 void test_string() {
   // Make a test string.
   std::basic_string<Char> s;
@@ -26,7 +26,7 @@ void test_string() {
   }
 }
 
-template<typename Integer, size_t N>
+template <typename Integer, size_t N>
 struct TestChar {
   Integer values[N];
 
@@ -37,15 +37,11 @@ struct TestChar {
     return ch;
   }
 
-  bool operator==(const TestChar &other) const {
-    return 0 == memcmp(values, other.values, sizeof(values));
-  }
-  bool operator<(const TestChar &other) const {
-    return 0 < memcmp(values, other.values, sizeof(values));
-  }
+  bool operator==(const TestChar& other) const { return 0 == memcmp(values, other.values, sizeof(values)); }
+  bool operator<(const TestChar& other) const { return 0 < memcmp(values, other.values, sizeof(values)); }
 };
 
-template<typename Integer, size_t N>
+template <typename Integer, size_t N>
 struct std::char_traits<TestChar<Integer, N>> {
   using char_type  = TestChar<Integer, N>;
   using int_type   = int;

``````````

</details>


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


More information about the libcxx-commits mailing list