Skip to content

Commit e4d8729

Browse files
author
github-actions
committed
Automatic update from GitHub Actions workflow
1 parent f39d71c commit e4d8729

25 files changed

+644
-47
lines changed

issue3806.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ <h3 id="3806"><a href="lwg-closed.html#3806">3806</a>. Should concept <code>form
6767
<b>Submitter:</b> Jonathan Wakely <b>Opened:</b> 2022-10-28 <b>Last modified:</b> 2023-01-24</p>
6868
<p><b>Priority: </b>2
6969
</p>
70+
<p><b>View other</b> <a href="lwg-index-open.html#format.formattable">active issues</a> in [format.formattable].</p>
7071
<p><b>View all other</b> <a href="lwg-index.html#format.formattable">issues</a> in [format.formattable].</p>
7172
<p><b>View all issues with</b> <a href="lwg-status.html#NAD">NAD</a> status.</p>
7273
<p><b>Discussion:</b></p>

issue3925.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ <h3 id="3925"><a href="lwg-defects.html#3925">3925</a>. Concept <code>formattabl
6767
<b>Submitter:</b> Mark de Wever <b>Opened:</b> 2023-04-16 <b>Last modified:</b> 2023-11-22</p>
6868
<p><b>Priority: </b>Not Prioritized
6969
</p>
70+
<p><b>View other</b> <a href="lwg-index-open.html#format.formattable">active issues</a> in [format.formattable].</p>
7071
<p><b>View all other</b> <a href="lwg-index.html#format.formattable">issues</a> in [format.formattable].</p>
7172
<p><b>View all issues with</b> <a href="lwg-status.html#WP">WP</a> status.</p>
7273
<p><b>Discussion:</b></p>

issue3943.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ <h3 id="3943"><a href="lwg-active.html#3943">3943</a>. Clarify lifetime requirem
6767
<b>Submitter:</b> Mark de Wever <b>Opened:</b> 2023-06-01 <b>Last modified:</b> 2023-06-08</p>
6868
<p><b>Priority: </b>3
6969
</p>
70+
<p><b>View other</b> <a href="lwg-index-open.html#format.formattable">active issues</a> in [format.formattable].</p>
7071
<p><b>View all other</b> <a href="lwg-index.html#format.formattable">issues</a> in [format.formattable].</p>
7172
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
7273
<p><b>Discussion:</b></p>

