This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3921. Is std::chrono::duration<std::int64_t, std::ratio<INT64_MAX - 1, INT64_MAX>>{40} required to be correctly formatted?

Section: 29.12 [time.format] Status: New Submitter: Jiang An Opened: 2023-04-14 Last modified: 2023-04-23

Priority: 3

View other active issues in [time.format].

View all other issues in [time.format].

View all issues with New status.

Discussion:

Currently none of MSVC STL, libc++, and libstdc++ correctly formats duration<int64_t, ratio<INT64_MAX -1, INT64_MAX>>{40} (Godbolt link). For MSVC and libstdc++, hh_mm_ss is used when formatting duration and thus duration_cast is also involved. And it's extremely easy for duration_cast to cause UB when the source type is duration<int64_t, ratio<INT64_MAX -1, INT64_MAX>>.

However, 29.12 [time.format] doesn't say hh_mm_ss is equivalently used when formatting duration. And it seems that the current wording require duration (whose rep type is an arithmetic type) to be correctly formatted without UB, even if it is of a weird type or extremely large (e.g. when it is duration<int64_t, ratio<INT64_MAX, 1>>{INT64_MAX}).

So, if it is intended that hh_mm_ss is used for formatting duration, perhaps we should explicitly so specify in 29.12 [time.format]. And we may need to fix initialization of hh_mm_ss to reduce UB whenever suitable.

[2023-05-24; Reflector poll]

Set priority to 3 after reflector poll.

"NAD. A compile-time error is required when ratio arithmetic overflows, 21.4.4 [ratio.arithmetic] p2"

Proposed resolution: