[libcxx-commits] [libcxx] [libc++] Refactor the <charconv> tests (PR #227611)

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Sep 30 02:04:19 PDT 2026


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,h -- libcxx/test/std/utilities/charconv/charconv.from.chars/floating_point.pass.cpp libcxx/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp libcxx/test/std/utilities/charconv/charconv.from.chars/integral.roundtrip.pass.cpp libcxx/test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp libcxx/test/support/charconv_test_helpers.h --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/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp b/libcxx/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
index 1e0aaebb1..0a32dd079 100644
--- a/libcxx/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
+++ b/libcxx/test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
@@ -37,120 +37,115 @@ static_assert(!has_from_chars<char*, char*, bool&, int>);
 
 struct test_basics
 {
-    template <typename T>
-    TEST_CONSTEXPR_CXX23 void operator()()
+  template <typename T>
+  TEST_CONSTEXPR_CXX23 void operator()() {
+    std::from_chars_result r;
+    T x;
+
+    {
+      char s[] = "001x";
+
+      // the expected form of the subject sequence is a sequence of
+      // letters and digits representing an integer with the radix
+      // specified by base (C11 7.22.1.4/3)
+      r = std::from_chars(s, s + sizeof(s), x);
+      assert(r.ec == std::errc{});
+      assert(r.ptr == s + 3);
+      assert(x == 1);
+    }
+
     {
-        std::from_chars_result r;
-        T x;
-
-        {
-            char s[] = "001x";
-
-            // the expected form of the subject sequence is a sequence of
-            // letters and digits representing an integer with the radix
-            // specified by base (C11 7.22.1.4/3)
-            r = std::from_chars(s, s + sizeof(s), x);
-            assert(r.ec == std::errc{});
-            assert(r.ptr == s + 3);
-            assert(x == 1);
-        }
-
-        {
-            // The string has more characters than valid in an 128-bit value.
-            char s[] = "0X7BAtSGHDkEIXZgQRfYChLpOzRnM ";
-
-            // The letters from a (or A) through z (or Z) are ascribed the
-            // values 10 through 35; (C11 7.22.1.4/3)
-            r = std::from_chars(s, s + sizeof(s), x, 36);
-            assert(r.ec == std::errc::result_out_of_range);
-            // The member ptr of the return value points to the first character
-            // not matching the pattern
-            assert(r.ptr == s + sizeof(s) - 2);
-            assert(x == 1);
-
-            // no "0x" or "0X" prefix shall appear if the value of base is 16
-            r = std::from_chars(s, s + sizeof(s), x, 16);
-            assert(r.ec == std::errc{});
-            assert(r.ptr == s + 1);
-            assert(x == 0);
-
-            // only letters and digits whose ascribed values are less than that
-            // of base are permitted. (C11 7.22.1.4/3)
-            r = std::from_chars(s + 2, s + sizeof(s), x, 12);
-            // If the parsed value is not in the range representable by the type
-            // of value,
-            if (!fits_in<T>(1150))
-            {
-                // value is unmodified and
-                assert(x == 0);
-                // the member ec of the return value is equal to
-                // errc::result_out_of_range
-                assert(r.ec == std::errc::result_out_of_range);
-            }
-            else
-            {
-                // Otherwise, value is set to the parsed value,
-                assert(x == 1150);
-                // and the member ec is value-initialized.
-                assert(r.ec == std::errc{});
-            }
-            assert(r.ptr == s + 5);
-        }
+      // The string has more characters than valid in an 128-bit value.
+      char s[] = "0X7BAtSGHDkEIXZgQRfYChLpOzRnM ";
+
+      // The letters from a (or A) through z (or Z) are ascribed the
+      // values 10 through 35; (C11 7.22.1.4/3)
+      r = std::from_chars(s, s + sizeof(s), x, 36);
+      assert(r.ec == std::errc::result_out_of_range);
+      // The member ptr of the return value points to the first character
+      // not matching the pattern
+      assert(r.ptr == s + sizeof(s) - 2);
+      assert(x == 1);
+
+      // no "0x" or "0X" prefix shall appear if the value of base is 16
+      r = std::from_chars(s, s + sizeof(s), x, 16);
+      assert(r.ec == std::errc{});
+      assert(r.ptr == s + 1);
+      assert(x == 0);
+
+      // only letters and digits whose ascribed values are less than that
+      // of base are permitted. (C11 7.22.1.4/3)
+      r = std::from_chars(s + 2, s + sizeof(s), x, 12);
+      // If the parsed value is not in the range representable by the type
+      // of value,
+      if (!fits_in<T>(1150)) {
+        // value is unmodified and
+        assert(x == 0);
+        // the member ec of the return value is equal to
+        // errc::result_out_of_range
+        assert(r.ec == std::errc::result_out_of_range);
+      } else {
+        // Otherwise, value is set to the parsed value,
+        assert(x == 1150);
+        // and the member ec is value-initialized.
+        assert(r.ec == std::errc{});
+      }
+      assert(r.ptr == s + 5);
     }
+  }
 };
 
 struct test_signed
 {
-    template <typename T>
-    TEST_CONSTEXPR_CXX23 void operator()()
+  template <typename T>
+  TEST_CONSTEXPR_CXX23 void operator()() {
+    std::from_chars_result r;
+    T x = 42;
+
+    {
+      // If the pattern allows for an optional sign,
+      // but the string has no digit characters following the sign,
+      char s[] = "- 9+12";
+      r        = std::from_chars(s, s + sizeof(s), x);
+      // value is unmodified,
+      assert(x == 42);
+      // no characters match the pattern.
+      assert(r.ptr == s);
+      assert(r.ec == std::errc::invalid_argument);
+    }
+
+    {
+      char s[] = "9+12";
+      r        = std::from_chars(s, s + sizeof(s), x);
+      assert(r.ec == std::errc{});
+      // The member ptr of the return value points to the first character
+      // not matching the pattern,
+      assert(r.ptr == s + 1);
+      assert(x == 9);
+    }
+
+    {
+      char s[] = "12";
+      r        = std::from_chars(s, s + 2, x);
+      assert(r.ec == std::errc{});
+      // or has the value last if all characters match.
+      assert(r.ptr == s + 2);
+      assert(x == 12);
+    }
+
     {
-        std::from_chars_result r;
-        T x = 42;
-
-        {
-            // If the pattern allows for an optional sign,
-            // but the string has no digit characters following the sign,
-            char s[] = "- 9+12";
-            r = std::from_chars(s, s + sizeof(s), x);
-            // value is unmodified,
-            assert(x == 42);
-            // no characters match the pattern.
-            assert(r.ptr == s);
-            assert(r.ec == std::errc::invalid_argument);
-        }
-
-        {
-            char s[] = "9+12";
-            r = std::from_chars(s, s + sizeof(s), x);
-            assert(r.ec == std::errc{});
-            // The member ptr of the return value points to the first character
-            // not matching the pattern,
-            assert(r.ptr == s + 1);
-            assert(x == 9);
-        }
-
-        {
-            char s[] = "12";
-            r = std::from_chars(s, s + 2, x);
-            assert(r.ec == std::errc{});
-            // or has the value last if all characters match.
-            assert(r.ptr == s + 2);
-            assert(x == 12);
-        }
-
-        {
-            // '-' is the only sign that may appear
-            char s[] = "+30";
-            // If no characters match the pattern,
-            r = std::from_chars(s, s + sizeof(s), x);
-            // value is unmodified,
-            assert(x == 12);
-            // the member ptr of the return value is first and
-            assert(r.ptr == s);
-            // the member ec is equal to errc::invalid_argument.
-            assert(r.ec == std::errc::invalid_argument);
-        }
+      // '-' is the only sign that may appear
+      char s[] = "+30";
+      // If no characters match the pattern,
+      r = std::from_chars(s, s + sizeof(s), x);
+      // value is unmodified,
+      assert(x == 12);
+      // the member ptr of the return value is first and
+      assert(r.ptr == s);
+      // the member ec is equal to errc::invalid_argument.
+      assert(r.ec == std::errc::invalid_argument);
     }
+  }
 };
 
 TEST_CONSTEXPR_CXX23 bool test()
diff --git a/libcxx/test/support/charconv_test_helpers.h b/libcxx/test/support/charconv_test_helpers.h
index 51c579e79..91313e66f 100644
--- a/libcxx/test/support/charconv_test_helpers.h
+++ b/libcxx/test/support/charconv_test_helpers.h
@@ -20,45 +20,33 @@
 #endif
 
 template <typename To, typename From>
-constexpr auto
-is_non_narrowing(From a) -> decltype(To{a}, std::true_type())
-{
-    return {};
+constexpr auto is_non_narrowing(From a) -> decltype(To{a}, std::true_type()) {
+  return {};
 }
 
 template <typename To>
-constexpr auto
-is_non_narrowing(...) -> std::false_type
-{
-    return {};
+constexpr auto is_non_narrowing(...) -> std::false_type {
+  return {};
 }
 
 template <typename X, typename T>
-constexpr bool
-_fits_in(T, std::true_type /* non-narrowing*/, ...)
-{
-    return true;
+constexpr bool _fits_in(T, std::true_type /* non-narrowing*/, ...) {
+  return true;
 }
 
 template <typename X, typename T, typename xl = std::numeric_limits<X>>
-constexpr bool
-_fits_in(T v, std::false_type, std::true_type /* T signed*/, std::true_type /* X signed */)
-{
-    return xl::lowest() <= v && v <= (xl::max)();
+constexpr bool _fits_in(T v, std::false_type, std::true_type /* T signed*/, std::true_type /* X signed */) {
+  return xl::lowest() <= v && v <= (xl::max)();
 }
 
 template <typename X, typename T, typename xl = std::numeric_limits<X>>
-constexpr bool
-_fits_in(T v, std::false_type, std::true_type /* T signed */, std::false_type /* X unsigned*/)
-{
-    return 0 <= v && typename std::make_unsigned<T>::type(v) <= (xl::max)();
+constexpr bool _fits_in(T v, std::false_type, std::true_type /* T signed */, std::false_type /* X unsigned*/) {
+  return 0 <= v && typename std::make_unsigned<T>::type(v) <= (xl::max)();
 }
 
 template <typename X, typename T, typename xl = std::numeric_limits<X>>
-constexpr bool
-_fits_in(T v, std::false_type, std::false_type /* T unsigned */, ...)
-{
-    return v <= typename std::make_unsigned<X>::type((xl::max)());
+constexpr bool _fits_in(T v, std::false_type, std::false_type /* T unsigned */, ...) {
+  return v <= typename std::make_unsigned<X>::type((xl::max)());
 }
 
 template <typename X, typename T>

``````````

</details>


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


More information about the libcxx-commits mailing list