From fc4486c2472b84384d4a31d2436a91bdb9b29792 Mon Sep 17 00:00:00 2001 From: Louis Dionne Date: Tue, 20 Aug 2019 18:21:06 +0000 Subject: [PATCH] [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 --- libcxx/include/istream | 2 +- .../template.bitset/bitset.operators/stream_in.pass.cpp | 12 ++++++++++++ libcxx/www/upcoming_meeting.html | 3 +-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/libcxx/include/istream b/libcxx/include/istream index d6217bb..bfbe5f2 100644 --- a/libcxx/include/istream +++ b/libcxx/include/istream @@ -1619,7 +1619,7 @@ operator>>(basic_istream<_CharT, _Traits>& __is, bitset<_Size>& __x) __is.rdbuf()->sbumpc(); } __x = bitset<_Size>(__str); - if (__c == 0) + if (_Size > 0 && __c == 0) __state |= ios_base::failbit; #ifndef _LIBCPP_NO_EXCEPTIONS } diff --git a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp index 1cb92ea..0127b75 100644 --- a/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp +++ b/libcxx/test/std/utilities/template.bitset/bitset.operators/stream_in.pass.cpp @@ -25,6 +25,18 @@ int main(int, char**) in >> b; assert(b.to_ulong() == 0x5A); } + { + // Make sure that input-streaming an empty bitset does not cause the + // failbit to be set (LWG 3199). + std::istringstream in("01011010"); + std::bitset<0> b; + in >> b; + assert(b.to_string() == ""); + assert(!in.bad()); + assert(!in.fail()); + assert(!in.eof()); + assert(in.good()); + } #ifndef TEST_HAS_NO_EXCEPTIONS { std::stringbuf sb; diff --git a/libcxx/www/upcoming_meeting.html b/libcxx/www/upcoming_meeting.html index 4989f5a..29b5174 100644 --- a/libcxx/www/upcoming_meeting.html +++ b/libcxx/www/upcoming_meeting.html @@ -71,7 +71,7 @@ 3191Yesstd::ranges::shuffle synopsis does not match algorithm definitionCologne 3196Yesstd::optional<T> is ill-formed is T is an arrayCologneComplete 3198YesBad constraint on std::span::span()CologneComplete -3199Yesistream >> bitset<0> failsCologne +3199Yesistream >> bitset<0> failsCologneComplete 3202YesP0318R1 was supposed to be revisedCologneComplete 3206Yesyear_month_day conversion to sys_days uses not-existing member functionCologneComplete 3208YesBoolean's expression requirements are ordered inconsistentlyCologneNothing to do @@ -105,7 +105,6 @@
  • 3191 - We don't do ranges yet
  • 3196 - We already do this
  • 3198 - We already do this
  • -
  • 3199 - Louis
  • 3202 - We already do this
  • 3206 - We already do this; added a couple of explicit tests
  • 3208 - Nothing to do; wording cleanup
  • -- 2.7.4