Skip to content

Commit ed85003

Browse files
committed
Addresses review comments.
1 parent bb97e00 commit ed85003

File tree

10 files changed

+70
-49
lines changed

10 files changed

+70
-49
lines changed

libcxx/include/__chrono/leap_second.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class leap_second {
5252
seconds __value_;
5353
};
5454

55-
_LIBCPP_HIDE_FROM_ABI constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
55+
_LIBCPP_HIDE_FROM_ABI inline constexpr bool operator==(const leap_second& __x, const leap_second& __y) {
5656
return __x.date() == __y.date();
5757
}
58-
_LIBCPP_HIDE_FROM_ABI constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
58+
_LIBCPP_HIDE_FROM_ABI inline constexpr strong_ordering operator<=>(const leap_second& __x, const leap_second& __y) {
5959
return __x.date() <=> __y.date();
6060
}
6161

libcxx/src/tzdb.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,9 @@ void __init_tzdb(tzdb& __tzdb, __tz::__rules_storage_type& __rules) {
669669
// The latter is much easier to parse, it seems Howard shares that
670670
// opinion.
671671
chrono::__parse_leap_seconds(__tzdb.leap_seconds, ifstream{__root / "leap-seconds.list"});
672-
// Note the input is sorted, but that does not seem to be are
673-
// requirement, it is a requirement in the Standard.
672+
// The Standard requires the leap seconds to be sorted. The file
673+
// leap-seconds.list usually provides them in sorted order, but that is not
674+
// guaranteed so we ensure it here.
674675
std::ranges::sort(__tzdb.leap_seconds);
675676
}
676677

