You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Formatting a chrono duration with an unsigned count type triggers -Wsign-compare.
The culprit is the to_nonnegative_int function for integers:
// Converts value to int and checks that it's in the range [0, upper).
template <typename T, FMT_ENABLE_IF(std::is_integral<T>::value)>
inline int to_nonnegative_int(T value, int upper) {
FMT_ASSERT(value >= 0 && value <= upper, "invalid value");
(void)upper;
return static_cast<int>(value);
}
Changing the assert to e.g. FMT_ASSERT(value >= 0 && value <= T{} + upper, "invalid value"); should fix this.
Also note that the implementation doesn't assert what the comment says. The comment says upper) (=exclusive) but the implementation checks for <= upper (inclusive). (The same is also true for the implementation for floating point types BTW.)
Changing this would however also require changing the line
time.tm_hour = to_nonnegative_int(hour12(), 12);
in chrono_formatter::on_12_hour since 12 is actually a possible value there.
The text was updated successfully, but these errors were encountered:
Formatting a chrono duration with an unsigned count type triggers -Wsign-compare.
The culprit is the
to_nonnegative_int
function for integers:Changing the assert to e.g.
FMT_ASSERT(value >= 0 && value <= T{} + upper, "invalid value");
should fix this.Also note that the implementation doesn't assert what the comment says. The comment says
upper)
(=exclusive) but the implementation checks for<= upper
(inclusive). (The same is also true for the implementation for floating point types BTW.)Changing this would however also require changing the line
in
chrono_formatter::on_12_hour
since 12 is actually a possible value there.The text was updated successfully, but these errors were encountered: