Title
The `chrono::hh_mm_ss` constructor is ill-formed for unsigned durations
Status
ready
Section
[time.hms.members]
Submitter
Michael Welsh Duggan

Created on 2025-06-04.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-06-13.09:08:09

Proposed resolution:

This wording is relative to N5008.

  1. Modify [time.hms.members] as indicated:

    constexpr explicit hh_mm_ss(Duration d);
    

    -3- Effects: Constructs an object of type `hh_mm_ss` which represents the `Duration d` with precision `precision`.

    1. (3.1) — Initializes `is_neg` with d < Duration::zero(). Let ABS_D represent `-d` if `is_neg` is `true` and `d` otherwise.

    2. (3.2) — Initializes `h` with duration_cast<chrono::hours>(abs(d)ABS_D).

    3. (3.3) — Initializes `m` with duration_cast<chrono::minutes>(abs(d)ABS_D - hours()).

    4. (3.4) — Initializes `s` with duration_cast<chrono::seconds>(abs(d)ABS_D - hours() - minutes()).

    5. (3.5) — If treat_as_floating_point_v<precision::rep> is `true`, initializes `ss` with abs(d)ABS_D - hours() - minutes() - seconds(). Otherwise, initializes `ss` with duration_cast<precision>(abs(d)ABS_D - hours() - minutes() - seconds()).

Date: 2025-06-15.00:00:00

[ 2025-06-13; Reflector poll ]

Set status to Tentatively Ready after five votes in favour during reflector poll.

Date: 2025-06-04.00:00:00

In [time.hms.members], paragraph 3, the current wording for the constructor of `hh_mm_ss` expresses some of its requirements in terms of `abs(d)`, which is assumed to be `chrono::abs(chrono::duration)`. `chrono::abs` is not defined, however, for durations with an unsigned representation. I believe that not being able to create `hh_mm_ss` objects from unsigned durations is unintentional.

Moreover, is_constructible_v<hh_mm_ss<ud>, ud> is required to be true by the standard for any duration, so making it actually work makes a lot of sense.

History
Date User Action Args
2025-06-13 09:08:09adminsetmessages: + msg14810
2025-06-13 09:08:09adminsetstatus: new -> ready
2025-06-07 12:58:37adminsetmessages: + msg14783
2025-06-04 00:00:00admincreate