libcxx/test/libcxx/time/time.zone/time.zone.db/leap_seconds.pass.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,23 +75,28 @@ static void test_invalid() {
7575
static void test_leap_seconds() {
7676
using namespace std::chrono;
7777

78+
// Test whether loading also sorts the entries in the proper order.
7879
const tzdb& result = parse(
7980
R"(
80-
2272060800 10 # 1 Jan 1972
81-
2287785600 11 # 1 Jul 1972
8281
2303683200 12 # 1 Jan 1973
82+
2287785600 11 # 1 Jul 1972
83+
2272060800 10 # 1 Jan 1972
84+
86400 1 # 2 Jan 1900 Dummy entry to test before 1970
8385
)");
8486

85-
assert(result.leap_seconds.size() == 3);
87+
assert(result.leap_seconds.size() == 4);
88+
89+
assert(result.leap_seconds[0].date() == sys_seconds{sys_days{1900y / January / 2}});
90+
assert(result.leap_seconds[0].value() == 1s);
8691

87-
assert(result.leap_seconds[0].date() == sys_seconds{sys_days{1972y / January / 1}});
88-
assert(result.leap_seconds[0].value() == 10s);
92+
assert(result.leap_seconds[1].date() == sys_seconds{sys_days{1972y / January / 1}});
93+
assert(result.leap_seconds[1].value() == 10s);
8994

90-
assert(result.leap_seconds[1].date() == sys_seconds{sys_days{1972y / July / 1}});
91-
assert(result.leap_seconds[1].value() == 11s);
95+
assert(result.leap_seconds[2].date() == sys_seconds{sys_days{1972y / July / 1}});
96+
assert(result.leap_seconds[2].value() == 11s);
9297

93-
assert(result.leap_seconds[2].date() == sys_seconds{sys_days{1973y / January / 1}});
94-
assert(result.leap_seconds[2].value() == 12s);
98+
assert(result.leap_seconds[3].date() == sys_seconds{sys_days{1973y / January / 1}});
99+
assert(result.leap_seconds[3].value() == 12s);
95100
}
96101

97102
int main(int, const char**) {

libcxx/test/std/time/time.zone/time.zone.db/time.zone.db.tzdb/tzdb.members.pass.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,9 @@ int main(int, const char**) {
3737
tzdb.version = "version";
3838
assert(tzdb.version == "version");
3939

40-
[[maybe_unused]] std::vector<std::chrono::time_zone>& zones = tzdb.zones;
41-
40+
[[maybe_unused]] std::vector<std::chrono::time_zone>& zones = tzdb.zones;
4241
[[maybe_unused]] std::vector<std::chrono::time_zone_link>& links = tzdb.links;
43-
44-
// TODO TZDB add the leap data member
42+
[[maybe_unused]] std::vector<std::chrono::leap_second>& leap_seconds = tzdb.leap_seconds;
4543

4644
return 0;
4745
}

libcxx/test/std/time/time.zone/time.zone.leap/assign.copy.pass.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// };
2323

2424
#include <chrono>
25+
#include <memory>
2526
#include <type_traits>
2627
#include <cassert>
2728

@@ -39,7 +40,9 @@ constexpr bool test() {
3940
assert(a.date() != b.date());
4041
assert(a.value() != b.value());
4142

42-
b = a;
43+
std::same_as<std::chrono::leap_second&> decltype(auto) result(b = a);
44+
assert(std::addressof(result) == std::addressof(b));
45+
4346
assert(a.date() == b.date());
4447
assert(a.value() == b.value());
4548

libcxx/test/std/time/time.zone/time.zone.leap/cons.copy.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
constexpr bool test() {
3333
std::chrono::leap_second a =
3434
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1});
35-
std::chrono::leap_second b(a);
35+
std::chrono::leap_second b = a;
3636

3737
// operator== only compares the date member.
3838
assert(a.date() == b.date());

libcxx/test/std/time/time.zone/time.zone.leap/members/date.pass.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@
2727
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
2828
#include "test_chrono_leap_second.h"
2929

30-
constexpr bool test(const std::chrono::leap_second leap_second, std::chrono::sys_seconds expected) {
30+
constexpr void test(const std::chrono::leap_second leap_second, std::chrono::sys_seconds expected) {
3131
std::same_as<std::chrono::sys_seconds> auto date = leap_second.date();
3232
assert(date == expected);
3333
static_assert(noexcept(leap_second.date()));
34+
}
35+
36+
constexpr bool test() {
37+
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
38+
std::chrono::sys_seconds{std::chrono::seconds{0}});
3439

3540
return true;
3641
}
3742

3843
int main(int, const char**) {
44+
test();
45+
static_assert(test());
46+
47+
// test with the real tzdb
3948
const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
4049
assert(!tzdb.leap_seconds.empty());
4150
test(tzdb.leap_seconds[0], tzdb.leap_seconds[0].date());
4251

43-
static_assert(
44-
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
45-
std::chrono::sys_seconds{std::chrono::seconds{0}}));
46-
4752
return 0;
4853
}

libcxx/test/std/time/time.zone/time.zone.leap/members/value.pass.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@
2727
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
2828
#include "test_chrono_leap_second.h"
2929

30-
constexpr bool test(const std::chrono::leap_second leap_second, std::chrono::seconds expected) {
30+
constexpr void test(const std::chrono::leap_second leap_second, std::chrono::seconds expected) {
3131
std::same_as<std::chrono::seconds> auto value = leap_second.value();
3232
assert(value == expected);
3333
static_assert(noexcept(leap_second.value()));
34+
}
35+
36+
constexpr bool test() {
37+
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
38+
std::chrono::seconds{1});
3439

3540
return true;
3641
}
3742

3843
int main(int, const char**) {
44+
test();
45+
static_assert(test());
46+
47+
// test with the real tzdb
3948
const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
4049
assert(!tzdb.leap_seconds.empty());
4150
test(tzdb.leap_seconds[0], tzdb.leap_seconds[0].value());
4251

43-
static_assert(
44-
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
45-
std::chrono::seconds{1}));
46-
4752
return 0;
4853
}

libcxx/test/std/time/time.zone/time.zone.leap/nonmembers/comparison.pass.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
5252
#include "test_chrono_leap_second.h"
5353

