Skip to content

Commit 0858a05

Browse files
committed
Fixes CI issues and adds missing tests.
1 parent 6f521f1 commit 0858a05

File tree

9 files changed

+157
-6
lines changed

9 files changed

+157
-6
lines changed

libcxx/docs/Status/FormatPaper.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Section,Description,Dependencies,Assignee,Status,First released version
33
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::duration<Rep, Period>``",,Mark de Wever,|Complete|,16
44
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::sys_time<Duration>``",,Mark de Wever,|Complete|,17
55
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::utc_time<Duration>``",A ``<chrono>`` implementation,Mark de Wever,|Complete|,20
6-
+`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::tai_time<Duration>``",,Mark de Wever,|Complete|,21
6+
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::tai_time<Duration>``",,Mark de Wever,|Complete|,21
77
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::gps_time<Duration>``",A ``<chrono>`` implementation,Mark de Wever,,,
88
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::file_time<Duration>``",,Mark de Wever,|Complete|,17
99
`[time.syn] <https://wg21.link/time.syn>`_,"Formatter ``chrono::local_time<Duration>``",,Mark de Wever,|Complete|,17

libcxx/include/__chrono/tai_clock.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
# pragma GCC system_header
2626
# endif
2727

28+
_LIBCPP_PUSH_MACROS
29+
# include <__undef_macros>
30+
2831
_LIBCPP_BEGIN_NAMESPACE_STD
2932

3033
# if _LIBCPP_STD_VER >= 20 && _LIBCPP_HAS_TIME_ZONE_DATABASE && _LIBCPP_HAS_FILESYSTEM && _LIBCPP_HAS_LOCALIZATION
@@ -98,6 +101,8 @@ class tai_clock {
98101

99102
_LIBCPP_END_NAMESPACE_STD
100103

104+
_LIBCPP_POP_MACROS
105+
101106
#endif // _LIBCPP_HAS_EXPERIMENTAL_TZDB
102107

103108
#endif // _LIBCPP___CHRONO_TAI_CLOCK_H
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++20
10+
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
11+
12+
// XFAIL: libcpp-has-no-experimental-tzdb
13+
// XFAIL: availability-tzdb-missing
14+
15+
// REQUIRES: has-unix-headers
16+
// UNSUPPORTED: libcpp-hardening-mode=none
17+
// XFAIL: libcpp-hardening-mode=fast && availability-verbose_abort-missing
18+
19+
// <chrono>
20+
//
21+
// class tai_clock;
22+
23+
// static tai_time<common_type_t<_Duration, seconds>>
24+
// from_utc(const utc_time<_Duration>& t) noexcept;
25+
26+
#include <chrono>
27+
28+
#include "check_assertion.h"
29+
30+
// The function is specified as
31+
// tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s
32+
// When t == t.max() there will be a signed integral overflow (other values too).
33+
int main(int, char**) {
34+
using namespace std::literals::chrono_literals;
35+
constexpr std::chrono::seconds offset{378691210};
36+
37+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::nanoseconds>::max() - offset);
38+
TEST_LIBCPP_ASSERT_FAILURE(
39+
std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::nanoseconds>::max() - offset + 1ns),
40+
"the UTC to TAI conversion would overflow");
41+
42+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::microseconds>::max() - offset);
43+
TEST_LIBCPP_ASSERT_FAILURE(
44+
std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::microseconds>::max() - offset + 1us),
45+
"the UTC to TAI conversion would overflow");
46+
47+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::milliseconds>::max() - offset);
48+
TEST_LIBCPP_ASSERT_FAILURE(
49+
std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::milliseconds>::max() - offset + 1ms),
50+
"the UTC to TAI conversion would overflow");
51+
52+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_seconds::max() - offset);
53+
TEST_LIBCPP_ASSERT_FAILURE(std::chrono::tai_clock::from_utc(std::chrono::utc_seconds::max() - offset + 1s),
54+
"the UTC to TAI conversion would overflow");
55+
56+
// The conversion uses `common_type_t<Duration, seconds>` so types "larger"
57+
// than seconds are converted to seconds. Types "larger" than seconds are
58+
// stored in "smaller" intergral and the overflow can never occur.
59+
60+
// Validate the types can never overflow on all current (and future) supported platforms.
61+
static_assert(std::chrono::utc_time<std::chrono::days>::max() <= std::chrono::utc_seconds::max() - offset);
62+
static_assert(std::chrono::utc_time<std::chrono::weeks>::max() <= std::chrono::utc_seconds::max() - offset);
63+
static_assert(std::chrono::utc_time<std::chrono::months>::max() <= std::chrono::utc_seconds::max() - offset);
64+
static_assert(std::chrono::utc_time<std::chrono::years>::max() <= std::chrono::utc_seconds::max() - offset);
65+
66+
// Validate the run-time conversion works.
67+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::days>::max());
68+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::weeks>::max());
69+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::months>::max());
70+
(void)std::chrono::tai_clock::from_utc(std::chrono::utc_time<std::chrono::years>::max());
71+
72+
return 0;
73+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
// REQUIRES: std-at-least-c++20
10+
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
11+
12+
// XFAIL: libcpp-has-no-experimental-tzdb
13+
// XFAIL: availability-tzdb-missing
14+
15+
// REQUIRES: has-unix-headers
16+
// UNSUPPORTED: libcpp-hardening-mode=none
17+
// XFAIL: libcpp-hardening-mode=fast && availability-verbose_abort-missing
18+
19+
// <chrono>
20+
//
21+
// class tai_clock;
22+
23+
// static utc_time<common_type_t<_Duration, seconds>>
24+
// to_utc(const tai_time<_Duration>& t) noexcept;
25+
26+
#include <chrono>
27+
28+
#include "check_assertion.h"
29+
30+
// The function is specified as
31+
// utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s
32+
// When t == t.min() there will be a signed integral underlow (other values too).
33+
int main(int, char**) {
34+
using namespace std::literals::chrono_literals;
35+
constexpr std::chrono::seconds offset{378691210};
36+
37+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::nanoseconds>::min() + offset);
38+
TEST_LIBCPP_ASSERT_FAILURE(
39+
std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::nanoseconds>::min() + offset - 1ns),
40+
"the TAI to UTC conversion would underflow");
41+
42+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::microseconds>::min() + offset);
43+
TEST_LIBCPP_ASSERT_FAILURE(
44+
std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::microseconds>::min() + offset - 1us),
45+
"the TAI to UTC conversion would underflow");
46+
47+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::milliseconds>::min() + offset);
48+
TEST_LIBCPP_ASSERT_FAILURE(
49+
std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::milliseconds>::min() + offset - 1ms),
50+
"the TAI to UTC conversion would underflow");
51+
52+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_seconds::min() + offset);
53+
TEST_LIBCPP_ASSERT_FAILURE(std::chrono::tai_clock::to_utc(std::chrono::tai_seconds::min() + offset - 1s),
54+
"the TAI to UTC conversion would underflow");
55+
56+
// The conversion uses `common_type_t<Duration, seconds>` so types "larger"
57+
// than seconds are converted to seconds. Types "larger" than seconds are
58+
// stored in "smaller" intergral and the underflow can never occur.
59+
60+
// Validate the types can never underflow on all current (and future) supported platforms.
61+
static_assert(std::chrono::tai_time<std::chrono::days>::min() >= std::chrono::tai_seconds::min() + offset);
62+
static_assert(std::chrono::tai_time<std::chrono::weeks>::min() >= std::chrono::tai_seconds::min() + offset);
63+
static_assert(std::chrono::tai_time<std::chrono::months>::min() >= std::chrono::tai_seconds::min() + offset);
64+
static_assert(std::chrono::tai_time<std::chrono::years>::min() >= std::chrono::tai_seconds::min() + offset);
65+
66+
// Validate the run-time conversion works.
67+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::days>::min());
68+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::weeks>::min());
69+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::months>::min());
70+
(void)std::chrono::tai_clock::to_utc(std::chrono::tai_time<std::chrono::years>::min());
71+
72+
return 0;
73+
}

