C++ Logo

std-proposals

Advanced search

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

From: Howard Hinnant <howard.hinnant_at_[hidden]>
Date: Tue, 3 Jun 2025 16:57:57 -0400
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.

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

Received on 2025-06-03 20:58:34