Repository navigation
Conversation
vitaut
left a comment
There was a problem hiding this comment.
Floating-point-to-integer conversion truncates toward zero, so values slightly below the minimum are also valid. For example, converting -0.5 to unsigned produces 0, but this check rejects it. Could we check std::trunc(count) instead and add a regression test?
|
Good catch. The check was on the raw count, so Switched it to check |
vitaut
left a comment
There was a problem hiding this comment.
One remaining concern: the change removes support for custom duration representations. The previous overload handled any combination of representation types that wasn't integral-to-integral or floating-point-to-floating-point. The new overloads only handle built-in arithmetic types.
I think we should preserve the original fallback for other representation types.
|
Right, the split dropped every rep that isn't a built-in arithmetic type. A Restored the original fallback in f501601. It now covers everything that isn't similar-arithmetic and isn't float to integral, so custom reps and integer to float go through Added |
UBSan, clang -fsanitize=undefined, when formatting a time point with a floating-point rep:
Repro:
The mixed integer <-> float overload of
detail::duration_castdelegates tostd::chrono::duration_cast, soto_time_tand thesys_time/local_timeformatters convert the seconds count with an uncheckedstatic_cast. Only the float to integral direction can overflow, so the overload is split: integer to float keeps the plain cast, and float to integral range-checks the count before casting (which also rejects NaN) and throws like the other checked overloads, with the same boundary handling asto_nonnegative_int(#4802).is_similar_arithmetic_typehad no remaining users and is removed.