Compare commits

...

26 Commits

Author SHA1 Message Date
455946faac Merge pull request #49 from Thomas-Barbier-1A/cpp7_redundant_redeclar_constexpr
Fix c++17 warning redundant redeclaration of 'constexpr' static data
2019-10-02 02:55:45 -07:00
08370c9158 Fix c++17 warning redundant redeclaration of 'constexpr' static data
member [-Werror=deprecated]
2019-10-01 18:49:31 +02:00
c556aba559 Remove redundant Travis job 2019-06-18 12:50:59 +03:00
ecc4ddd87c Add gcc9, clang8 to Travis 2019-06-18 12:46:04 +03:00
f67827eee3 Add dist: trusty to .travis.yml 2019-06-18 01:08:17 +03:00
c08b8a94ea Fix sign extension (warning 4826.) Closes #48. 2019-05-24 18:55:27 +03:00
835e5de228 Add clang-win to Appveyor 2019-05-14 04:16:53 +03:00
dc2ad73e30 Merge pull request #47 from KABoissonneault/feature/issue_46
Added boost::winapi::ERROR_CONNECTION_ABORTED_ to handled error codes…
2019-05-13 18:14:54 -07:00
32a6c13533 Added boost::winapi::ERROR_CONNECTION_ABORTED_ to handled error codes in Win32's system_category, making it equivalent to errc::connection_aborted 2019-05-13 18:08:24 -04:00
bfbc5ec42f Remove BOOST_SYSTEM_REQUIRE_CONST_INIT; variables are constexpr, so no longer needed. Closes #45. 2019-05-12 04:15:35 +03:00
9deadda4b4 Merge branch 'feature/system-generic-visible' into feature/std-ec-mismatch 2019-04-25 20:54:01 +03:00
3b6315e4a1 Add BOOST_SYMBOL_VISIBLE to system_category(), generic_category() 2019-04-25 16:55:13 +03:00
1d845408dd Fix thread safety issue in std interop 2019-04-25 01:01:48 +03:00
e08e4253d0 Avoid allocation on interop for system/generic categories; fix DLL interoperability on msvc-14.x by poking into std::system_category::_Addr 2019-04-25 00:31:25 +03:00
afc51937be Mark to_std_category as BOOST_SYMBOL_VISIBLE 2019-04-24 23:18:19 +03:00
907c867cd1 Rename test/std_ec_mismatch to std_single_instance; test also static and shared libraries 2019-04-24 21:15:39 +03:00
9f225112f1 Add std_ec_mismatch_test 2019-04-24 18:19:21 +03:00
48b8a6c41c Switch Appveyor to 2015 image 2019-04-14 18:06:05 +03:00
9b8cb7f1f6 Fix wrong null character stripping for FormatMessage (Nikita Kniazev) 2019-03-24 01:59:23 +02:00
90b2356015 system_error_test: Increase tested messages range (Nikita Kniazev) 2019-03-24 00:24:05 +02:00
1c36a72b79 Merge pull request #40 from Kojoley/system_error_test-mingw-non-en
system_error_test: Enable locale query on MinGW-w64
2019-03-17 11:28:45 +02:00
7947d0ed0d system_error_test: Reenable locale query on MinGW and Cygwin 2019-03-17 01:53:37 +03:00
72d3e96c73 Disable English-dependent test; fixes #39. 2019-03-16 19:51:21 +02:00
ca882f286c Skip system_category_test_utf8; comparing against FormatMessageA isn't going to work. Fixes #38. 2019-03-16 19:44:43 +02:00
df78f08bd2 Merge pull request #37 from Kojoley/patch-1
system_category_test: Increase buffer size
2019-03-16 19:02:47 +02:00
f878f41fe7 system_category_test: Increase buffer size
The message for 5810 error does not fit into buffer on non-English locales.
2019-03-16 01:55:18 +03:00
13 changed files with 290 additions and 70 deletions

View File

