Skip to content

Commit fc4486c

Browse files
committed
[libc++] Implement LWG 3199
Summary: The resolution of LWG 3199 makes sure that input-streaming into an empty bitset does not set the failbit on the input stream. Reviewers: mclow.lists, EricWF Subscribers: christof, jkorous, dexonsmith, libcxx-commits Tags: #libc Differential Revision: https://reviews.llvm.org/D65105 llvm-svn: 369422
1 parent 292b108 commit fc4486c

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

libcxx/include/istream

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x)
16191619
__is.rdbuf()->sbumpc();
16201620
}
16211621
__x = bitset<_Size>(__str);
1622-
if (__c == 0)
1622+
if (_Size > 0 && __c == 0)
16231623
__state |= ios_base::failbit;
16241624
#ifndef _LIBCPP_NO_EXCEPTIONS
16251625
}

libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ int main(int, char**)
2525
in >> b;
2626
assert(b.to_ulong() == 0x5A);
2727
}
28+
{
29+
// Make sure that input-streaming an empty bitset does not cause the
30+
// failbit to be set (LWG 3199).
31+
std::istringstream in("01011010");
32+
std::bitset<0> b;
33+
in >> b;
34+
assert(b.to_string() == "");
35+
assert(!in.bad());
36+
assert(!in.fail());
37+
assert(!in.eof());
38+
assert(in.good());
39+
}
2840
#ifndef TEST_HAS_NO_EXCEPTIONS
2941
{
3042
std::stringbuf sb;

libcxx/www/upcoming_meeting.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ <h3>Library Working group Issues Status</h3>
7171
<tr><td><a href="https://wg21.link/LWG3191">3191</a></td><td>Yes</td><td><tt>std::ranges::shuffle</tt> synopsis does not match algorithm definition</td><td>Cologne</td><td></td></tr>
7272
<tr><td><a href="https://wg21.link/LWG3196">3196</a></td><td>Yes</td><td><tt>std::optional&lt;T&gt;</tt> is ill-formed is <tt>T</tt> is an array</td><td>Cologne</td><td>Complete</td></tr>
7373
<tr><td><a href="https://wg21.link/LWG3198">3198</a></td><td>Yes</td><td>Bad constraint on <tt>std::span::span()</tt></td><td>Cologne</td><td>Complete</td></tr>
74-
<tr><td><a href="https://wg21.link/LWG3199">3199</a></td><td>Yes</td><td><tt>istream &gt;&gt; bitset&lt;0&gt;</tt> fails</td><td>Cologne</td><td></td></tr>
74+
<tr><td><a href="https://wg21.link/LWG3199">3199</a></td><td>Yes</td><td><tt>istream &gt;&gt; bitset&lt;0&gt;</tt> fails</td><td>Cologne</td><td>Complete</td></tr>
7575
<tr><td><a href="https://wg21.link/LWG3202">3202</a></td><td>Yes</td><td>P0318R1 was supposed to be revised</td><td>Cologne</td><td>Complete</td></tr>
7676
<tr><td><a href="https://wg21.link/LWG3206">3206</a></td><td>Yes</td><td><tt>year_month_day</tt> conversion to <tt>sys_days</tt> uses not-existing member function</td><td>Cologne</td><td>Complete</td></tr>
7777
<tr><td><a href="https://wg21.link/LWG3208">3208</a></td><td>Yes</td><td><tt>Boolean</tt>'s expression requirements are ordered inconsistently</td><td>Cologne</td><td>Nothing to do</td></tr>
@@ -105,7 +105,6 @@ <h3>Comments about the issues</h3>
105105
<li>3191 - We don't do ranges yet</li>
106106
<li>3196 - We already do this</li>
107107
<li>3198 - We already do this</li>
108-
<li>3199 - Louis</li>
109108
<li>3202 - We already do this</li>
110109
<li>3206 - We already do this; added a couple of explicit tests</li>
111110
<li>3208 - Nothing to do; wording cleanup</li>

0 commit comments

Comments
 (0)