|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4284" status="New"> |
| 5 | +<title>Integer-class types should be formattable</title> |
| 6 | +<section> |
| 7 | +<sref ref="[format.formatter.spec]"/> |
| 8 | +</section> |
| 9 | +<submitter>Jiang An</submitter> |
| 10 | +<date>27 Jun 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +The following program doesn't compile with MSVC STL (<a href="https://godbolt.org/z/aazK6bhqM">Godbolt link</a>). |
| 16 | +</p> |
| 17 | +<blockquote><pre> |
| 18 | +#include <format> |
| 19 | +#include <ranges> |
| 20 | + |
| 21 | +int main() { |
| 22 | + auto iv1 = std::views::iota(42ull, 1729ull); |
| 23 | + auto iv2 = std::views::iota(iv1.begin(), iv1.end()); |
| 24 | + std::format("{}", iv2.size()); // <span style="color:red;font-weight:bolder">Error</span> |
| 25 | +} |
| 26 | +</pre></blockquote> |
| 27 | +<p> |
| 28 | +In MSVC STL, the type of `iv2.size()` is an integer-class type, and the standard hasn't guaranteed there're |
| 29 | +enabled formatter specializations for integer-class types. As a result, this program is not guaranteed to |
| 30 | +be well-formed. |
| 31 | +<p/> |
| 32 | +Perhaps we should require enabled `std::formatter` specializations for integer-class types to get rid of |
| 33 | +such uncertainty and inconsistency. |
| 34 | +</p> |
| 35 | +</discussion> |
| 36 | + |
| 37 | +<resolution> |
| 38 | +<p> |
| 39 | +This wording is relative to <paper num="N5008"/>. |
| 40 | +</p> |
| 41 | + |
| 42 | +<ol> |
| 43 | +<li><p>Modify <sref ref="[format.formatter.spec]"/> as indicated:</p> |
| 44 | + |
| 45 | +<blockquote> |
| 46 | +<p> |
| 47 | +-2- […] Each header that declares the template |
| 48 | +`formatter` provides the following enabled specializations: |
| 49 | +</p> |
| 50 | +<ol style="list-style-type: none"> |
| 51 | +<li><p>(2.1) — […]</p></li> |
| 52 | +<li><p>(2.2) — […]</p></li> |
| 53 | +<li><p>(2.3) — […]</p></li> |
| 54 | +<li><p><ins>(2.?) — For each `charT`, for each cv-unqualified integer-class type |
| 55 | +(<sref ref="[iterator.concept.winc]"/>) `IntegerClass`, a specialization</ins> |
| 56 | +</p> |
| 57 | +<blockquote><pre> |
| 58 | +<ins>template<> struct formatter<IntegerClass, charT>;</ins> |
| 59 | +</pre></blockquote> |
| 60 | +</li> |
| 61 | +<li><p>(2.4) — […]</p></li> |
| 62 | +</ol> |
| 63 | +</blockquote> |
| 64 | +</li> |
| 65 | + |
| 66 | +</ol> |
| 67 | +</resolution> |
| 68 | + |
| 69 | +</issue> |
0 commit comments