From b300fdeef440a3f11bb54f9f5a6ad85fd577cc2c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 21 Sep 2018 20:45:44 +0300 Subject: [PATCH 1/5] Use CP_UTF8 when BOOST_SYSTEM_USE_UTF8 is defined --- .../system/detail/system_category_win32.hpp | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/include/boost/system/detail/system_category_win32.hpp b/include/boost/system/detail/system_category_win32.hpp index 4739b89..72b3b3b 100644 --- a/include/boost/system/detail/system_category_win32.hpp +++ b/include/boost/system/detail/system_category_win32.hpp @@ -95,7 +95,17 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s return unknown_message_win32( ev, buffer, len ); } - int r = boost::winapi::WideCharToMultiByte( CP_ACP_, 0, wbuffer, -1, buffer, static_cast( len ), NULL, NULL ); +#if defined(BOOST_SYSTEM_USE_UTF8) + + UINT_ code_page = CP_UTF8_; + +#else + + UINT_ code_page = CP_ACP_; + +#endif + + int r = boost::winapi::WideCharToMultiByte( code_page, 0, wbuffer, -1, buffer, static_cast( len ), NULL, NULL ); if( r == 0 ) { @@ -156,7 +166,17 @@ inline std::string system_category_message_win32( int ev ) local_free lf_ = { lpMsgBuf }; - int r = boost::winapi::WideCharToMultiByte( CP_ACP_, 0, lpMsgBuf, -1, 0, 0, NULL, NULL ); +#if defined(BOOST_SYSTEM_USE_UTF8) + + UINT_ code_page = CP_UTF8_; + +#else + + UINT_ code_page = CP_ACP_; + +#endif + + int r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, 0, 0, NULL, NULL ); if( r == 0 ) { @@ -165,7 +185,7 @@ inline std::string system_category_message_win32( int ev ) std::string buffer( r, char() ); - r = boost::winapi::WideCharToMultiByte( CP_ACP_, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL ); + r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL ); if( r == 0 ) { From 584f9731addf343fc8eba7d97e571648b9a3307b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 1 Oct 2018 17:40:16 +0300 Subject: [PATCH 2/5] Refactor BOOST_SYSTEM_USE_UTF8 code --- .../system/detail/system_category_win32.hpp | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/include/boost/system/detail/system_category_win32.hpp b/include/boost/system/detail/system_category_win32.hpp index 72b3b3b..323eae7 100644 --- a/include/boost/system/detail/system_category_win32.hpp +++ b/include/boost/system/detail/system_category_win32.hpp @@ -55,6 +55,19 @@ inline char const * unknown_message_win32( int ev, char * buffer, std::size_t le #endif +inline boost::winapi::UINT_ message_cp_win32() +{ +#if defined(BOOST_SYSTEM_USE_UTF8) + + return boost::winapi::CP_UTF8_; + +#else + + return boost::winapi::CP_ACP_; + +#endif +} + inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT { if( len == 0 ) @@ -95,15 +108,7 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s return unknown_message_win32( ev, buffer, len ); } -#if defined(BOOST_SYSTEM_USE_UTF8) - - UINT_ code_page = CP_UTF8_; - -#else - - UINT_ code_page = CP_ACP_; - -#endif + UINT_ const code_page = message_cp_win32(); int r = boost::winapi::WideCharToMultiByte( code_page, 0, wbuffer, -1, buffer, static_cast( len ), NULL, NULL ); @@ -166,15 +171,7 @@ inline std::string system_category_message_win32( int ev ) local_free lf_ = { lpMsgBuf }; -#if defined(BOOST_SYSTEM_USE_UTF8) - - UINT_ code_page = CP_UTF8_; - -#else - - UINT_ code_page = CP_ACP_; - -#endif + UINT_ const code_page = message_cp_win32(); int r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, 0, 0, NULL, NULL ); From 342400c7ec74aa5a05b71e42bf3276b156aa158b Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 2 Oct 2018 04:34:33 +0300 Subject: [PATCH 3/5] Add a quick test with -Wall -Werror --- test/Jamfile.v2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index ee73b6b..8b6ee0a 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -132,3 +132,5 @@ system-run- failed_constexpr_test.cpp ; # Quick (CI) test run quick.cpp ; + +run quick.cpp : : : all on : warnings_test ; From 3d01409fe6d21f95033214eb24d2ce81ac028520 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 2 Oct 2018 17:51:09 +0300 Subject: [PATCH 4/5] Avoid long long warnings --- include/boost/system/error_code.hpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index f413980..2f2f60a 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -278,7 +278,8 @@ public: // clang++ 3.8 and below: initialization of const object // requires a user-provided default constructor - BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT: error_category( 0xB2AB117A257EDF0Dull ) + BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT: + error_category( ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDF0D ) { } @@ -295,7 +296,8 @@ class BOOST_SYMBOL_VISIBLE system_error_category: public error_category { public: - BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT: error_category( 0x8FAFD21E25C5E09Bull ) + BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT: + error_category( ( boost::ulong_long_type( 0x8FAFD21E ) << 32 ) + 0x25C5E09B ) { } @@ -651,7 +653,7 @@ public: return failed_? unspecified_bool_true: 0; } - BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error + BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error { return !failed_; } @@ -773,8 +775,8 @@ inline std::size_t hash_value( error_code const & ec ) id = reinterpret_cast( &cat ); } - boost::ulong_long_type hv = 0xCBF29CE484222325ull; - boost::ulong_long_type const prime = 0x00000100000001B3ull; + boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325; + boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3; // id From e87cd333a8f2e7326ced282b6e03ca97e985b876 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 2 Oct 2018 18:39:41 +0300 Subject: [PATCH 5/5] Work around 'unused variable' MSVC warning --- include/boost/system/detail/system_category_win32.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/system/detail/system_category_win32.hpp b/include/boost/system/detail/system_category_win32.hpp index 323eae7..8a86e81 100644 --- a/include/boost/system/detail/system_category_win32.hpp +++ b/include/boost/system/detail/system_category_win32.hpp @@ -170,6 +170,7 @@ inline std::string system_category_message_win32( int ev ) } local_free lf_ = { lpMsgBuf }; + (void)lf_; UINT_ const code_page = message_cp_win32();