From 2741e62f5f9fefbffda50d11d73c7e8d151a13d8 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 14 Dec 2021 21:24:30 +0700 Subject: [PATCH 01/13] flush_emit set badbit if the emit call fails --- stl/inc/ostream | 5 ++++- .../test.cpp | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 23049b5d15..670c6523ce 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1041,7 +1041,10 @@ basic_ostream<_Elem, _Traits>& flush_emit(basic_ostream<_Elem, _Traits>& _Ostr) _Ostr.flush(); const auto _Sync_buf_ptr = dynamic_cast<_Basic_syncbuf_impl<_Elem, _Traits>*>(_Ostr.rdbuf()); if (_Sync_buf_ptr) { - _Sync_buf_ptr->_Do_emit(); + const bool _Emit_failed = !_Sync_buf_ptr->_Do_emit(); + if (_Emit_failed) { + _Ostr.setstate(ios_base::badbit); + } } return _Ostr; } diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index f58fde5239..824bd6295d 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -35,7 +35,8 @@ class string_buffer : public basic_streambuf> { // represent template -void test_osyncstream_manipulators(string_buffer* buf = nullptr) { +void test_osyncstream_manipulators( + string_buffer* buf = nullptr, bool buffer_can_sync = true) { using char_type = typename Ty::char_type; using traits_type = typename Ty::traits_type; @@ -77,7 +78,8 @@ void test_osyncstream_manipulators(string_buffer, Ty>) { - assert(os.rdstate() == ios::goodbit); + auto bit = (buf && buffer_can_sync) ? ios::goodbit : ios::badbit; + assert(os.rdstate() == bit); if (buf) { assert(buf->str == "Another input"); } @@ -89,6 +91,12 @@ void test_osyncstream_manipulators(string_buffer stream(nullptr); + stream << flush_emit; + assert(stream.rdstate() == ios::badbit); +} + int main() { string_buffer char_buffer{}; string_buffer no_sync_char_buffer{}; @@ -102,5 +110,7 @@ int main() { test_osyncstream_manipulators>(&no_sync_char_buffer); test_osyncstream_manipulators, allocator>, allocator>( - &no_sync_char_buffer); + &no_sync_char_buffer, false); + + test_lwg_3571(); } From a6596d58f88ae97cdd0028ec56c0fa4362e573de Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 14 Dec 2021 21:56:54 +0700 Subject: [PATCH 02/13] better name for output stream state Co-authored-by: Michael Schellenberger Costa --- .../test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index 824bd6295d..7f0340d41f 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -78,8 +78,8 @@ void test_osyncstream_manipulators( assert(addressof(flush_emit(os)) == addressof(os)); if constexpr (is_base_of_v, Ty>) { - auto bit = (buf && buffer_can_sync) ? ios::goodbit : ios::badbit; - assert(os.rdstate() == bit); + const auto state = (buf && buffer_can_sync) ? ios::goodbit : ios::badbit; + assert(os.rdstate() == state); if (buf) { assert(buf->str == "Another input"); } From 1dbdcdcbaa9fdf3906fc9f515b859ce743a96d3a Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 15 Dec 2021 13:25:49 +0700 Subject: [PATCH 03/13] construct a sentry object --- stl/inc/ostream | 1 + stl/inc/syncstream | 1 + 2 files changed, 2 insertions(+) diff --git a/stl/inc/ostream b/stl/inc/ostream index 670c6523ce..c53d0a33de 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1038,6 +1038,7 @@ basic_ostream<_Elem, _Traits>& noemit_on_flush(basic_ostream<_Elem, _Traits>& _O template basic_ostream<_Elem, _Traits>& flush_emit(basic_ostream<_Elem, _Traits>& _Ostr) { + const sentry _Ok(_Ostr); _Ostr.flush(); const auto _Sync_buf_ptr = dynamic_cast<_Basic_syncbuf_impl<_Elem, _Traits>*>(_Ostr.rdbuf()); if (_Sync_buf_ptr) { diff --git a/stl/inc/syncstream b/stl/inc/syncstream index 83350ca2d9..84f35c9734 100644 --- a/stl/inc/syncstream +++ b/stl/inc/syncstream @@ -153,6 +153,7 @@ public: } bool emit() { + const sentry _Ok(*this); if (!_Wrapped) { return false; } From c0b25f220128c88454adb6be5012f2de2253924f Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 15 Dec 2021 13:58:11 +0700 Subject: [PATCH 04/13] qualified name --- stl/inc/ostream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index c53d0a33de..25507d2754 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1038,7 +1038,7 @@ basic_ostream<_Elem, _Traits>& noemit_on_flush(basic_ostream<_Elem, _Traits>& _O template basic_ostream<_Elem, _Traits>& flush_emit(basic_ostream<_Elem, _Traits>& _Ostr) { - const sentry _Ok(_Ostr); + const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); _Ostr.flush(); const auto _Sync_buf_ptr = dynamic_cast<_Basic_syncbuf_impl<_Elem, _Traits>*>(_Ostr.rdbuf()); if (_Sync_buf_ptr) { From d93e386849e812a77258765c38c572166c008c83 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Wed, 15 Dec 2021 14:20:47 +0700 Subject: [PATCH 05/13] correct place for sentry --- stl/inc/syncstream | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stl/inc/syncstream b/stl/inc/syncstream index 84f35c9734..fdcd97c1cf 100644 --- a/stl/inc/syncstream +++ b/stl/inc/syncstream @@ -153,7 +153,6 @@ public: } bool emit() { - const sentry _Ok(*this); if (!_Wrapped) { return false; } @@ -345,6 +344,7 @@ public: basic_osyncstream& operator=(basic_osyncstream&&) noexcept = default; void emit() { + const typename basic_ostream<_Elem, _Traits>::sentry _Ok(*this); if (!_Sync_buf.emit()) { _Mybase::setstate(ios::badbit); } From 4ecbb31a7cdbe9003cd19042a1aee62c2f842cf2 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 16 Dec 2021 09:39:05 +0700 Subject: [PATCH 06/13] correct sentries usage Co-authored-by: Matt Stephanson --- stl/inc/ostream | 16 ++++++++++++---- stl/inc/syncstream | 13 +++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/stl/inc/ostream b/stl/inc/ostream index 25507d2754..e589453d67 100644 --- a/stl/inc/ostream +++ b/stl/inc/ostream @@ -1038,14 +1038,22 @@ basic_ostream<_Elem, _Traits>& noemit_on_flush(basic_ostream<_Elem, _Traits>& _O template basic_ostream<_Elem, _Traits>& flush_emit(basic_ostream<_Elem, _Traits>& _Ostr) { - const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); _Ostr.flush(); const auto _Sync_buf_ptr = dynamic_cast<_Basic_syncbuf_impl<_Elem, _Traits>*>(_Ostr.rdbuf()); if (_Sync_buf_ptr) { - const bool _Emit_failed = !_Sync_buf_ptr->_Do_emit(); - if (_Emit_failed) { - _Ostr.setstate(ios_base::badbit); + ios_base::iostate _State = ios_base::goodbit; + const typename basic_ostream<_Elem, _Traits>::sentry _Ok(_Ostr); + if (!_Ok) { + _State |= ios_base::badbit; + } else { + _TRY_IO_BEGIN + const bool _Emit_failed = !_Sync_buf_ptr->_Do_emit(); + if (_Emit_failed) { + _State |= ios_base::badbit; + } + _CATCH_IO_(ios_base, _Ostr) } + _Ostr.setstate(_State); } return _Ostr; } diff --git a/stl/inc/syncstream b/stl/inc/syncstream index fdcd97c1cf..4deec8eb55 100644 --- a/stl/inc/syncstream +++ b/stl/inc/syncstream @@ -323,6 +323,7 @@ public: using syncbuf_type = basic_syncbuf<_Elem, _Traits, _Alloc>; using _Mybase = basic_ostream<_Elem, _Traits>; + using _Myios = basic_ios<_Elem, _Traits>; basic_osyncstream(streambuf_type* _Strbuf, const _Alloc& _Al) : _Mybase(_STD addressof(_Sync_buf)), _Sync_buf(_Strbuf, _Al) {} @@ -344,10 +345,18 @@ public: basic_osyncstream& operator=(basic_osyncstream&&) noexcept = default; void emit() { + ios_base::iostate _State = ios_base::goodbit; const typename basic_ostream<_Elem, _Traits>::sentry _Ok(*this); - if (!_Sync_buf.emit()) { - _Mybase::setstate(ios::badbit); + if (!_Ok) { + _State |= ios_base::badbit; + } else { + _TRY_IO_BEGIN + if (!_Sync_buf.emit()) { + _State |= ios_base::badbit; + } + _CATCH_IO_END } + _Mybase::setstate(_State); } _NODISCARD streambuf_type* get_wrapped() const noexcept { return _Sync_buf.get_wrapped(); From c08e7890b987879590305e731710b55f9e86f305 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 16 Dec 2021 10:22:10 +0700 Subject: [PATCH 07/13] add tests Co-authored-by: Matt Stephanson --- .../test.cpp | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index 7f0340d41f..6bc198b528 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -92,9 +93,32 @@ void test_osyncstream_manipulators( } void test_lwg_3571() { - basic_osyncstream stream(nullptr); - stream << flush_emit; - assert(stream.rdstate() == ios::badbit); + { + osyncstream stream(nullptr); + stream << flush_emit; + assert(stream.rdstate() == ios::badbit); + } + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios::badbit) == 0); + stream << flush_emit; + assert(stream.rdstate() & ios::badbit); + assert(inner.str() == ""); + } +} + +void test_lwg_3570() { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios::badbit) == 0); + stream.emit(); + assert(stream.rdstate() & ios::badbit); + assert(inner.str() == ""); } int main() { @@ -113,4 +137,5 @@ int main() { &no_sync_char_buffer, false); test_lwg_3571(); + test_lwg_3570(); } From 797fc6760900de49324346557b5227e0e9e65c99 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 16 Dec 2021 16:11:36 +0700 Subject: [PATCH 08/13] add more tests --- .../test.cpp | 55 ++++++++++++++++--- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index 6bc198b528..c5a8582964 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -92,6 +92,17 @@ void test_osyncstream_manipulators( } } +template +class throwing_string_buffer : public basic_streambuf> { +public: + throwing_string_buffer() = default; + ~throwing_string_buffer() = default; + + streamsize xsputn(const Ty*, streamsize) override { + throw std::ostream::failure("test exception"); + } +}; + void test_lwg_3571() { { osyncstream stream(nullptr); @@ -108,17 +119,45 @@ void test_lwg_3571() { assert(stream.rdstate() & ios::badbit); assert(inner.str() == ""); } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | std::ios_base::badbit); + assert((stream.rdstate() & ios::badbit) == 0); + try { + stream << flush_emit; + assert(false); + } catch (const std::ostream::failure&) { + assert(stream.rdstate() & ios::badbit); + } + } } void test_lwg_3570() { - stringstream inner; - osyncstream stream(inner); - stream << "Hello World"; - stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios::badbit) == 0); - stream.emit(); - assert(stream.rdstate() & ios::badbit); - assert(inner.str() == ""); + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios::badbit) == 0); + stream.emit(); + assert(stream.rdstate() & ios::badbit); + assert(inner.str() == ""); + } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | std::ios_base::badbit); + assert((stream.rdstate() & ios::badbit) == 0); + try { + stream.emit(); + assert(false); + } catch (const std::ostream::failure&) { + assert(stream.rdstate() & ios::badbit); + } + } } int main() { From ba291d96df63f740a15fef911521380ef1ba3b65 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Tue, 21 Dec 2021 00:06:31 +0700 Subject: [PATCH 09/13] add lwg descriptions --- .../test.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index c5a8582964..545d224f02 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -104,6 +104,7 @@ class throwing_string_buffer : public basic_streambuf> { }; void test_lwg_3571() { + // LWG-3571: "flush_emit should set badbit if the emit call fails" { osyncstream stream(nullptr); stream << flush_emit; @@ -135,6 +136,7 @@ void test_lwg_3571() { } void test_lwg_3570() { + // LWG-3570: "basic_osyncstream::emit should be an unformatted output function" { stringstream inner; osyncstream stream(inner); From e8f598a95a70d0a082e680e77e5ca5182da82eb6 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Tue, 22 Feb 2022 19:27:25 -0800 Subject: [PATCH 10/13] Code review feedback. --- stl/inc/syncstream | 2 +- .../test.cpp | 34 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/stl/inc/syncstream b/stl/inc/syncstream index 6f81897c61..1437ca8ac1 100644 --- a/stl/inc/syncstream +++ b/stl/inc/syncstream @@ -346,7 +346,7 @@ public: void emit() { ios_base::iostate _State = ios_base::goodbit; - const typename basic_ostream<_Elem, _Traits>::sentry _Ok(*this); + const typename _Mybase::sentry _Ok(*this); if (!_Ok) { _State |= ios_base::badbit; } else { diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index 545d224f02..b06fd4ad71 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -58,9 +58,9 @@ void test_osyncstream_manipulators( assert(addressof(flush_emit(os)) == addressof(os)); if constexpr (is_base_of_v, Ty>) { if constexpr (ThrowOnSync) { - assert(os.rdstate() == ios::badbit); + assert(os.rdstate() == ios_base::badbit); } else { - assert(os.rdstate() == (buf ? ios::goodbit : ios::badbit)); + assert(os.rdstate() == (buf ? ios_base::goodbit : ios_base::badbit)); } if (buf) { @@ -79,7 +79,7 @@ void test_osyncstream_manipulators( assert(addressof(flush_emit(os)) == addressof(os)); if constexpr (is_base_of_v, Ty>) { - const auto state = (buf && buffer_can_sync) ? ios::goodbit : ios::badbit; + const auto state = (buf && buffer_can_sync) ? ios_base::goodbit : ios_base::badbit; assert(os.rdstate() == state); if (buf) { assert(buf->str == "Another input"); @@ -99,7 +99,7 @@ class throwing_string_buffer : public basic_streambuf> { ~throwing_string_buffer() = default; streamsize xsputn(const Ty*, streamsize) override { - throw std::ostream::failure("test exception"); + throw ios_base::failure{"test exception"}; } }; @@ -108,29 +108,29 @@ void test_lwg_3571() { { osyncstream stream(nullptr); stream << flush_emit; - assert(stream.rdstate() == ios::badbit); + assert(stream.rdstate() == ios_base::badbit); } { stringstream inner; osyncstream stream(inner); stream << "Hello World"; stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios::badbit) == 0); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); stream << flush_emit; - assert(stream.rdstate() & ios::badbit); + assert(stream.rdstate() & ios_base::badbit); assert(inner.str() == ""); } { throwing_string_buffer inner; osyncstream stream(&inner); stream << "Hello World"; - stream.exceptions(ios_base::failbit | std::ios_base::badbit); - assert((stream.rdstate() & ios::badbit) == 0); + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); try { stream << flush_emit; assert(false); - } catch (const std::ostream::failure&) { - assert(stream.rdstate() & ios::badbit); + } catch (const ios_base::failure&) { + assert(stream.rdstate() & ios_base::badbit); } } } @@ -142,22 +142,22 @@ void test_lwg_3570() { osyncstream stream(inner); stream << "Hello World"; stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios::badbit) == 0); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); stream.emit(); - assert(stream.rdstate() & ios::badbit); + assert(stream.rdstate() & ios_base::badbit); assert(inner.str() == ""); } { throwing_string_buffer inner; osyncstream stream(&inner); stream << "Hello World"; - stream.exceptions(ios_base::failbit | std::ios_base::badbit); - assert((stream.rdstate() & ios::badbit) == 0); + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); try { stream.emit(); assert(false); - } catch (const std::ostream::failure&) { - assert(stream.rdstate() & ios::badbit); + } catch (const ios_base::failure&) { + assert(stream.rdstate() & ios_base::badbit); } } } From 0c4f21644ff335c297a4c8d2840f8aed1ef57241 Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 10 Mar 2022 17:12:27 +0700 Subject: [PATCH 11/13] move the ternary operator out of the assert Co-authored-by: Charlie Barto --- .../test.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index b06fd4ad71..a687668879 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -60,7 +60,11 @@ void test_osyncstream_manipulators( if constexpr (ThrowOnSync) { assert(os.rdstate() == ios_base::badbit); } else { - assert(os.rdstate() == (buf ? ios_base::goodbit : ios_base::badbit)); + if(buf) { + assert(os.rdstate() == ios_base::goodbit); + else { + assert(os.rdstate() == ios_base::badbit); + } } if (buf) { From 37e1a33e31d1bb9c1eabd3dba26a2231782236cd Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 10 Mar 2022 17:33:15 +0700 Subject: [PATCH 12/13] clang-format --- .../test.cpp | 196 +++++++++--------- 1 file changed, 98 insertions(+), 98 deletions(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index a687668879..bebbd7cbb3 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -60,127 +60,127 @@ void test_osyncstream_manipulators( if constexpr (ThrowOnSync) { assert(os.rdstate() == ios_base::badbit); } else { - if(buf) { + if (buf) { assert(os.rdstate() == ios_base::goodbit); - else { - assert(os.rdstate() == ios_base::badbit); + else { + assert(os.rdstate() == ios_base::badbit); + } } + + if (buf) { + assert(buf->str == "Some input"); + buf->str.clear(); + } + os.clear(); + os << "Another input"; } - if (buf) { - assert(buf->str == "Some input"); - buf->str.clear(); + assert(addressof(noemit_on_flush(os)) == addressof(os)); + if constexpr (is_base_of_v, Ty>) { + auto* aSyncbuf = static_cast*>(os.rdbuf()); + assert(aSyncbuf->_Stl_internal_check_get_emit_on_sync() == false); } - os.clear(); - os << "Another input"; - } - assert(addressof(noemit_on_flush(os)) == addressof(os)); - if constexpr (is_base_of_v, Ty>) { - auto* aSyncbuf = static_cast*>(os.rdbuf()); - assert(aSyncbuf->_Stl_internal_check_get_emit_on_sync() == false); - } + assert(addressof(flush_emit(os)) == addressof(os)); + if constexpr (is_base_of_v, Ty>) { + const auto state = (buf && buffer_can_sync) ? ios_base::goodbit : ios_base::badbit; + assert(os.rdstate() == state); + if (buf) { + assert(buf->str == "Another input"); + } + os.clear(); + } - assert(addressof(flush_emit(os)) == addressof(os)); - if constexpr (is_base_of_v, Ty>) { - const auto state = (buf && buffer_can_sync) ? ios_base::goodbit : ios_base::badbit; - assert(os.rdstate() == state); if (buf) { - assert(buf->str == "Another input"); + buf->str.clear(); } - os.clear(); - } - - if (buf) { - buf->str.clear(); } -} -template -class throwing_string_buffer : public basic_streambuf> { -public: - throwing_string_buffer() = default; - ~throwing_string_buffer() = default; + template + class throwing_string_buffer : public basic_streambuf> { + public: + throwing_string_buffer() = default; + ~throwing_string_buffer() = default; - streamsize xsputn(const Ty*, streamsize) override { - throw ios_base::failure{"test exception"}; - } -}; + streamsize xsputn(const Ty*, streamsize) override { + throw ios_base::failure{"test exception"}; + } + }; -void test_lwg_3571() { - // LWG-3571: "flush_emit should set badbit if the emit call fails" - { - osyncstream stream(nullptr); - stream << flush_emit; - assert(stream.rdstate() == ios_base::badbit); - } - { - stringstream inner; - osyncstream stream(inner); - stream << "Hello World"; - stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - stream << flush_emit; - assert(stream.rdstate() & ios_base::badbit); - assert(inner.str() == ""); - } - { - throwing_string_buffer inner; - osyncstream stream(&inner); - stream << "Hello World"; - stream.exceptions(ios_base::failbit | ios_base::badbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - try { + void test_lwg_3571() { + // LWG-3571: "flush_emit should set badbit if the emit call fails" + { + osyncstream stream(nullptr); + stream << flush_emit; + assert(stream.rdstate() == ios_base::badbit); + } + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); stream << flush_emit; - assert(false); - } catch (const ios_base::failure&) { assert(stream.rdstate() & ios_base::badbit); + assert(inner.str() == ""); + } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + try { + stream << flush_emit; + assert(false); + } catch (const ios_base::failure&) { + assert(stream.rdstate() & ios_base::badbit); + } } } -} - -void test_lwg_3570() { - // LWG-3570: "basic_osyncstream::emit should be an unformatted output function" - { - stringstream inner; - osyncstream stream(inner); - stream << "Hello World"; - stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - stream.emit(); - assert(stream.rdstate() & ios_base::badbit); - assert(inner.str() == ""); - } - { - throwing_string_buffer inner; - osyncstream stream(&inner); - stream << "Hello World"; - stream.exceptions(ios_base::failbit | ios_base::badbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - try { + + void test_lwg_3570() { + // LWG-3570: "basic_osyncstream::emit should be an unformatted output function" + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); stream.emit(); - assert(false); - } catch (const ios_base::failure&) { assert(stream.rdstate() & ios_base::badbit); + assert(inner.str() == ""); + } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + try { + stream.emit(); + assert(false); + } catch (const ios_base::failure&) { + assert(stream.rdstate() & ios_base::badbit); + } } } -} -int main() { - string_buffer char_buffer{}; - string_buffer no_sync_char_buffer{}; + int main() { + string_buffer char_buffer{}; + string_buffer no_sync_char_buffer{}; - test_osyncstream_manipulators>(); - test_osyncstream_manipulators, allocator>, allocator>(); + test_osyncstream_manipulators>(); + test_osyncstream_manipulators, allocator>, allocator>(); - test_osyncstream_manipulators>(&char_buffer); - test_osyncstream_manipulators, allocator>, allocator>( - &char_buffer); + test_osyncstream_manipulators>(&char_buffer); + test_osyncstream_manipulators, allocator>, allocator>( + &char_buffer); - test_osyncstream_manipulators>(&no_sync_char_buffer); - test_osyncstream_manipulators, allocator>, allocator>( - &no_sync_char_buffer, false); + test_osyncstream_manipulators>(&no_sync_char_buffer); + test_osyncstream_manipulators, allocator>, allocator>( + &no_sync_char_buffer, false); - test_lwg_3571(); - test_lwg_3570(); -} + test_lwg_3571(); + test_lwg_3570(); + } From 56ccebd87f547bc896e28d5ced87fc5cb5ce1b9a Mon Sep 17 00:00:00 2001 From: Igor Zhukov Date: Thu, 10 Mar 2022 19:06:25 +0700 Subject: [PATCH 13/13] typo --- .../test.cpp | 194 +++++++++--------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp index bebbd7cbb3..89680ef17e 100644 --- a/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp +++ b/tests/std/tests/P0753R2_manipulators_for_cpp_synchronized_buffered_ostream/test.cpp @@ -62,125 +62,125 @@ void test_osyncstream_manipulators( } else { if (buf) { assert(os.rdstate() == ios_base::goodbit); - else { - assert(os.rdstate() == ios_base::badbit); - } + } else { + assert(os.rdstate() == ios_base::badbit); } - - if (buf) { - assert(buf->str == "Some input"); - buf->str.clear(); - } - os.clear(); - os << "Another input"; } - assert(addressof(noemit_on_flush(os)) == addressof(os)); - if constexpr (is_base_of_v, Ty>) { - auto* aSyncbuf = static_cast*>(os.rdbuf()); - assert(aSyncbuf->_Stl_internal_check_get_emit_on_sync() == false); + if (buf) { + assert(buf->str == "Some input"); + buf->str.clear(); } + os.clear(); + os << "Another input"; + } - assert(addressof(flush_emit(os)) == addressof(os)); - if constexpr (is_base_of_v, Ty>) { - const auto state = (buf && buffer_can_sync) ? ios_base::goodbit : ios_base::badbit; - assert(os.rdstate() == state); - if (buf) { - assert(buf->str == "Another input"); - } - os.clear(); - } + assert(addressof(noemit_on_flush(os)) == addressof(os)); + if constexpr (is_base_of_v, Ty>) { + auto* aSyncbuf = static_cast*>(os.rdbuf()); + assert(aSyncbuf->_Stl_internal_check_get_emit_on_sync() == false); + } + assert(addressof(flush_emit(os)) == addressof(os)); + if constexpr (is_base_of_v, Ty>) { + const auto state = (buf && buffer_can_sync) ? ios_base::goodbit : ios_base::badbit; + assert(os.rdstate() == state); if (buf) { - buf->str.clear(); + assert(buf->str == "Another input"); } + os.clear(); + } + + if (buf) { + buf->str.clear(); } +} - template - class throwing_string_buffer : public basic_streambuf> { - public: - throwing_string_buffer() = default; - ~throwing_string_buffer() = default; +template +class throwing_string_buffer : public basic_streambuf> { +public: + throwing_string_buffer() = default; + ~throwing_string_buffer() = default; - streamsize xsputn(const Ty*, streamsize) override { - throw ios_base::failure{"test exception"}; - } - }; + streamsize xsputn(const Ty*, streamsize) override { + throw ios_base::failure{"test exception"}; + } +}; - void test_lwg_3571() { - // LWG-3571: "flush_emit should set badbit if the emit call fails" - { - osyncstream stream(nullptr); - stream << flush_emit; - assert(stream.rdstate() == ios_base::badbit); - } - { - stringstream inner; - osyncstream stream(inner); - stream << "Hello World"; - stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); +void test_lwg_3571() { + // LWG-3571: "flush_emit should set badbit if the emit call fails" + { + osyncstream stream(nullptr); + stream << flush_emit; + assert(stream.rdstate() == ios_base::badbit); + } + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + stream << flush_emit; + assert(stream.rdstate() & ios_base::badbit); + assert(inner.str() == ""); + } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + try { stream << flush_emit; + assert(false); + } catch (const ios_base::failure&) { assert(stream.rdstate() & ios_base::badbit); - assert(inner.str() == ""); - } - { - throwing_string_buffer inner; - osyncstream stream(&inner); - stream << "Hello World"; - stream.exceptions(ios_base::failbit | ios_base::badbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - try { - stream << flush_emit; - assert(false); - } catch (const ios_base::failure&) { - assert(stream.rdstate() & ios_base::badbit); - } } } - - void test_lwg_3570() { - // LWG-3570: "basic_osyncstream::emit should be an unformatted output function" - { - stringstream inner; - osyncstream stream(inner); - stream << "Hello World"; - stream.setstate(ios_base::failbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); +} + +void test_lwg_3570() { + // LWG-3570: "basic_osyncstream::emit should be an unformatted output function" + { + stringstream inner; + osyncstream stream(inner); + stream << "Hello World"; + stream.setstate(ios_base::failbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + stream.emit(); + assert(stream.rdstate() & ios_base::badbit); + assert(inner.str() == ""); + } + { + throwing_string_buffer inner; + osyncstream stream(&inner); + stream << "Hello World"; + stream.exceptions(ios_base::failbit | ios_base::badbit); + assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); + try { stream.emit(); + assert(false); + } catch (const ios_base::failure&) { assert(stream.rdstate() & ios_base::badbit); - assert(inner.str() == ""); - } - { - throwing_string_buffer inner; - osyncstream stream(&inner); - stream << "Hello World"; - stream.exceptions(ios_base::failbit | ios_base::badbit); - assert((stream.rdstate() & ios_base::badbit) == ios_base::goodbit); - try { - stream.emit(); - assert(false); - } catch (const ios_base::failure&) { - assert(stream.rdstate() & ios_base::badbit); - } } } +} - int main() { - string_buffer char_buffer{}; - string_buffer no_sync_char_buffer{}; +int main() { + string_buffer char_buffer{}; + string_buffer no_sync_char_buffer{}; - test_osyncstream_manipulators>(); - test_osyncstream_manipulators, allocator>, allocator>(); + test_osyncstream_manipulators>(); + test_osyncstream_manipulators, allocator>, allocator>(); - test_osyncstream_manipulators>(&char_buffer); - test_osyncstream_manipulators, allocator>, allocator>( - &char_buffer); + test_osyncstream_manipulators>(&char_buffer); + test_osyncstream_manipulators, allocator>, allocator>( + &char_buffer); - test_osyncstream_manipulators>(&no_sync_char_buffer); - test_osyncstream_manipulators, allocator>, allocator>( - &no_sync_char_buffer, false); + test_osyncstream_manipulators>(&no_sync_char_buffer); + test_osyncstream_manipulators, allocator>, allocator>( + &no_sync_char_buffer, false); - test_lwg_3571(); - test_lwg_3570(); - } + test_lwg_3571(); + test_lwg_3570(); +}