@ -6,6 +6,8 @@ language: cpp
sudo: false
dist: trusty
branches:
only:
- master
@ -115,6 +117,16 @@ matrix:
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-9
env: TOOLSET=gcc COMPILER=g++-9 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- g++-9
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-8
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11,14,17 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
@ -306,18 +318,6 @@ matrix:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- os: linux
compiler: clang++-6.0
env: TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,17
addons:
apt:
packages:
- clang-6.0
- libstdc++-4.9-dev
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-6.0
- os: linux
compiler: clang++-7
env: TOOLSET=clang COMPILER=clang++-7 CXXSTD=03,11,14,17,2a
@ -329,6 +329,17 @@ matrix:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-7
- os: linux
compiler: clang++-8
env: TOOLSET=clang COMPILER=clang++-8 CXXSTD=03,11,14,17,2a
addons:
apt:
packages:
- clang-8
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-trusty-8
- os: linux
compiler: clang++-6.0
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-6.0 CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1

View File

@ -1,4 +1,4 @@
# Copyright 2016-2018 Peter Dimov
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
@ -14,28 +14,28 @@ branches:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0,msvc-12.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-14.0
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-12.0,msvc-14.0
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
TOOLSET: msvc-14.1,clang-win
CXXSTD: 14,17
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z

View File

@ -22,6 +22,11 @@
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
#if defined(BOOST_NO_CXX11_HDR_MUTEX)
// Required for thread-safe map manipulation
# undef BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
// BOOST_SYSTEM_NOEXCEPT
// Retained for backward compatibility
@ -43,15 +48,4 @@
# define BOOST_SYSTEM_CONSTEXPR
#endif
// BOOST_SYSTEM_REQUIRE_CONST_INIT
#define BOOST_SYSTEM_REQUIRE_CONST_INIT
#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(clang::require_constant_initialization)
# undef BOOST_SYSTEM_REQUIRE_CONST_INIT
# define BOOST_SYSTEM_REQUIRE_CONST_INIT [[clang::require_constant_initialization]]
#endif
#endif
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED

View File

@ -10,6 +10,7 @@
#include <system_error>
#include <map>
#include <memory>
#include <mutex>
//
@ -30,8 +31,20 @@ private:
public:
explicit std_category( boost::system::error_category const * pc ): pc_( pc )
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
{
if( id != 0 )
{
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
// Poking into the protected _Addr member of std::error_category
// is not a particularly good programming practice, but what can
// you do
_Addr = id;
#endif
}
}
virtual const char * name() const BOOST_NOEXCEPT
@ -53,24 +66,50 @@ public:
virtual bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT;
};
inline std::error_category const & to_std_category( boost::system::error_category const & cat ) BOOST_SYMBOL_VISIBLE;
struct cat_ptr_less
{
bool operator()( boost::system::error_category const * p1, boost::system::error_category const * p2 ) const BOOST_NOEXCEPT
{
return *p1 < *p2;
}
};
inline std::error_category const & to_std_category( boost::system::error_category const & cat )
{
typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category> > map_type;
static map_type map_;
map_type::iterator i = map_.find( &cat );
if( i == map_.end() )
if( cat == boost::system::system_category() )
{
std::unique_ptr<std_category> p( new std_category( &cat ) );
std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );
i = r.first;
static const std_category system_instance( &cat, 0x1F4D7 );
return system_instance;
}
else if( cat == boost::system::generic_category() )
{
static const std_category generic_instance( &cat, 0x1F4D3 );
return generic_instance;
}
else
{
typedef std::map< boost::system::error_category const *, std::unique_ptr<std_category>, cat_ptr_less > map_type;
return *i->second;
static map_type map_;
static std::mutex map_mx_;
std::lock_guard<std::mutex> guard( map_mx_ );
map_type::iterator i = map_.find( &cat );
if( i == map_.end() )
{
std::unique_ptr<std_category> p( new std_category( &cat, 0 ) );
std::pair<map_type::iterator, bool> r = map_.insert( map_type::value_type( &cat, std::move( p ) ) );
i = r.first;
}
return *i->second;
}
}
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT

View File

