basic_format_context<_Out, _CharT>& __fc) const
{
if constexpr (numeric_limits<_Rep>::is_signed)
- if (__d < __d.zero())
- return _M_f._M_format(-__d, __fc, true);
+ if (__d < __d.zero()) [[unlikely]]
+ {
+ if constexpr (is_integral_v<_Rep>)
+ {
+ // -d is undefined for the most negative integer.
+ // Convert duration to corresponding unsigned rep.
+ using _URep = make_unsigned_t<_Rep>;
+ auto __ucnt = -static_cast<_URep>(__d.count());
+ auto __ud = chrono::duration<_URep, _Period>(__ucnt);
+ return _M_f._M_format(__ud, __fc, true);
+ }
+ else
+ return _M_f._M_format(-__d, __fc, true);
+ }
return _M_f._M_format(__d, __fc, false);
}
VERIFY( s == "500ms" );
s = std::format("{:%Q %q}", u);
VERIFY( s == "500 ms" );
+
+ // PR libstdc++/116755 extra minus sign for most negative value
+ auto minsec = std::chrono::seconds::min();
+ s = std::format("{}", minsec);
+ auto expected = std::format("{}s", minsec.count());
+ VERIFY( s == expected );
+ s = std::format("{:%Q%q}", minsec);
+ VERIFY( s == expected );
}
void