Issue 4274: The chrono::hh_mm_ss constructor is ill-formed for unsigned durations (original) (raw)
This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.
4274. The chrono::hh_mm_ss constructor is ill-formed for unsigned durations
Section: 30.9.2 [time.hms.members] Status: WP Submitter: Michael Welsh Duggan Opened: 2025-06-04 Last modified: 2025-11-11
Priority: Not Prioritized
View all issues with WP status.
Discussion:
In 30.9.2 [time.hms.members], paragraph 3, the current wording for the constructor of hh_mm_ss expresses some of its requirements in terms ofabs(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_ssobjects 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.
[2025-06-13; Reflector poll]
Set status to Tentatively Ready after five votes in favour during reflector poll.
[Kona 2025-11-08; Status changed: Voting → WP.]
Proposed resolution:
This wording is relative to N5008.
- Modify 30.9.2 [time.hms.members] as indicated:
constexpr explicit hh_mm_ss(Duration d);
-3- Effects: Constructs an object of type
hh_mm_sswhich represents theDuration dwith precisionprecision.- (3.1) — Initializes
is_negwithd < Duration::zero(). Let_ABSD_represent-difis_negistrueanddotherwise. - (3.2) — Initializes
hwithduration_cast<chrono::hours>(~~abs(d)~~_ABSD_). - (3.3) — Initializes
mwithduration_cast<chrono::minutes>(~~abs(d)~~_ABSD_ - hours()). - (3.4) — Initializes
swithduration_cast<chrono::seconds>(~~abs(d)~~_ABSD_ - hours() - minutes()). - (3.5) — If
treat_as_floating_point_v<precision::rep>istrue, initializessswith~~abs(d)~~_ABSD_ - hours() - minutes() - seconds(). Otherwise, initializessswithduration_cast<precision>(~~abs(d)~~_ABSD_ - hours() - minutes() - seconds()).
- (3.1) — Initializes