https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115668
Bug ID: 115668 Summary: Cannot format chrono::duration<unsigned> Product: gcc Version: 13.3.1 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- std::format("", std::chrono::duration<unsigned>{}) fails with: /home/jwakely/gcc/15/include/c++/15.0.0/bits/chrono_io.h:1699:44: error: no matching function for call to ‘abs(const std::chrono::duration<unsigned int>&)’ 1699 | return _M_f._M_format(chrono::abs(__d), __fc, __d < __d.zero()); | ~~~~~~~~~~~^~~~~ chrono::abs is only defined for durations with signed rep types. This fixes it: --- a/libstdc++-v3/include/bits/chrono_io.h +++ b/libstdc++-v3/include/bits/chrono_io.h @@ -1696,10 +1696,10 @@ namespace __format format(const chrono::duration<_Rep, _Period>& __d, basic_format_context<_Out, _CharT>& __fc) const { - const bool __is_neg = __d < __d.zero(); - if (__is_neg) - __d = -__d; - return _M_f._M_format(__d, __fc, __is_neg); + if (__d < __d.zero()) + return _M_f._M_format(-__d, __fc, true); + else + return _M_f._M_format(__d, __fc, false); } private: