3997. std::formatter specializations should be consistently restricted to supported character types

Section: 28.5.1 [format.syn], 30.2 [time.syn], 32.4.3.2 [thread.thread.id] Status: New Submitter: Jiang An Opened: 2023-10-15 Last modified: 2023-11-04

Priority: 4

View other active issues in [format.syn].

View all other issues in [format.syn].

View all issues with New status.

Discussion:

28.5.6.4 [format.formatter.spec]/2 requires some std::formatter specializations are only enabled for character types char and wchar_t. But for specializations that are explicitly shown in the synopses (28.5.1 [format.syn], 30.2 [time.syn], and 32.4.3.2 [thread.thread.id]), there is no such restrictions for charT. The difference may be observable via the std::formattable concept, e.g. std::formattable<std::chrono::second, char8_t> is currently satisfied, even though there would be a hard error during formatting due to STATICALLY-WIDEN.

Perhaps we should introduce an exposition-only concept that is only satisfied (and modeled) by char and wchar_t for now, and constrain the charT template parameter of all std::formatter specializations that are explicitly mentioned in synopses with that concept. This is what libc++ currently implements (e.g. the __fmt_char_type concept and its usage in <chrono>).

[2023-11-03; Reflector poll]

Set priority to 4 after reflector poll. "Problem looks theoretical, all entry points to formatters are constrained."

Proposed resolution: