[libcxx-commits] [libcxx] [libc++][math] Implement C++23 (parts of) P0533: constexpr `std::div()` (PR #104633)

via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 16 12:10:10 PDT 2024


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 026d963cb004689477d2b5798cbba5ad41c25a70 067b03ac48e4f787ab8ab34a95879e76483a72fb --extensions ,cpp -- libcxx/include/cstdlib libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
``````````

</details>

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

``````````diff
diff --git a/libcxx/include/cstdlib b/libcxx/include/cstdlib
index 8452cf1643..b8a24cb7e2 100644
--- a/libcxx/include/cstdlib
+++ b/libcxx/include/cstdlib
@@ -152,39 +152,29 @@ using ::div _LIBCPP_USING_IF_EXISTS;
 using ::ldiv _LIBCPP_USING_IF_EXISTS;
 using ::lldiv _LIBCPP_USING_IF_EXISTS;
 
-#else  // _LIBCPP_STD_VER >= 23
+#else // _LIBCPP_STD_VER >= 23
 
 template <class _Div_t, class _Int>
 _LIBCPP_HIDE_FROM_ABI constexpr _Div_t __div(_Int __x, _Int __y) {
   _Div_t __d;
   __d.quot = __x / __y;
-  __d.rem = __x % __y;
+  __d.rem  = __x % __y;
   return __d;
 }
 
-inline _LIBCPP_HIDE_FROM_ABI constexpr div_t div(int __x, int __y) {
-  return std::__div<std::div_t>(__x, __y);
-}
+inline _LIBCPP_HIDE_FROM_ABI constexpr div_t div(int __x, int __y) { return std::__div<std::div_t>(__x, __y); }
 
-inline _LIBCPP_HIDE_FROM_ABI constexpr ldiv_t div(long __x, long __y) {
-  return std::__div<std::ldiv_t>(__x, __y);
-}
+inline _LIBCPP_HIDE_FROM_ABI constexpr ldiv_t div(long __x, long __y) { return std::__div<std::ldiv_t>(__x, __y); }
 
-inline _LIBCPP_HIDE_FROM_ABI constexpr lldiv_t div(long long __x,
-                                                   long long __y) {
+inline _LIBCPP_HIDE_FROM_ABI constexpr lldiv_t div(long long __x, long long __y) {
   return std::__div<std::lldiv_t>(__x, __y);
 }
 
-inline _LIBCPP_HIDE_FROM_ABI constexpr ldiv_t ldiv(long __x, long __y) {
-  return std::div(__x, __y);
-}
+inline _LIBCPP_HIDE_FROM_ABI constexpr ldiv_t ldiv(long __x, long __y) { return std::div(__x, __y); }
 
-inline _LIBCPP_HIDE_FROM_ABI constexpr lldiv_t lldiv(long long __x,
-                                                     long long __y) {
-  return std::div(__x, __y);
-}
+inline _LIBCPP_HIDE_FROM_ABI constexpr lldiv_t lldiv(long long __x, long long __y) { return std::div(__x, __y); }
 
-#endif  // _LIBCPP_STD_VER
+#endif // _LIBCPP_STD_VER
 
 _LIBCPP_END_NAMESPACE_STD
 
diff --git a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
index cc2686d19a..9f84a49163 100644
--- a/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
+++ b/libcxx/test/std/language.support/support.runtime/cstdlib.pass.cpp
@@ -80,20 +80,20 @@ template <class TestType, class IntType>
 void test_div_struct() {
   TestType obj;
   static_assert(sizeof(obj) >= sizeof(IntType) * 2,
-                "");  // >= to account for alignment.
+                ""); // >= to account for alignment.
   static_assert((std::is_same<decltype(obj.quot), IntType>::value), "");
   static_assert((std::is_same<decltype(obj.rem), IntType>::value), "");
   ((void)obj);
 }
 
 void test_div() {
-  {  // tests member types of std::div_t, etc.
+  { // tests member types of std::div_t, etc.
     test_div_struct<std::div_t, int>();
     test_div_struct<std::ldiv_t, long>();
     test_div_struct<std::lldiv_t, long long>();
   }
 
-  {  // tests return type of std::div
+  { // tests return type of std::div
     // clang-format off
     static_assert((std::is_same<decltype(std::div(  0,   0  )), std::div_t  >::value), "");
     static_assert((std::is_same<decltype(std::div(  0L,  0L )), std::ldiv_t >::value), "");
@@ -103,7 +103,7 @@ void test_div() {
     // clang-format on
   }
 
-  {  // check one basic input for correctness.
+  { // check one basic input for correctness.
     // (42 // 5 == 8) AND (42 % 5 == 2)
     const auto check = [](const auto callable_div) -> void {
       const auto div = callable_div(42, 5);

``````````

</details>


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


More information about the libcxx-commits mailing list