issue4240.html

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Issue 4240: The formattable type is not a formattable type</title>
6+
<meta property="og:title" content="Issue 4240: The formattable type is not a formattable type">
7+
<meta property="og:description" content="C++ library issue. Status: New">
8+
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue4240.html">
9+
<meta property="og:type" content="website">
10+
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
11+
<meta property="og:image:alt" content="C++ logo">
12+
<style>
13+
p {text-align:justify}
14+
li {text-align:justify}
15+
pre code.backtick::before { content: "`" }
16+
pre code.backtick::after { content: "`" }
17+
blockquote.note
18+
{
19+
background-color:#E0E0E0;
20+
padding-left: 15px;
21+
padding-right: 15px;
22+
padding-top: 1px;
23+
padding-bottom: 1px;
24+
}
25+
ins {background-color:#A0FFA0}
26+
del {background-color:#FFA0A0}
27+
table.issues-index { border: 1px solid; border-collapse: collapse; }
28+
table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
29+
table.issues-index td { padding: 4px; border: 1px solid; }
30+
table.issues-index td:nth-child(1) { text-align: right; }
31+
table.issues-index td:nth-child(2) { text-align: left; }
32+
table.issues-index td:nth-child(3) { text-align: left; }
33+
table.issues-index td:nth-child(4) { text-align: left; }
34+
table.issues-index td:nth-child(5) { text-align: center; }
35+
table.issues-index td:nth-child(6) { text-align: center; }
36+
table.issues-index td:nth-child(7) { text-align: left; }
37+
table.issues-index td:nth-child(5) span.no-pr { color: red; }
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color: #ddd;
41+
background-color: black;
42+
}
43+
ins {
44+
background-color: #225522
45+
}
46+
del {
47+
background-color: #662222
48+
}
49+
a {
50+
color: #6af
51+
}
52+
a:visited {
53+
color: #6af
54+
}
55+
blockquote.note
56+
{
57+
background-color: rgba(255, 255, 255, .10)
58+
}
59+
}
60+
</style>
61+
</head>
62+
<body>
63+
<hr>
64+
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#New">New</a> status.</em></p>
65+
<h3 id="4240"><a href="lwg-active.html#4240">4240</a>. The formattable type is not a <code>formattable</code> type</h3>
66+
<p><b>Section:</b> 28.5.6.3 <a href="https://wg21.link/format.formattable">[format.formattable]</a> <b>Status:</b> <a href="lwg-active.html#New">New</a>
67+
<b>Submitter:</b> Hewill Kang <b>Opened:</b> 2025-04-06 <b>Last modified:</b> 2025-04-06</p>
68+
<p><b>Priority: </b>Not Prioritized
69+
</p>
70+
<p><b>View other</b> <a href="lwg-index-open.html#format.formattable">active issues</a> in [format.formattable].</p>
71+
<p><b>View all other</b> <a href="lwg-index.html#format.formattable">issues</a> in [format.formattable].</p>
72+
<p><b>View all issues with</b> <a href="lwg-status.html#New">New</a> status.</p>
73+
<p><b>Discussion:</b></p>
74+
<p>
75+
User-specific <code>formatter</code>s usually have the following form:
76+
</p>
77+
<blockquote><pre>
78+
template &lt;&gt; struct std::formatter&lt;T&gt; {
79+
constexpr auto parse(format_parse_context&amp; ctx)
80+
-> format_parse_context::iterator;
81+
82+
auto format(const T&amp; value, format_context&amp; ctx) const
83+
-> format_context::iterator;
84+
};
85+
</pre></blockquote>
86+
<p>
87+
This is reflected in wording examples such as 28.5.6.4 <a href="https://wg21.link/format.formatter.spec">[format.formatter.spec]</a> bullet 8 or
88+
28.5.6.7 <a href="https://wg21.link/format.context">[format.context]</a> bullet 9:
89+
</p>
90+
<blockquote><pre>
91+
#include &lt;format&gt;
92+
#include &lt;string&gt;
93+
94+
enum color { red, green, blue };
95+
const char* color_names[] = { "red", "green", "blue" };
96+
97+
template&lt;&gt; struct std::formatter&lt;color&gt; : std::formatter&lt;const char*&gt; {
98+
auto format(color c, format_context&amp; ctx) const {
99+
return formatter&lt;const char*&gt;::format(color_names[c], ctx);
100+
}
101+
};
102+
</pre></blockquote>
103+
<p>
104+
which allows us to format <code>color</code> with <code>std::format("{}", red)</code>.
105+
Unfortunately, even so, the <code>color</code> still does not satisfy <code>std::formattable</code>.
106+
<p/>
107+
This is because the concept <code>formattable</code> is currently defined as follows:
108+
</p>
109+
<blockquote><pre>
110+
template&lt;class T, class Context,
111+
class Formatter = typename Context::template formatter_type&lt;remove_const_t&lt;T&gt;&gt;&gt;
112+
concept <i>formattable-with</i> = // <i>exposition only</i>
113+
semiregular&lt;Formatter&gt; &amp;&amp;
114+
requires(Formatter&amp; f, const Formatter&amp; cf, T&amp;&amp; t, Context fc,
115+
basic_format_parse_context&lt;typename Context::char_type&gt; pc)
116+
{
117+
{ f.parse(pc) } -> same_as&lt;typename decltype(pc)::iterator&gt;;
118+
{ cf.format(t, fc) } -> same_as&lt;typename Context::iterator&gt;;
119+
};
120+
121+
template&lt;class T, class charT&gt;
122+
concept formattable =
123+
<i>formattable-with</i>&lt;remove_reference_t&lt;T&gt;, basic_format_context&lt;<i>fmt-iter-for</i>&lt;charT&gt;, charT&gt;&gt;;
124+
</pre></blockquote>
125+
<p>
126+
where <code><i>fmt-iter-for</i>&lt;charT&gt;</code> is an unspecified type that can write
127+
<code>charT</code>, which for <code>char</code> is <code>back_insert_iterator&lt;string&gt;</code>
128+
and <code>char*</code> in libstdc++ and libc++, respectively.
129+
</p>
130+
<p>
131+
That is, for <code>color</code> to satisfy <code>formattable</code>, it is
132+
necessary to ensure that <code>cf.format(t, fc)</code> is well-formed.
133+
</p>
134+
<p>
135+
However, the <code>format()</code> function in the above example takes a <code>format_context</code>
136+
whose <code>Out</code> parameter is internal iterator type, namely
137+
<code>_Sink_iter&lt;char&gt;</code> and <code>__format::__output_buffer&lt;char&gt;</code> in
138+
libstdc++ and libc++, respectively.
139+
Since <code>basic_format_context</code> with different <code>Out</code> parameters cannot be converted to
140+
each other, the constraint is not satisfied.
141+
</p>
142+
<p>
143+
The reason <code>color</code> can still be formatted is that <code>basic_format_arg</code>
144+
checks for <code><i>formattable-with</i>&lt;Context&gt;</code> where <code>Context</code>
145+
has been correctly specified as <code>format_context</code>.
146+
</p>
147+
<p>
148+
And since <code>color</code> is formattable but not <code>formattable</code>, this further
149+
prevents formatting a range with elements of <code>color</code>, because the <code>formatter</code>
150+
specialization for ranges requires that the element type must be <code>formattable</code>.
151+
This leads to some inconsistencies (<a href="https://godbolt.org/z/Y8a6WTrK1">demo</a>):
152+
</p>
153+
<blockquote><pre>
154+
std::println("{}", red); // ok
155+
static_assert(std::formattable&lt;color, char&gt;); // <span style="color:#C80000;font-weight:bold">fires</span>
156+
157+
std::vector&lt;color&gt; v;
158+
std::println("{}", v); // <span style="color:#C80000;font-weight:bold">not ok</span>
159+
</pre></blockquote>
160+
<p>
161+
The workaround is to turn the custom <code>format()</code> into a template function
162+
such as <code>format(color c, auto&amp; ctx)</code> or
163+
<code>format(color c, basic_format_context&lt;Out, charT&gt;&amp; ctx)</code>,
164+
However, this seems mandate users to always declare <code>format()</code> as the template
165+
function for the best practice, which in my opinion defeats the purpose of introducing
166+
<code>format_context</code> in the first place.
167+
</p>
168+
<p>
169+
Also, since <code><i>fmt-iter-for</i>&lt;charT&gt;</code> is unspecified, if it is specified
170+
in some library implementation as the same type as <code>format_context</code>'s <code>Out</code>
171+
parameters, then <code>color</code> will suddenly become <code>formattable</code>. This lack
172+
of guarantee about <code>formattable</code> can bring unnecessary confusion.
173+
</p>
174+
<p>
175+
I think we should ensure that <code>color</code> is <code>formattable</code>, because it is formattable.
176+
</p>
177+
178+
179+
<p id="res-4240"><b>Proposed resolution:</b></p>
180+
<p>
181+
This wording is relative to <a href="https://wg21.link/N5008">N5008</a>.
182+
</p>
183+
184+
<ol>
185+
186+
<li><p>Modify 28.5.6.3 <a href="https://wg21.link/format.formattable">[format.formattable]</a> as indicated:</p>
187+
188+
<blockquote>
189+
<p>
190+
-1- <del>Let <code><i>fmt-iter-for</i>&lt;charT&gt;</code> be an unspecified type that models
191+
<code>output_iterator&lt;const charT&amp;&gt;</code> (24.3.4.10 <a href="https://wg21.link/iterator.concept.output">[iterator.concept.output]</a>)</del>.
192+
</p>
193+
<blockquote><pre>
194+
[&hellip;]
195+
template&lt;class T, class charT&gt;
196+
concept formattable =
197+
<i>formattable-with</i>&lt;remove_reference_t&lt;T&gt;, <ins>conditional_t&lt;same_as&lt;charT, char&gt;, format_context, wformat_context&gt;</ins><del>basic_format_context&lt;<i>fmt-iter-for</i>&lt;charT&gt;, charT&gt;</del>&gt;;
198+
</pre></blockquote>
199+
</blockquote>
200+
201+
</li>
202+
203+
</ol>
204+
205+
206+
207+
208+
209+
</body>
210+
</html>

0 commit comments

Comments
 (0)