Skip to content

Commit e31d943

Browse files
committed
New issue from Casey: "§[format.formatter.spec]/3 unconditionally enables nonlocking for container adaptors"
1 parent dac1b88 commit e31d943

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

xml/issue4146.xml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4146" status="New">
5+
<title>&sect;[format.formatter.spec]/3 unconditionally enables nonlocking for container adaptors</title>
6+
<section><sref ref="[format.formatter.spec]"/><sref ref="[container.adaptors.format]"/></section>
7+
<submitter>Casey Carter</submitter>
8+
<date>31 Aug 2024</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
<sref ref="[format.formatter.spec]"/>/3 says that the library provides a specialization of
14+
`enable_nonlocking_formatter_optimization` with value `true` corresponding to each library-provided
15+
specialization of `formatter`, unless otherwise specified. Although it actually states
16+
"for each type `T`", the intent is that partial specializations are also provided corresponding to
17+
library-provided partial specializations of formatter.
18+
<p/>
19+
<sref ref="[container.adaptors.format]"/>/1 says the library provides a partial specialization of
20+
`formatter` for each of the container adaptor templates `priority_queue`, `queue`, and `stack`.
21+
Together with <sref ref="[format.formatter.spec]"/>/3, that means that e.g.
22+
<tt>enable_nonlocking_formatter_optimization&lt;stack&lt;T&gt;&gt; == true</tt>. Formatting a stack of
23+
that type will enable the nonlocking optimization even if
24+
<tt>enable_nonlocking_formatter_optimization&lt;T&gt; == false</tt>. To avoid this, the author of `T`
25+
must partially specialize `enable_nonlocking_formatter_optimization` to `false` for all container
26+
adaptors when they adapt a container of `T`.
27+
<p/>
28+
It is clearly not the design intent that programmers must explicitly opt out of the nonlocking
29+
optimization, so this is a defect that LWG should correct. Since <paper num="P3235R3"/> was applied
30+
as a Defect Report to C++23, the resolution of this issue should be so applied as well.
31+
<p/>
32+
<b>Suggested Resolution:</b>
33+
<p/>
34+
LEWG was reticent to apply the optimization to general ranges &mdash; ostensibly due to the possibility
35+
of deadlock in program-defined iterator operations &mdash; but apparently unconcerned about the iterators
36+
of program-defined containers nor the fancy pointers of program-defined allocators. It seems consistent
37+
with that design to ignore the "container" part of "container adaptors" and only pay attention to the
38+
elements that are going to be formatted. (I have prototyped this resolution on MSVCSTL, albeit slightly
39+
modified since neither MSVC nor Clang like this partial specialization form.)
40+
</p>
41+
</discussion>
42+
43+
<resolution>
44+
<p>
45+
This wording is relative to <paper num="N4988"/>.
46+
</p>
47+
48+
<ol>
49+
<li><p>Modify <sref ref="[container.adaptors.format]"/> as indicated:</p>
50+
51+
<blockquote>
52+
<p>
53+
-1- For each of <tt>queue</tt>, <tt>priority_queue</tt>, and <tt>stack</tt>, the library provides the
54+
following <del>formatter</del> specialization<ins>s</ins> where <tt><i>adaptor-type</i></tt> is the
55+
name of the template:
56+
</p>
57+
<blockquote><pre>
58+
namespace std {
59+
template&lt;class charT, class T, formattable&lt;charT&gt; Container, class... U&gt;
60+
struct formatter&lt;<i>adaptor-type</i>&lt;T, Container, U...&gt;, charT&gt; {
61+
[&hellip;]
62+
};
63+
64+
<ins>template&lt;class T, class Container, class... U&gt;</ins>
65+
<ins>constexpr bool enable_nonlocking_formatter_optimization&lt;<i>adaptor-type</i>&lt;T, Container, U...&gt;&gt; =</ins>
66+
<ins>enable_nonlocking_formatter_optimization&lt;T&gt;;</ins>
67+
}
68+
</pre></blockquote>
69+
</blockquote>
70+
</li>
71+
72+
</ol>
73+
74+
</resolution>
75+
76+
</issue>

0 commit comments

Comments
 (0)