Title
Is std::chrono::duration<std::int64_t, std::ratio<INT64_MAX - 1, INT64_MAX>>{40} required to be correctly formatted?
Status
new
Section
[time.format]
Submitter
Jiang An

Created on 2023-04-14.00:00:00 last changed 18 months ago

Messages

Date: 2023-05-15.00:00:00

[ 2023-05-24; Reflector poll ]

Set priority to 3 after reflector poll.

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

Date: 2023-04-23.13:30:03

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, [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 [time.format]. And we may need to fix initialization of hh_mm_ss to reduce UB whenever suitable.

History
Date User Action Args
2023-05-24 14:33:00adminsetmessages: + msg13571
2023-04-14 00:00:00admincreate