Title
Integer-class types should be formattable
Status
new
Section
[format.formatter.spec]
Submitter
Jiang An

Created on 2025-06-27.00:00:00 last changed 5 days ago

Messages

Date: 2025-06-28.17:27:39

Proposed resolution:

This wording is relative to N5008.

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

    -2- […] Each header that declares the template `formatter` provides the following enabled specializations:

    1. (2.1) — […]

    2. (2.2) — […]

    3. (2.3) — […]

    4. (2.?) — For each `charT`, for each cv-unqualified integer-class type ([iterator.concept.winc]) `IntegerClass`, a specialization

      template<> struct formatter<IntegerClass, charT>;
      
    5. (2.4) — […]

Date: 2025-06-27.00:00:00

The following program doesn't compile with MSVC STL (Godbolt link).

#include <format>
#include <ranges>

int main() {
  auto iv1 = std::views::iota(42ull, 1729ull);
  auto iv2 = std::views::iota(iv1.begin(), iv1.end());
  std::format("{}", iv2.size()); // Error
}

In MSVC STL, the type of `iv2.size()` is an integer-class type, and the standard hasn't guaranteed there're enabled formatter specializations for integer-class types. As a result, this program is not guaranteed to be well-formed.

Perhaps we should require enabled `std::formatter` specializations for integer-class types to get rid of such uncertainty and inconsistency.

History
Date User Action Args
2025-06-28 17:27:39adminsetmessages: + msg14873
2025-06-27 00:00:00admincreate