54-
constexpr bool test(const std::chrono::leap_second lhs, const std::chrono::leap_second rhs) {
54+
constexpr void test(const std::chrono::leap_second lhs, const std::chrono::leap_second rhs) {
5555
AssertOrderReturn<std::strong_ordering, std::chrono::leap_second>();
5656
assert(testOrder(lhs, rhs, std::strong_ordering::less));
5757

@@ -60,18 +60,23 @@ constexpr bool test(const std::chrono::leap_second lhs, const std::chrono::leap_
6060

6161
AssertOrderReturn<std::strong_ordering, std::chrono::sys_seconds, std::chrono::leap_second>();
6262
assert(testOrder(lhs.date(), rhs, std::strong_ordering::less));
63+
}
64+
65+
constexpr bool test() {
66+
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
67+
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{1}}, std::chrono::seconds{2}));
6368

6469
return true;
6570
}
6671

6772
int main(int, const char**) {
73+
test();
74+
static_assert(test());
75+
76+
// test with the real tzdb
6877
const std::chrono::tzdb& tzdb = std::chrono::get_tzdb();
6978
assert(tzdb.leap_seconds.size() > 2);
7079
test(tzdb.leap_seconds[0], tzdb.leap_seconds[1]);
7180

72-
static_assert(
73-
test(test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{0}}, std::chrono::seconds{1}),
74-
test_leap_second_create(std::chrono::sys_seconds{std::chrono::seconds{1}}, std::chrono::seconds{2})));
75-
7681
return 0;
7782
}

libcxx/test/support/test_chrono_leap_second.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,17 @@
1010
#ifndef SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
1111
#define SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP
1212

13-
/**
14-
* @file Helper functions to create a @ref std::chrono::leap_second.
15-
*
16-
* Since the standard doesn't specify how a @ref std::chrono::leap_second is
17-
* constructed this is implementation defined. To make the public API tests of
18-
* the class generic this header defines helper functions to create the
19-
* required object.
20-
*
21-
* @note This requires every standard library implementation to write their own
22-
* helper function. Vendors are encouraged to create a pull request at
23-
* https://github.com/llvm/llvm-project so their specific implementation can be
24-
* part of this file.
25-
*/
13+
// Contains helper functions to create a std::chrono::leap_second.
14+
//
15+
// Since the standard doesn't specify how a @ref std::chrono::leap_second is
16+
// constructed this is implementation defined. To make the public API tests of
17+
// the class generic this header defines helper functions to create the
18+
// required object.
19+
//
20+
// Note This requires every standard library implementation to write their own
21+
// helper function. Vendors are encouraged to create a pull request at
22+
// https://github.com/llvm/llvm-project so their specific implementation can be
23+
// part of this file.
2624

2725
#include "test_macros.h"
2826

@@ -36,7 +34,7 @@
3634

3735
// In order to find this include the calling test needs to provide this path in
3836
// the search path. Typically this looks like:
39-
// REMOVE_THIS_PREFIX__ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
37+
// ADDITIONAL_COMPILE_FLAGS(stdlib=libc++): -I %S/../../../../../../src/include
4038
// where the number of `../` sequences depends on the subdirectory level of the
4139
// test.
4240
# include "tzdb/leap_second_private.h" // Header in the dylib
@@ -47,7 +45,8 @@ test_leap_second_create(const std::chrono::sys_seconds& date, const std::chrono:
4745
}
4846

4947
#else // _LIBCPP_VERSION
50-
# error "Please create a vendor specific version of the test functions and file a review at https://reviews.llvm.org/"
48+
# error \
49+
"Please create a vendor specific version of the test typedef and file a PR at https://github.com/llvm/llvm-project"
5150
#endif // _LIBCPP_VERSION
5251

5352
#endif // SUPPORT_TEST_CHRONO_LEAP_SECOND_HPP

0 commit comments

Comments
 (0)