C++ Logo

std-proposals

Advanced search

Re: [std-proposals] chrono::hh_mm_ss constructor defined in terms of abs

From: Jonathan Wakely <cxx_at_[hidden]>
Date: Tue, 3 Jun 2025 23:24:12 +0100
On Tue, 3 Jun 2025 at 21:58, Howard Hinnant via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I view this as a bug in the spec. It was not intended to outlaw unsigned
> durations for hh_mm_ss.
>
> Upon experimentation I found that my example implementation does not
> outlaw it, gcc does not, msvc does, and llvm does.
>
> A revised wording might look something like: let abs_d have the value -d
> if is_neg is true, else d. Then replace abs(d) with abs_d.
>
> This change in wording will not break gcc. And it will turn cases that
> don’t compile on MSVC and LLVM into cases that do compile, so I believe the
> “breakage” would be acceptable.
>

It's no accident that it works with GCC:

commit r13-5002-ge36e57b032b2d70eaa1294d5921e4fd8ce12a74d
<https://gcc.gnu.org/cgit/gcc/commit/?id=e36e57b032b2d70eaa1294d5921e4fd8ce12a74d>
Author: Jonathan Wakely
Date: Wed Jan 4 16:43:51 2023 +0000

    libstdc++: Fix std::chrono::hh_mm_ss with unsigned rep [PR108265
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108265>]

    libstdc++-v3/ChangeLog:

            PR libstdc++/108265
<https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108265>
            * include/std/chrono (hh_mm_ss): Do not use chrono::abs if
            duration rep is unsigned.
            * testsuite/std/time/hh_mm_ss/1.cc: Check unsigned rep.


In response to https://gcc.gnu.org/PR108265 reported by one Michael Duggan
:-)






>
> Howard
>
> On Jun 3, 2025, at 4:24 PM, Michael Welsh Duggan via Std-Proposals <
> std-proposals_at_[hidden]> wrote:
> >
> > The text describing the constructor for chrono::hh_mm_ss defines what it
> > does partially using the chrono::abs function. However, the chrono::abs
> > function is not defined for unsigned durations. I feel as if limiting
> > construction of hh_mm_ss objects to only be from signed durations was
> > not intentional.
> >
> > Should the standard be changed to consider abs in this context to be
> > solely for exposition? Should a different wording be used? Or is
> > constructing an hh_mm_ss from an unsigned duration somehow "wrong"?
> >
> > Honestly, I think having chrono::abs being undefined for unsigned types
> > was a mistake, but that ship may have already sailed. Thoughts?
> >
> > --
> > Michael Welsh Duggan
> > (md5i_at_[hidden])
> >
> > --
> > Std-Proposals mailing list
> > Std-Proposals_at_[hidden]
> > https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-06-03 22:24:27