Skip to content

Commit d62c140

Browse files
committed
New issue from Jan Kokemüller: "§[ostream.formatted.print]: Inappropriate usage of badbit in definition of vprint_unicode/vprint_nonunicode"
1 parent 27ce49f commit d62c140

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

xml/issue4039.xml

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4039" status="New">
5+
<title>&sect;[ostream.formatted.print]: Inappropriate usage of <tt>badbit</tt> in definition of
6+
<tt>vprint_unicode</tt>/<tt>vprint_nonunicode</tt></title>
7+
<section><sref ref="[ostream.formatted.print]"/></section>
8+
<submitter>Jan Kokemüller</submitter>
9+
<date>13 Jan 2024</date>
10+
<priority>99</priority>
11+
12+
<discussion>
13+
<p>
14+
In section <sref ref="[ostream.formatted.print]"/>, bullet 3.2 there is a mention of <tt>badbit</tt>:
15+
</p>
16+
<blockquote>
17+
<p>
18+
any exception thrown by the call to <tt>vformat</tt> is propagated without regard to the
19+
value of <tt>os.exceptions()</tt> and without turning on <tt>ios_base::badbit</tt> in the error state of <tt>os</tt>.
20+
</p>
21+
</blockquote>
22+
<p>
23+
Now the affected functions <tt>vprint_unicode</tt> and <tt>vprint_nonunicode</tt> are specified to behave as
24+
formatted output functions (<sref ref="[ostream.formatted.reqmts]"/>), which distinguishes two phases:
25+
</p>
26+
<ol>
27+
<li><p>Output <em>generation</em>, which would call <tt>setstate(ios_base::failbit)</tt> in case of a failure
28+
(which may throw an exception)</p></li>
29+
<li><p>The actual output itself, which would call <tt>setstate(ios_base::badbit)</tt> in case of an exception</p></li>
30+
</ol>
31+
<p>
32+
The <tt>vformat</tt> call is obviously part of the first phase (since it generates the output sequence and not
33+
yet the actual output), and any failure here (such as an exception) would under regular formatted output function
34+
rules set <tt>ios_base::failbit</tt> and <em>not</em> <tt>ios_base::badbit</tt> (the latter would indicate a loss
35+
of the actual output sequence integrity and is therefore set by the second phase in case of an exception).
36+
<p/>
37+
Therefore mentioning <tt>ios_base::badbit</tt> in (3.2) doesn't really make sense, it could only meaningfully
38+
refer to <tt>ios_base::failbit</tt> instead.
39+
</p>
40+
</discussion>
41+
42+
<resolution>
43+
<p>
44+
This wording is relative to <paper num="N4971"/>.
45+
</p>
46+
47+
<ol>
48+
<li><p>Modify <sref ref="[ostream.formatted.print]"/> as indicated:</p>
49+
50+
<blockquote>
51+
<pre>
52+
void vprint_unicode(ostream&amp; os, string_view fmt, format_args args);
53+
void vprint_nonunicode(ostream&amp; os, string_view fmt, format_args args);
54+
</pre>
55+
<blockquote>
56+
<p>
57+
-3- <i>Effects</i>: Behaves as a formatted output function (<sref ref="[ostream.formatted.reqmts]"/>)
58+
of <tt>os</tt>, except that:
59+
</p>
60+
<ol style="list-style-type: none">
61+
<li><p>(3.1) &mdash; failure to generate output is reported as specified below, and</p></li>
62+
<li><p>(3.2) &mdash; any exception thrown by the call to <tt>vformat</tt> is propagated without regard
63+
to the value of <tt>os.exceptions()</tt> and without turning on <tt>ios_base::<ins>failbit</ins><del>badbit</del></tt>
64+
in the error state of <tt>os</tt>.</p></li>
65+
</ol>
66+
<p>
67+
[&hellip;]
68+
</p>
69+
</blockquote>
70+
</blockquote>
71+
</li>
72+
</ol>
73+
</resolution>
74+
75+
</issue>

0 commit comments

Comments
 (0)