This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++23 status.

3842. Unclear wording for precision in chrono-format-spec

Section: 29.12 [time.format] Status: C++23 Submitter: Jonathan Wakely Opened: 2022-12-14 Last modified: 2024-01-29

Priority: Not Prioritized

View other active issues in [time.format].

View all other issues in [time.format].

View all issues with C++23 status.

Discussion:

29.12 [time.format] says:

[…] Giving a precision specification in the chrono-format-spec is valid only for std::chrono::duration types where the representation type Rep is a floating-point type. For all other Rep types, an exception of type format_error is thrown if the chrono-format-spec contains a precision specification. […]

It's unclear whether the restriction in the first sentence applies to all types, or only duration types. The second sentence seems to restrict the exceptional case to only types with a non-floating-point Rep, but what about types with no Rep type at all?

Can you use a precision with sys_time<duration<float>>? That is not a duration type at all, so does the restriction apply? What about hh_mm_ss<duration<int>>? That's not a duration type, but it uses one, and its Rep is not a floating-point type. What about sys_info? That's not a duration and doesn't have any associated duration, or Rep type.

What is the intention here?

Less importantly, I don't like the use of Rep here. That's the template parameter of the duration class template, but that name isn't in scope here. Why aren't we talking about the duration type's rep type, which is the public name for it? Or about a concrete specialization duration<Rep, Period>, instead of the class template?

The suggested change below would preserve the intended meaning, but with more … precision.

[2023-01-06; Reflector poll]

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

[2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Voting → WP.]

Proposed resolution:

This wording is relative to N4917.

  1. Modify 29.12 [time.format] as indicated:

    -1- […]

    The productions fill-and-align, width, and precision are described in 22.14.2 [format.string]. Giving a precision specification in the chrono-format-spec is valid only for types that are specializations of std::chrono::duration types where the representation type Rep isfor which the nested typedef-name rep denotes a floating-point type. For all other Rep types, an exception of type format_error is thrown if the chrono-format-spec contains a precision specification. […]