Title
Specification of vformat_to contains ill-formed formatted_size calls
Status
c++23
Section
[format.functions]
Submitter
Tim Song

Created on 2021-10-17.00:00:00 last changed 4 months ago

Messages

Date: 2022-02-10.12:58:57

Proposed resolution:

This wording is relative to N4892.

  1. Modify [format.functions] as indicated:

    template<class Out>
      Out vformat_to(Out out, string_view fmt, format_args args);
    template<class Out>
      Out vformat_to(Out out, wstring_view fmt, wformat_args args);
    template<class Out>
      Out vformat_to(Out out, const locale& loc, string_view fmt, format_args args);
    template<class Out>
      Out vformat_to(Out out, const locale& loc, wstring_view fmt, wformat_args args);
    

    -12- Let charT be decltype(fmt)::value_type.

    -13- Constraints: Out satisfies output_iterator<const charT&>.

    -14- Preconditions: Out models output_iterator<const charT&>.

    -15- Effects: Places the character representation of formatting the arguments provided by args, formatted according to the specifications given in fmt, into the range [out, out + N), where N is formatted_size(fmt, args...) for the functions without a loc parameter and formatted_size(loc, fmt, args...) for the functions with a loc parameterthe number of characters in that character representation. If present, loc is used for locale-specific formatting.

    -16- Returns: out + N.

    -17- […]

Date: 2022-02-10.00:00:00

[ 2022-02-10 Approved at February 2022 virtual plenary. Status changed: Tentatively Ready → WP. ]

Date: 2022-01-15.00:00:00

[ 2022-01-29; Reflector poll ]

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

Date: 2021-10-17.00:00:00

The specification of vformat_to says that it formats "into the range [out, out + N), where N is formatted_size(fmt, args...) for the functions without a loc parameter and formatted_size(loc, fmt, args...) for the functions with a loc parameter".

This is wrong in at least two ways:

  • First, args is a (w)format_args, not a pack, so it doesn't make sense to use ... to expand it.

  • Second, fmt is a (w)string_view parameter, and it is never a constant expression, and so the call is ill-formed after P2216 added compile-time format string checking.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-02-10 12:58:57adminsetmessages: + msg12355
2022-02-10 12:58:57adminsetstatus: ready -> wp
2022-01-29 22:29:12adminsetmessages: + msg12287
2022-01-29 22:29:12adminsetstatus: new -> ready
2021-10-17 11:39:01adminsetmessages: + msg12176
2021-10-17 00:00:00admincreate