Skip to content

Commit b81c694

Browse files
authored
[libc++][NFC] Add a few explicit 'inline' keywords, mostly in <chrono> (#75234)
Even though constexpr implicitly makes functions inline, we try not to rely on this implicit effect in the code base. We are mostly consistent about using `inline` on non-template free-functions to make it clear that we don't have an ODR violation. This patch simply fixes a few places where we didn't explicitly use inline on non-template free functions, presumably because they were constexpr. Fixes #75227
1 parent a26aa79 commit b81c694

File tree

11 files changed

+47
-47
lines changed

11 files changed

+47
-47
lines changed

libcxx/include/__chrono/day.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
4646
bool operator==(const day& __lhs, const day& __rhs) noexcept
4747
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
4848

49-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
49+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const day& __lhs, const day& __rhs) noexcept {
5050
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
5151
}
5252

libcxx/include/__chrono/hh_mm_ss.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,17 @@ class hh_mm_ss
8787
};
8888
_LIBCPP_CTAD_SUPPORTED_FOR_TYPE(hh_mm_ss);
8989

90-
_LIBCPP_HIDE_FROM_ABI constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
91-
_LIBCPP_HIDE_FROM_ABI constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
90+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_am(const hours& __h) noexcept { return __h >= hours( 0) && __h < hours(12); }
91+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool is_pm(const hours& __h) noexcept { return __h >= hours(12) && __h < hours(24); }
9292

93-
_LIBCPP_HIDE_FROM_ABI constexpr hours make12(const hours& __h) noexcept
93+
_LIBCPP_HIDE_FROM_ABI inline constexpr hours make12(const hours& __h) noexcept
9494
{
9595
if (__h == hours( 0)) return hours(12);
9696
else if (__h <= hours(12)) return __h;
9797
else return __h - hours(12);
9898
}
9999

100-
_LIBCPP_HIDE_FROM_ABI constexpr hours make24(const hours& __h, bool __is_pm) noexcept
100+
_LIBCPP_HIDE_FROM_ABI inline constexpr hours make24(const hours& __h, bool __is_pm) noexcept
101101
{
102102
if (__is_pm)
103103
return __h == hours(12) ? __h : __h + hours(12);

libcxx/include/__chrono/month.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
4646
bool operator==(const month& __lhs, const month& __rhs) noexcept
4747
{ return static_cast<unsigned>(__lhs) == static_cast<unsigned>(__rhs); }
4848

49-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
49+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month& __lhs, const month& __rhs) noexcept {
5050
return static_cast<unsigned>(__lhs) <=> static_cast<unsigned>(__rhs);
5151
}
5252