@ -126,6 +126,7 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s
{
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, buffer, static_cast<int>( len ), NULL, NULL );
boost::winapi::LocalFree( lpMsgBuf );
if ( r != 0 ) --r; // exclude null terminator
}
}
@ -134,8 +135,6 @@ inline char const * system_category_message_win32( int ev, char * buffer, std::s
return unknown_message_win32( ev, buffer, len );
}
--r; // exclude null terminator
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
{
buffer[ --r ] = 0;
@ -265,6 +264,7 @@ inline error_condition system_category_default_error_condition_win32( int ev ) B
case ERROR_CANTOPEN_: return make_error_condition( io_error );
case ERROR_CANTREAD_: return make_error_condition( io_error );
case ERROR_CANTWRITE_: return make_error_condition( io_error );
case ERROR_CONNECTION_ABORTED_: return make_error_condition( connection_aborted );
case ERROR_CURRENT_DIRECTORY_: return make_error_condition( permission_denied );
case ERROR_DEV_NOT_EXIST_: return make_error_condition( no_such_device );
case ERROR_DEVICE_IN_USE_: return make_error_condition( device_or_resource_busy );

View File

@ -329,14 +329,17 @@ public:
namespace detail
{
template<class T> struct cat_holder
template<class T> struct BOOST_SYMBOL_VISIBLE cat_holder
{
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr system_error_category system_category_instance{};
BOOST_SYSTEM_REQUIRE_CONST_INIT static constexpr generic_error_category generic_category_instance{};
static constexpr system_error_category system_category_instance{};
static constexpr generic_error_category generic_category_instance{};
};
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr system_error_category cat_holder<T>::system_category_instance;
template<class T> BOOST_SYSTEM_REQUIRE_CONST_INIT constexpr generic_error_category cat_holder<T>::generic_category_instance;
// Before C++17 it was mandatory to redeclare all static constexpr
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template<class T> constexpr system_error_category cat_holder<T>::system_category_instance;
template<class T> constexpr generic_error_category cat_holder<T>::generic_category_instance;
#endif
} // namespace detail
@ -352,12 +355,16 @@ constexpr error_category const & generic_category() BOOST_NOEXCEPT
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
inline error_category const & system_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
inline error_category const & system_category() BOOST_NOEXCEPT
{
static const detail::system_error_category system_category_instance;
return system_category_instance;
}
inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
inline error_category const & generic_category() BOOST_NOEXCEPT
{
static const detail::generic_error_category generic_category_instance;
@ -780,7 +787,7 @@ inline std::size_t hash_value( error_code const & ec )
if( id == 0 )
{
id = reinterpret_cast<boost::ulong_long_type>( &cat );
id = reinterpret_cast<boost::uintptr_t>( &cat );
}
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;

View File

@ -10,11 +10,6 @@
import testing ;
lib throw_test : throw_test.cpp : <link>shared:<define>THROW_DYN_LINK=1 ;
lib single_instance_lib1 : single_instance_1.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
lib single_instance_lib2 : single_instance_2.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
rule system-run ( sources + )
{
local result ;
@ -32,6 +27,8 @@ system-run error_code_test.cpp ;
system-run error_code_user_test.cpp ;
system-run system_error_test.cpp ;
lib throw_test : throw_test.cpp : <link>shared:<define>THROW_DYN_LINK=1 ;
run dynamic_link_test.cpp throw_test : : : <link>shared : throw_test_shared ;
system-run initialization_test.cpp ;
@ -42,6 +39,9 @@ run config_test.cpp : : : <test-info>always_show_run_output ;
system-run std_interop_test.cpp ;
system-run std_mismatch_test.cpp ;
lib single_instance_lib1 : single_instance_1.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
lib single_instance_lib2 : single_instance_2.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
system-run single_instance_test.cpp single_instance_1.cpp single_instance_2.cpp ;
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>static : single_instance_lib_static ;
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ;
@ -62,3 +62,10 @@ system-run failed_constexpr_test.cpp ;
run quick.cpp ;
run warnings_test.cpp : : : <warnings>all <warnings-as-errors>on <toolset>gcc:<cxxflags>-Wnon-virtual-dtor <toolset>clang:<cxxflags>-Wnon-virtual-dtor ;
lib std_single_instance_lib1 : std_single_instance_1.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
lib std_single_instance_lib2 : std_single_instance_2.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
system-run std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>static : std_single_instance_lib_static ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared <define>STD_SINGLE_INSTANCE_SHARED : std_single_instance_lib_shared ;

View File

@ -197,7 +197,8 @@ int main( int, char ** )
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
// Fails when the language isn't US English
// BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );

View File

@ -0,0 +1,40 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(STD_SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
namespace lib1
{
EXPORT std::error_code get_system_code()
{
return boost::system::error_code( 0, boost::system::system_category() );
}
EXPORT std::error_code get_generic_code()
{
return boost::system::error_code( 0, boost::system::generic_category() );
}
} // namespace lib1
#else
EXPORT void lib1_f()
{
}
#endif

View File

@ -0,0 +1,40 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/config.hpp>
#if defined(STD_SINGLE_INSTANCE_DYN_LINK)
# define EXPORT BOOST_SYMBOL_EXPORT
#else
# define EXPORT
#endif
#include <boost/system/error_code.hpp>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
namespace lib2
{
EXPORT std::error_code get_system_code()
{
return boost::system::error_code( 0, boost::system::system_category() );
}
EXPORT std::error_code get_generic_code()
{
return boost::system::error_code( 0, boost::system::generic_category() );
}
} // namespace lib2
#else
EXPORT void lib2_f()
{
}
#endif

View File

@ -0,0 +1,76 @@
// Copyright 2019 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config/helper_macros.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(__CYGWIN__)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, __CYGWIN__" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_MSC_VER)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _MSC_VER" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && !defined(_CPPLIB_VER)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, no _CPPLIB_VER" )
int main() {}
#elif defined(STD_SINGLE_INSTANCE_SHARED) && defined(_WIN32) && (_MSC_VER < 1900 || _MSC_VER >= 2000)
BOOST_PRAGMA_MESSAGE( "Skipping Windows/DLL test, _MSC_VER is " BOOST_STRINGIZE(_MSC_VER) )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
#include <system_error>
using namespace boost::system;
namespace lib1
{
std::error_code get_system_code();
std::error_code get_generic_code();
} // namespace lib1
namespace lib2
{
std::error_code get_system_code();
std::error_code get_generic_code();
} // namespace lib2
int main()
{
{
std::error_code e1 = lib1::get_system_code();
std::error_code e2 = lib2::get_system_code();
BOOST_TEST_EQ( e1, e2 );
}
{
std::error_code e1 = lib1::get_generic_code();
std::error_code e2 = lib2::get_generic_code();
BOOST_TEST_EQ( e1, e2 );
}
return boost::report_errors();
}
#endif

View File

@ -18,6 +18,16 @@
//
#if defined(BOOST_WINDOWS_API) && defined(BOOST_SYSTEM_USE_UTF8)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE( "Skipping test due to BOOST_WINDOWS_API && BOOST_SYSTEM_USE_UTF8" )
int main() {}
#else
#if defined(BOOST_WINDOWS_API)
#include <windows.h>
@ -90,7 +100,7 @@ static void test_message( sys::error_category const & cat, int ev )
{
BOOST_TEST_EQ( cat.message( ev ), sys_strerror( ev ) );
char buffer[ 2048 ]; // yes, really
char buffer[ 4096 ]; // yes, really
BOOST_TEST_CSTR_EQ( cat.message( ev, buffer, sizeof( buffer ) ), sys_strerror( ev ).c_str() );
}
@ -100,17 +110,12 @@ int main()
// message
for( int i = -2; i < 1024; ++i )
{
test_message( cat, i );
}
test_message( cat, 5810 );
for( int i = 10000; i < 11032; ++i )
for( int i = -2; i < 16000; ++i )
{
test_message( cat, i );
}
return boost::report_errors();
}
#endif // #if defined(BOOST_WINDOWS_API) && defined(BOOST_SYSTEM_USE_UTF8)

View File

@ -37,7 +37,7 @@ namespace
BOOST_TEST( ex.code().category() == system_category() );
# ifdef BOOST_WINDOWS_API
LANGID language_id;
# if !defined(__MINGW32__) && !defined(__CYGWIN__) && !BOOST_PLAT_WINDOWS_RUNTIME
# if !BOOST_PLAT_WINDOWS_RUNTIME
language_id = ::GetUserDefaultUILanguage();
# else
language_id = 0x0409; // Assume US English