Title
Make formatter<remove_cvref_t<const charT[N]>, charT> requirement explicit
Status
c++23
Section
[format.formatter.spec]
Submitter
Mark de Wever

Created on 2022-05-17.00:00:00 last changed 12 months ago

Messages

Date: 2022-07-25.20:32:58

Proposed resolution:

This wording is relative to N4910.

  1. Modify [format.formatter.spec] as indicated:

    -2- Let charT be either char or wchar_t. Each specialization of formatter is either enabled or disabled, as described below. Each header that declares the template formatter provides the following enabled specializations:

    1. (2.1) — The specializations […]

    2. (2.2) — For each charT, the string type specializations

      template<> struct formatter<charT*, charT>;
      template<> struct formatter<const charT*, charT>;
      template<size_t N> struct formatter<charT[N], charT>;
      template<size_t N> struct formatter<const charT[N], charT>;
      template<class traits, class Allocator>
        struct formatter<basic_string<charT, traits, Allocator>, charT>;
      template<class traits>
        struct formatter<basic_string_view<charT, traits>, charT>;
      
    3. (2.3) — […]

    4. (2.4) — […]

Date: 2022-07-25.00:00:00

[ 2022-07-25 Approved at July 2022 virtual plenary. Status changed: Ready → WP. ]

Date: 2022-07-15.00:00:00

[ 2022-07-15; LWG telecon: move to Ready ]

Date: 2022-06-15.00:00:00

[ 2022-06-21; Reflector poll ]

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

Date: 2022-05-17.00:00:00

The wording in [format.functions]/20 and [format.functions]/25 both contain

formatter<remove_cvref_t<Ti>, charT> meets the BasicFormatter requirements ([formatter.requirements]) for each Ti in Args.

The issue is that remove_cvref_t<const charT[N]> becomes charT[N]. [format.formatter.spec]/2.2 requires a specialization for

template<size_t N> struct formatter<const charT[N], charT>;

but there's no requirement to provide

 template<size_t N> struct formatter<charT[N], charT>;

There's no wording preventing library vendors from providing additional specializations. So it's possible to implement the current specification but the indirect requirement is odd. I noticed this while implementing a formattable concept. The concept is based on the formattable concept of P2286 "Formatting Ranges" (This paper is targeting C++23.)

It could be argued that the specialization

template<size_t N> struct formatter<const charT[N], charT>

is not needed and should be removed from the Standard. This will be an API break. Vendors can decide to keep the no longer required specialization as an extension; which would lead to implementation divergence. Microsoft is already shipping this specialization as stable and Victor doesn't like the removal too.

Therefore I only propose to add the required formatter specialization.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2022-07-25 20:32:58adminsetmessages: + msg12643
2022-07-25 20:32:58adminsetstatus: ready -> wp
2022-07-25 20:28:19adminsetmessages: + msg12617
2022-06-21 11:47:28adminsetmessages: + msg12514
2022-06-21 11:47:28adminsetstatus: new -> ready
2022-05-21 12:26:11adminsetmessages: + msg12474
2022-05-17 00:00:00admincreate