libcxx/include/__chrono/monthday.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
5959
bool operator==(const month_day& __lhs, const month_day& __rhs) noexcept
6060
{ return __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
6161

62-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
62+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const month_day& __lhs, const month_day& __rhs) noexcept {
6363
if (auto __c = __lhs.month() <=> __rhs.month(); __c != 0)
6464
return __c;
6565
return __lhs.day() <=> __rhs.day();
@@ -69,19 +69,19 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
6969
month_day operator/(const month& __lhs, const day& __rhs) noexcept
7070
{ return month_day{__lhs, __rhs}; }
7171

72-
_LIBCPP_HIDE_FROM_ABI constexpr
72+
_LIBCPP_HIDE_FROM_ABI inline constexpr
7373
month_day operator/(const day& __lhs, const month& __rhs) noexcept
7474
{ return __rhs / __lhs; }
7575

7676
_LIBCPP_HIDE_FROM_ABI inline constexpr
7777
month_day operator/(const month& __lhs, int __rhs) noexcept
7878
{ return __lhs / day(__rhs); }
7979

80-
_LIBCPP_HIDE_FROM_ABI constexpr
80+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8181
month_day operator/(int __lhs, const day& __rhs) noexcept
8282
{ return month(__lhs) / __rhs; }
8383

84-
_LIBCPP_HIDE_FROM_ABI constexpr
84+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8585
month_day operator/(const day& __lhs, int __rhs) noexcept
8686
{ return month(__rhs) / __lhs; }
8787

@@ -99,7 +99,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
9999
bool operator==(const month_day_last& __lhs, const month_day_last& __rhs) noexcept
100100
{ return __lhs.month() == __rhs.month(); }
101101

102-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
102+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
103103
operator<=>(const month_day_last& __lhs, const month_day_last& __rhs) noexcept {
104104
return __lhs.month() <=> __rhs.month();
105105
}

libcxx/include/__chrono/weekday.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,23 +85,23 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
8585
bool operator>=(const weekday& __lhs, const weekday& __rhs) noexcept
8686
{ return !(__lhs < __rhs); }
8787

88-
_LIBCPP_HIDE_FROM_ABI constexpr
88+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8989
weekday operator+(const weekday& __lhs, const days& __rhs) noexcept
9090
{
9191
auto const __mu = static_cast<long long>(__lhs.c_encoding()) + __rhs.count();
9292
auto const __yr = (__mu >= 0 ? __mu : __mu - 6) / 7;
9393
return weekday{static_cast<unsigned>(__mu - __yr * 7)};
9494
}
9595

96-
_LIBCPP_HIDE_FROM_ABI constexpr
96+
_LIBCPP_HIDE_FROM_ABI inline constexpr
9797
weekday operator+(const days& __lhs, const weekday& __rhs) noexcept
9898
{ return __rhs + __lhs; }
9999

100-
_LIBCPP_HIDE_FROM_ABI constexpr
100+
_LIBCPP_HIDE_FROM_ABI inline constexpr
101101
weekday operator-(const weekday& __lhs, const days& __rhs) noexcept
102102
{ return __lhs + -__rhs; }
103103

104-
_LIBCPP_HIDE_FROM_ABI constexpr
104+
_LIBCPP_HIDE_FROM_ABI inline constexpr
105105
days operator-(const weekday& __lhs, const weekday& __rhs) noexcept
106106
{
107107
const int __wdu = __lhs.c_encoding() - __rhs.c_encoding();

libcxx/include/__chrono/year_month.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
5353
bool operator==(const year_month& __lhs, const year_month& __rhs) noexcept
5454
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month(); }
5555

56-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
56+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const year_month& __lhs, const year_month& __rhs) noexcept {
5757
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
5858
return __c;
5959
return __lhs.month() <=> __rhs.month();
6060
}
6161

62-
_LIBCPP_HIDE_FROM_ABI constexpr
62+
_LIBCPP_HIDE_FROM_ABI inline constexpr
6363
year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
6464
{
6565
int __dmi = static_cast<int>(static_cast<unsigned>(__lhs.month())) - 1 + __rhs.count();
@@ -68,27 +68,27 @@ year_month operator+(const year_month& __lhs, const months& __rhs) noexcept
6868
return (__lhs.year() + years(__dy)) / month(static_cast<unsigned>(__dmi));
6969
}
7070

71-
_LIBCPP_HIDE_FROM_ABI constexpr
71+
_LIBCPP_HIDE_FROM_ABI inline constexpr
7272
year_month operator+(const months& __lhs, const year_month& __rhs) noexcept
7373
{ return __rhs + __lhs; }
7474

75-
_LIBCPP_HIDE_FROM_ABI constexpr
75+
_LIBCPP_HIDE_FROM_ABI inline constexpr
7676
year_month operator+(const year_month& __lhs, const years& __rhs) noexcept
7777
{ return (__lhs.year() + __rhs) / __lhs.month(); }
7878

79-
_LIBCPP_HIDE_FROM_ABI constexpr
79+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8080
year_month operator+(const years& __lhs, const year_month& __rhs) noexcept
8181
{ return __rhs + __lhs; }
8282

