include/o3tl/string_view.hxx | 11 +++++------ o3tl/qa/test-string_view.cxx | 9 +++++++++ 2 files changed, 14 insertions(+), 6 deletions(-)
New commits: commit 0d2ac93f4a3bec9d2fe2719b270333193d20596b Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Sun Dec 16 12:52:56 2018 +0100 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Sun Dec 16 17:14:33 2018 +0100 Fix o3tl::string_view streaming operator << (The unnecessary os.setstate(std::ios_base::failbit) was due to a misreading of C++17 [ostream.formatted.reqmts]/1.) Change-Id: I7d8285230cb316c7af45c76029e9629517d05d56 Reviewed-on: https://gerrit.libreoffice.org/65217 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/include/o3tl/string_view.hxx b/include/o3tl/string_view.hxx index b605da65ac90..2bc182034342 100644 --- a/include/o3tl/string_view.hxx +++ b/include/o3tl/string_view.hxx @@ -732,12 +732,13 @@ operator <<( std::basic_ostream<charT, traits> & os, basic_string_view<charT, traits> str) { - typename std::basic_ostream<charT, traits>::sentry sentry; + typename std::basic_ostream<charT, traits>::sentry sentry(os); if (sentry) { auto const w = os.width(); - auto const pad - = std::max<std::make_unsigned<decltype(w + str.size())>::type>( - w < 0 ? 0 : w, str.size()); + auto pad + = std::max<typename std::make_unsigned<decltype(w + str.size())>::type>( + w < 0 ? 0 : w, str.size()) + - str.size(); auto const after = (os.flags() & std::ios_base::adjustfield) == std::ios_base::left; if (pad != 0 && !after) { @@ -754,8 +755,6 @@ operator <<( } } os.width(0); - } else { - os.setstate(std::ios_base::failbit); } return os; } diff --git a/o3tl/qa/test-string_view.cxx b/o3tl/qa/test-string_view.cxx index 977cfebc460a..fb6239fca379 100644 --- a/o3tl/qa/test-string_view.cxx +++ b/o3tl/qa/test-string_view.cxx @@ -9,7 +9,9 @@ #include <sal/config.h> +#include <sstream> #include <stdexcept> +#include <string> #include <cppunit/TestAssert.h> #include <cppunit/TestFixture.h> @@ -27,6 +29,7 @@ private: CPPUNIT_TEST(testChar32Literal); CPPUNIT_TEST(testWcharLiteral); CPPUNIT_TEST(testOperations); + CPPUNIT_TEST(testOutput); CPPUNIT_TEST_SUITE_END(); void testCharLiteral() { @@ -203,6 +206,12 @@ private: v.find_last_not_of("fxo", o3tl::string_view::npos, 2)); CPPUNIT_ASSERT_EQUAL(npos, v.find_last_not_of("fxo")); } + + void testOutput() { + std::ostringstream s; + s << o3tl::string_view("foo"); + CPPUNIT_ASSERT_EQUAL(std::string("foo"), s.str()); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(Test); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits