[libcxx-commits] [libcxx] [libc++][NFC] Add a few explicit 'inline' keywords, mostly in <chrono> (PR #75234)

via libcxx-commits libcxx-commits at lists.llvm.org
Tue Dec 12 10:51:26 PST 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 06613095c4e56447d75560a0968d5af4025eee58 fbf787530ddd3046bb80465a8a9041ab4670c03b -- libcxx/include/__chrono/day.h libcxx/include/__chrono/hh_mm_ss.h libcxx/include/__chrono/month.h libcxx/include/__chrono/monthday.h libcxx/include/__chrono/weekday.h libcxx/include/__chrono/year_month.h libcxx/include/__chrono/year_month_day.h libcxx/include/__variant/monostate.h libcxx/include/cmath libcxx/include/complex libcxx/include/cstddef
``````````

</details>

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

``````````diff
diff --git a/libcxx/include/__chrono/hh_mm_ss.h b/libcxx/include/__chrono/hh_mm_ss.h
index 0adee2d60d..05bce7ceaa 100644
--- a/libcxx/include/__chrono/hh_mm_ss.h
+++ b/libcxx/include/__chrono/hh_mm_ss.h
@@ -87,22 +87,27 @@ private:
 };
 _LIBCPP_CTAD_SUPPORTED_FOR_TYPE(hh_mm_ss);
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
-_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept {
+  return __h >= hours(0) && __h < hours(12);
+}
+_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept {
+  return __h >= hours(12) && __h < hours(24);
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept
-{
-    if      (__h == hours( 0)) return hours(12);
-    else if (__h <= hours(12)) return __h;
-    else                       return __h - hours(12);
+_LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept {
+  if (__h == hours(0))
+    return hours(12);
+  else if (__h <= hours(12))
+    return __h;
+  else
+    return __h - hours(12);
 }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept
-{
-    if (__is_pm)
-        return __h == hours(12) ? __h : __h + hours(12);
-    else
-        return __h == hours(12) ? hours(0) : __h;
+_LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept {
+  if (__is_pm)
+    return __h == hours(12) ? __h : __h + hours(12);
+  else
+    return __h == hours(12) ? hours(0) : __h;
 }
 } // namespace chrono
 
diff --git a/libcxx/include/__chrono/month.h b/libcxx/include/__chrono/month.h
index 2dee5d8c6c..8536cbde82 100644
--- a/libcxx/include/__chrono/month.h
+++ b/libcxx/include/__chrono/month.h
@@ -47,7 +47,7 @@ bool operator==(const month& __lhs, const month& __rhs) noexcept
 { return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
-    return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
+  return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
 }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr
diff --git a/libcxx/include/__chrono/monthday.h b/libcxx/include/__chrono/monthday.h
index 8403d9ec4e..fbdfc84cd3 100644
--- a/libcxx/include/__chrono/monthday.h
+++ b/libcxx/include/__chrono/monthday.h
@@ -59,31 +59,32 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
 bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
 { return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
-    if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
-        return __c;
-    return __lhs.day() <=> __rhs.day();
+_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
+operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
+  if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
+    return __c;
+  return __lhs.day() <=> __rhs.day();
 }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr
 month_day operator/(const month& __lhs, const day& __rhs) noexcept
 { return month_day{__lhs, __rhs}; }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-month_day operator/(const day& __lhs, const month& __rhs) noexcept
-{ return __rhs / __lhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, const month& __rhs) noexcept {
+  return __rhs / __lhs;
+}
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr
 month_day operator/(const month& __lhs, int __rhs) noexcept
 { return __lhs / day(__rhs); }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-month_day operator/(int __lhs, const day& __rhs) noexcept
-{ return month(__lhs) / __rhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(int __lhs, const day& __rhs) noexcept {
+  return month(__lhs) / __rhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-month_day operator/(const day& __lhs, int __rhs) noexcept
-{ return month(__rhs) / __lhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr month_day operator/(const day& __lhs, int __rhs) noexcept {
+  return month(__rhs) / __lhs;
+}
 
 class month_day_last {
 private:
@@ -101,7 +102,7 @@ bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexce
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
 operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
-    return __lhs.month() <=> __rhs.month();
+  return __lhs.month() <=> __rhs.month();
 }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr
diff --git a/libcxx/include/__chrono/weekday.h b/libcxx/include/__chrono/weekday.h
index 292fcb40dc..68bb125ce9 100644
--- a/libcxx/include/__chrono/weekday.h
+++ b/libcxx/include/__chrono/weekday.h
@@ -85,28 +85,24 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
 bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
 { return !(__lhs < __rhs); }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
-{
-    auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
-    auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
-    return weekday{static_cast<unsigned>(__mu - __yr * 7)};
+_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const weekday& __lhs, const days& __rhs) noexcept {
+  auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
+  auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
+  return weekday{static_cast<unsigned>(__mu - __yr * 7)};
 }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
-{ return __rhs + __lhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator+(const days& __lhs, const weekday& __rhs) noexcept {
+  return __rhs + __lhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
-{ return __lhs + -__rhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr weekday operator-(const weekday& __lhs, const days& __rhs) noexcept {
+  return __lhs + -__rhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
-{
-    const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
-    const int __wk = (__wdu >= 0 ? __wdu : __wdu-6) / 7;
-    return days{__wdu - __wk * 7};
+_LIBCPP_HIDE_FROM_ABI inline constexpr days operator-(const weekday& __lhs, const weekday& __rhs) noexcept {
+  const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();
+  const int __wk  = (__wdu >= 0 ? __wdu : __wdu - 6) / 7;
+  return days{__wdu - __wk * 7};
 }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr
diff --git a/libcxx/include/__chrono/year_month.h b/libcxx/include/__chrono/year_month.h
index 320cf588cc..77b864362f 100644
--- a/libcxx/include/__chrono/year_month.h
+++ b/libcxx/include/__chrono/year_month.h
@@ -53,44 +53,44 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
 bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
 { return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
-    if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
-      return __c;
-    return __lhs.month() <=> __rhs.month();
+_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
+operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
+  if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
+    return __c;
+  return __lhs.month() <=> __rhs.month();
 }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
-{
-    int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
-    const int __dy = (__dmi >= 0 ? __dmi : __dmi-11) / 12;
-    __dmi = __dmi - __dy * 12 + 1;
-    return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const months& __rhs) noexcept {
+  int __dmi      = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
+  const int __dy = (__dmi >= 0 ? __dmi : __dmi - 11) / 12;
+  __dmi          = __dmi - __dy * 12 + 1;
+  return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
 }
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
-{ return __rhs + __lhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const months& __lhs, const year_month& __rhs) noexcept {
+  return __rhs + __lhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
-{ return (__lhs.year() + __rhs) / __lhs.month(); }
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const year_month& __lhs, const years& __rhs) noexcept {
+  return (__lhs.year() + __rhs) / __lhs.month();
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
-{ return __rhs + __lhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator+(const years& __lhs, const year_month& __rhs) noexcept {
+  return __rhs + __lhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
-{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
+_LIBCPP_HIDE_FROM_ABI inline constexpr months operator-(const year_month& __lhs, const year_month& __rhs) noexcept {
+  return (__lhs.year() - __rhs.year()) +
+         months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month()));
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
-{ return __lhs + -__rhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const months& __rhs) noexcept {
+  return __lhs + -__rhs;
+}
 
-_LIBCPP_HIDE_FROM_ABI inline constexpr
-year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
-{ return __lhs + -__rhs; }
+_LIBCPP_HIDE_FROM_ABI inline constexpr year_month operator-(const year_month& __lhs, const years& __rhs) noexcept {
+  return __lhs + -__rhs;
+}
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr year_month& year_month::operator+=(const months& __dm) noexcept {
   *this = *this + __dm;
diff --git a/libcxx/include/__chrono/year_month_day.h b/libcxx/include/__chrono/year_month_day.h
index e84d2f8a83..24fc3a5933 100644
--- a/libcxx/include/__chrono/year_month_day.h
+++ b/libcxx/include/__chrono/year_month_day.h
@@ -112,11 +112,11 @@ bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexce
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
 operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept {
-    if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
-      return __c;
-    if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
-      return __c;
-    return __lhs.day() <=> __rhs.day();
+  if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
+    return __c;
+  if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
+    return __c;
+  return __lhs.day() <=> __rhs.day();
 }
 
 _LIBCPP_HIDE_FROM_ABI inline constexpr

``````````

</details>


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


More information about the libcxx-commits mailing list