83-
_LIBCPP_HIDE_FROM_ABI constexpr
83+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8484
months operator-(const year_month& __lhs, const year_month& __rhs) noexcept
8585
{ return (__lhs.year() - __rhs.year()) + months(static_cast<unsigned>(__lhs.month()) - static_cast<unsigned>(__rhs.month())); }
8686

87-
_LIBCPP_HIDE_FROM_ABI constexpr
87+
_LIBCPP_HIDE_FROM_ABI inline constexpr
8888
year_month operator-(const year_month& __lhs, const months& __rhs) noexcept
8989
{ return __lhs + -__rhs; }
9090

91-
_LIBCPP_HIDE_FROM_ABI constexpr
91+
_LIBCPP_HIDE_FROM_ABI inline constexpr
9292
year_month operator-(const year_month& __lhs, const years& __rhs) noexcept
9393
{ return __lhs + -__rhs; }
9494

libcxx/include/__chrono/year_month_day.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ _LIBCPP_HIDE_FROM_ABI inline constexpr
110110
bool operator==(const year_month_day& __lhs, const year_month_day& __rhs) noexcept
111111
{ return __lhs.year() == __rhs.year() && __lhs.month() == __rhs.month() && __lhs.day() == __rhs.day(); }
112112

113-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering
113+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering
114114
operator<=>(const year_month_day& __lhs, const year_month_day& __rhs) noexcept {
115115
if (auto __c = __lhs.year() <=> __rhs.year(); __c != 0)
116116
return __c;

libcxx/include/__variant/monostate.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2525

2626
struct _LIBCPP_TEMPLATE_VIS monostate {};
2727

28-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(monostate, monostate) noexcept { return true; }
28+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(monostate, monostate) noexcept { return true; }
2929

3030
# if _LIBCPP_STD_VER >= 20
3131

32-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(monostate, monostate) noexcept {
32+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(monostate, monostate) noexcept {
3333
return strong_ordering::equal;
3434
}
3535

3636
# else // _LIBCPP_STD_VER >= 20
3737

38-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator!=(monostate, monostate) noexcept { return false; }
38+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator!=(monostate, monostate) noexcept { return false; }
3939

40-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<(monostate, monostate) noexcept { return false; }
40+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<(monostate, monostate) noexcept { return false; }
4141

42-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>(monostate, monostate) noexcept { return false; }
42+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>(monostate, monostate) noexcept { return false; }
4343

44-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator<=(monostate, monostate) noexcept { return true; }
44+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator<=(monostate, monostate) noexcept { return true; }
4545

46-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator>=(monostate, monostate) noexcept { return true; }
46+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator>=(monostate, monostate) noexcept { return true; }
4747

4848
# endif // _LIBCPP_STD_VER >= 20
4949

libcxx/include/cmath

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,13 @@ _Fp __lerp(_Fp __a, _Fp __b, _Fp __t) noexcept {
798798
return __x < __b ? __x : __b;
799799
}
800800

801-
_LIBCPP_HIDE_FROM_ABI constexpr float
801+
_LIBCPP_HIDE_FROM_ABI inline constexpr float
802802
lerp(float __a, float __b, float __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
803803

804-
_LIBCPP_HIDE_FROM_ABI constexpr double
804+
_LIBCPP_HIDE_FROM_ABI inline constexpr double
805805
lerp(double __a, double __b, double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
806806

807-
_LIBCPP_HIDE_FROM_ABI constexpr long double
807+
_LIBCPP_HIDE_FROM_ABI inline constexpr long double
808808
lerp(long double __a, long double __b, long double __t) _NOEXCEPT { return __lerp(__a, __b, __t); }
809809

810810
template <class _A1, class _A2, class _A3>

libcxx/include/complex

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,34 +1503,34 @@ inline namespace literals
15031503
{
15041504
inline namespace complex_literals
15051505
{
1506-
_LIBCPP_HIDE_FROM_ABI constexpr complex<long double> operator""il(long double __im)
1506+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<long double> operator""il(long double __im)
15071507
{
15081508
return { 0.0l, __im };
15091509
}
15101510

1511-
_LIBCPP_HIDE_FROM_ABI constexpr complex<long double> operator""il(unsigned long long __im)
1511+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<long double> operator""il(unsigned long long __im)
15121512
{
15131513
return { 0.0l, static_cast<long double>(__im) };
15141514
}
15151515

15161516

1517-
_LIBCPP_HIDE_FROM_ABI constexpr complex<double> operator""i(long double __im)
1517+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<double> operator""i(long double __im)
15181518
{
15191519
return { 0.0, static_cast<double>(__im) };
15201520
}
15211521

1522-
_LIBCPP_HIDE_FROM_ABI constexpr complex<double> operator""i(unsigned long long __im)
1522+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<double> operator""i(unsigned long long __im)
15231523
{
15241524
return { 0.0, static_cast<double>(__im) };
15251525
}
15261526

15271527

1528-
_LIBCPP_HIDE_FROM_ABI constexpr complex<float> operator""if(long double __im)
1528+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<float> operator""if(long double __im)
15291529
{
15301530
return { 0.0f, static_cast<float>(__im) };
15311531
}
15321532

1533-
_LIBCPP_HIDE_FROM_ABI constexpr complex<float> operator""if(unsigned long long __im)
1533+
_LIBCPP_HIDE_FROM_ABI inline constexpr complex<float> operator""if(unsigned long long __im)
15341534
{
15351535
return { 0.0f, static_cast<float>(__im) };
15361536
}

libcxx/include/cstddef

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,40 +71,40 @@ namespace std // purposefully not versioned
7171
{
7272
enum class byte : unsigned char {};
7373

74-
_LIBCPP_HIDE_FROM_ABI constexpr byte operator| (byte __lhs, byte __rhs) noexcept
74+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator| (byte __lhs, byte __rhs) noexcept
7575
{
7676
return static_cast<byte>(
7777
static_cast<unsigned char>(
7878
static_cast<unsigned int>(__lhs) | static_cast<unsigned int>(__rhs)
7979
));
8080
}
8181

82-
_LIBCPP_HIDE_FROM_ABI constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
82+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator|=(byte& __lhs, byte __rhs) noexcept
8383
{ return __lhs = __lhs | __rhs; }
8484

85-
_LIBCPP_HIDE_FROM_ABI constexpr byte operator& (byte __lhs, byte __rhs) noexcept
85+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator& (byte __lhs, byte __rhs) noexcept
8686
{
8787
return static_cast<byte>(
8888
static_cast<unsigned char>(
8989
static_cast<unsigned int>(__lhs) & static_cast<unsigned int>(__rhs)
9090
));
9191
}
9292

93-
_LIBCPP_HIDE_FROM_ABI constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
93+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator&=(byte& __lhs, byte __rhs) noexcept
9494
{ return __lhs = __lhs & __rhs; }
9595

96-
_LIBCPP_HIDE_FROM_ABI constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
96+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator^ (byte __lhs, byte __rhs) noexcept
9797
{
9898
return static_cast<byte>(
9999
static_cast<unsigned char>(
100100
static_cast<unsigned int>(__lhs) ^ static_cast<unsigned int>(__rhs)
101101
));
102102
}
103103

104-
_LIBCPP_HIDE_FROM_ABI constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
104+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte& operator^=(byte& __lhs, byte __rhs) noexcept
105105
{ return __lhs = __lhs ^ __rhs; }
106106

107-
_LIBCPP_HIDE_FROM_ABI constexpr byte operator~ (byte __b) noexcept
107+
_LIBCPP_HIDE_FROM_ABI inline constexpr byte operator~ (byte __b) noexcept
108108
{
109109
return static_cast<byte>(
110110
static_cast<unsigned char>(

0 commit comments

Comments
 (0)