libcxx/test/std/time/time.clock/time.clock.tai/tai_time.ostream.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// TODO FMT This test should not require std::to_chars(floating-point)
1414
// XFAIL: availability-fp_to_chars-missing
1515

16-
// XFAIL: libcpp-has-no-incomplete-tzdb
16+
// XFAIL: libcpp-has-no-experimental-tzdb
1717
// XFAIL: availability-tzdb-missing
1818

1919
// REQUIRES: locale.fr_FR.UTF-8

libcxx/test/std/time/time.clock/time.clock.tai/time.clock.tai.members/from_utc.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// REQUIRES: std-at-least-c++20
1010
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
1111

12-
// XFAIL: libcpp-has-no-incomplete-tzdb
12+
// XFAIL: libcpp-has-no-experimental-tzdb
1313
// XFAIL: availability-tzdb-missing
1414

1515
// <chrono>

libcxx/test/std/time/time.clock/time.clock.tai/time.clock.tai.members/now.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// REQUIRES: std-at-least-c++20
1010
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
1111

12-
// XFAIL: libcpp-has-no-incomplete-tzdb
12+
// XFAIL: libcpp-has-no-experimental-tzdb
1313
// XFAIL: availability-tzdb-missing
1414

1515
// <chrono>

libcxx/test/std/time/time.clock/time.clock.tai/time.clock.tai.members/to_utc.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// REQUIRES: std-at-least-c++20
1010
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
1111

12-
// XFAIL: libcpp-has-no-incomplete-tzdb
12+
// XFAIL: libcpp-has-no-experimental-tzdb
1313
// XFAIL: availability-tzdb-missing
1414

1515
// <chrono>

libcxx/test/std/time/time.clock/time.clock.tai/types.compile.pass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// REQUIRES: std-at-least-c++20
1010
// UNSUPPORTED: no-filesystem, no-localization, no-tzdb
1111

12-
// XFAIL: libcpp-has-no-incomplete-tzdb
12+
// XFAIL: libcpp-has-no-experimental-tzdb
1313
// XFAIL: availability-tzdb-missing
1414

1515
// <chrono>

0 commit comments

Comments
 (0)