From c8ad51877ec4d2345a012089477a8ea95675ce74 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sun, 5 Jan 2020 20:25:09 +0100 Subject: [PATCH 1/4] Make class really uncopyable --- include/boost/nowide/args.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/nowide/args.hpp b/include/boost/nowide/args.hpp index 5601b91..a1cbdc3 100644 --- a/include/boost/nowide/args.hpp +++ b/include/boost/nowide/args.hpp @@ -85,7 +85,10 @@ namespace nowide { { wchar_t **p; int argc; - wargv_ptr(const wargv_ptr &); // Non-copyable + // Non-copyable + wargv_ptr(const wargv_ptr &); + wargv_ptr &operator=(const wargv_ptr &); + public: wargv_ptr() : p(CommandLineToArgvW(GetCommandLineW(), &argc)) {} @@ -110,7 +113,10 @@ namespace nowide { class wenv_ptr { wchar_t *p; - wenv_ptr(const wenv_ptr &); // Non-copyable + // Non-copyable + wenv_ptr(const wenv_ptr &); + wenv_ptr &operator=(const wenv_ptr &); + public: wenv_ptr() : p(GetEnvironmentStringsW()) {} From 74586edc531551e388c76eed04fea5df95aa9cb3 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sun, 5 Jan 2020 20:25:35 +0100 Subject: [PATCH 2/4] Test and fix compile failure in is_open function --- include/boost/nowide/fstream.hpp | 6 +++--- test/test_fstream.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/include/boost/nowide/fstream.hpp b/include/boost/nowide/fstream.hpp index caf1451..ff90fd3 100644 --- a/include/boost/nowide/fstream.hpp +++ b/include/boost/nowide/fstream.hpp @@ -74,7 +74,7 @@ namespace nowide { } bool is_open() { - return buf_->is_open(); + return buf_.is_open(); } bool is_open() const { @@ -134,7 +134,7 @@ namespace nowide { } bool is_open() { - return buf_->is_open(); + return buf_.is_open(); } bool is_open() const { @@ -198,7 +198,7 @@ namespace nowide { } bool is_open() { - return buf_->is_open(); + return buf_.is_open(); } bool is_open() const { diff --git a/test/test_fstream.cpp b/test/test_fstream.cpp index ce4c7af..eb5e291 100644 --- a/test/test_fstream.cpp +++ b/test/test_fstream.cpp @@ -435,6 +435,37 @@ void test_fstream(const char *filename) TEST(nw::remove(filename) == 0); } +template +bool is_open(T &stream) +{ + // There are const and non const versions of is_open + // Test both + TEST(stream.is_open() == const_cast(stream).is_open()); + return stream.is_open(); +} + +template +void do_test_is_open(const char *filename) +{ + T f; + TEST(!is_open(f)); + f.open(filename); + TEST(f); + TEST(is_open(f)); + f.close(); + TEST(f); + TEST(!is_open(f)); +} + +void test_is_open(const char *filename) +{ + // Note the order: Output before input so file exists + do_test_is_open(filename); + do_test_is_open(filename); + do_test_is_open(filename); + TEST(nw::remove(filename) == 0); +} + int main(int, char **argv) { const std::string exampleFilename = std::string(argv[0]) + "-\xd7\xa9-\xd0\xbc-\xce\xbd.txt"; @@ -445,6 +476,7 @@ int main(int, char **argv) test_ofstream_write(exampleFilename.c_str()); test_ifstream_open_read(exampleFilename.c_str()); test_fstream(exampleFilename.c_str()); + test_is_open(exampleFilename.c_str()); std::cout << "Complex IO - Sanity Check" << std::endl; // Don't use chars the std stream can't properly handle From 920e60c6da072c5b58b96b57a7c1def0d188bcfa Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Sun, 5 Jan 2020 20:26:27 +0100 Subject: [PATCH 3/4] Remove unused vectors in test_codecvt --- test/test_codecvt.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/test/test_codecvt.cpp b/test/test_codecvt.cpp index ac9dcfd..25312db 100644 --- a/test/test_codecvt.cpp +++ b/test/test_codecvt.cpp @@ -187,14 +187,13 @@ void test_codecvt_err() wchar_t buf[4]; wchar_t *const to = buf; wchar_t *const to_end = buf + 4; - wchar_t *to_next = to; char const *err_utf = "1\xFF\xFF\xd7\xa9"; { std::mbstate_t mb = std::mbstate_t(); char const *from = err_utf; char const *from_end = from + std::strlen(from); char const *from_next = from; - to_next = to; + wchar_t *to_next = to; TEST(cvt.in(mb, from, from_end, from_next, to, to_end, to_next) == cvt_type::ok); TEST(from_next == from + 5); TEST(to_next == to + 4); @@ -228,7 +227,6 @@ std::wstring codecvt_to_wide(std::string const &s) std::locale l(std::locale::classic(), new boost::nowide::utf8_codecvt()); cvt_type const &cvt = std::use_facet(l); - std::vector output(s.size() + 1); std::mbstate_t mb = std::mbstate_t(); char const *from = s.c_str(); @@ -251,7 +249,6 @@ std::string codecvt_to_narrow(std::wstring const &s) std::locale l(std::locale::classic(), new boost::nowide::utf8_codecvt()); cvt_type const &cvt = std::use_facet(l); - std::vector output(s.size() + 1); std::mbstate_t mb = std::mbstate_t(); wchar_t const *from = s.c_str(); From ca2091a884b47e2bafdb5eba80cf0bf7e9881799 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Mon, 6 Jan 2020 09:41:47 +0100 Subject: [PATCH 4/4] Add BOOST_NOWIDE_FALLTHROUGH for Boost < 1.64 --- include/boost/nowide/config.hpp | 7 +++++++ include/boost/nowide/detail/utf.hpp | 10 +++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/boost/nowide/config.hpp b/include/boost/nowide/config.hpp index 40db464..63de44d 100644 --- a/include/boost/nowide/config.hpp +++ b/include/boost/nowide/config.hpp @@ -13,6 +13,7 @@ #include #include +#include #if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_NOWIDE_DYN_LINK) #ifdef BOOST_NOWIDE_SOURCE @@ -63,5 +64,11 @@ #define BOOST_NOWIDE_USE_FSTREAM_REPLACEMENTS 0 #endif +#if BOOST_VERSION < 106500 && defined(BOOST_GCC) && BOOST_GCC_VERSION >= 70000 +#define BOOST_NOWIDE_FALLTHROUGH __attribute__((fallthrough)) +#else +#define BOOST_NOWIDE_FALLTHROUGH BOOST_FALLTHROUGH +#endif + #endif // boost/nowide/config.hpp // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 diff --git a/include/boost/nowide/detail/utf.hpp b/include/boost/nowide/detail/utf.hpp index 28bd7f0..ed43980 100644 --- a/include/boost/nowide/detail/utf.hpp +++ b/include/boost/nowide/detail/utf.hpp @@ -8,7 +8,7 @@ #ifndef BOOST_NOWIDE_UTF_HPP_INCLUDED #define BOOST_NOWIDE_UTF_HPP_INCLUDED -#include +#include #include namespace boost { @@ -219,7 +219,7 @@ namespace nowide { if(!is_trail(tmp)) return illegal; c = (c << 6) | (tmp & 0x3F); - BOOST_FALLTHROUGH; + BOOST_NOWIDE_FALLTHROUGH; case 2: if(BOOST_UNLIKELY(p == e)) return incomplete; @@ -227,7 +227,7 @@ namespace nowide { if(!is_trail(tmp)) return illegal; c = (c << 6) | (tmp & 0x3F); - BOOST_FALLTHROUGH; + BOOST_NOWIDE_FALLTHROUGH; case 1: if(BOOST_UNLIKELY(p == e)) return incomplete; @@ -269,8 +269,8 @@ namespace nowide { switch(trail_size) { - case 3: c = (c << 6) | (static_cast(*p++) & 0x3F); BOOST_FALLTHROUGH; - case 2: c = (c << 6) | (static_cast(*p++) & 0x3F); BOOST_FALLTHROUGH; + case 3: c = (c << 6) | (static_cast(*p++) & 0x3F); BOOST_NOWIDE_FALLTHROUGH; + case 2: c = (c << 6) | (static_cast(*p++) & 0x3F); BOOST_NOWIDE_FALLTHROUGH; case 1: c = (c << 6) | (static_cast(*p++) & 0x3F); }