diff --git a/include/boost/system/detail/error_category_impl.hpp b/include/boost/system/detail/error_category_impl.hpp index 904a3a6..0c4593f 100644 --- a/include/boost/system/detail/error_category_impl.hpp +++ b/include/boost/system/detail/error_category_impl.hpp @@ -143,7 +143,7 @@ inline void error_category::init_stdcat() const if( sc_init_.load( std::memory_order_acquire ) == 0 ) { - ::new( static_cast( stdcat_ ) ) boost::system::detail::std_category( this, 0 ); + ::new( static_cast( stdcat_ ) ) boost::system::detail::std_category( this, system::detail::id_wrapper<0>() ); sc_init_.store( 1, std::memory_order_release ); } } @@ -160,7 +160,7 @@ inline BOOST_NOINLINE error_category::operator std::error_category const & () co // This condition must be the same as the one in error_condition.hpp #if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY) - static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 ); + static const boost::system::detail::std_category generic_instance( this, system::detail::id_wrapper<0x1F4D3>() ); return generic_instance; #else @@ -175,7 +175,7 @@ inline BOOST_NOINLINE error_category::operator std::error_category const & () co // This condition must be the same as the one in error_code.hpp #if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY) - static const boost::system::detail::std_category system_instance( this, 0x1F4D7 ); + static const boost::system::detail::std_category system_instance( this, system::detail::id_wrapper<0x1F4D7>() ); return system_instance; #else diff --git a/include/boost/system/detail/std_category.hpp b/include/boost/system/detail/std_category.hpp index 2b98aa7..68073c1 100644 --- a/include/boost/system/detail/std_category.hpp +++ b/include/boost/system/detail/std_category.hpp @@ -11,6 +11,7 @@ // See library home page at http://www.boost.org/libs/system #include +#include #include // @@ -24,6 +25,8 @@ namespace system namespace detail { +template struct id_wrapper {}; + class BOOST_SYMBOL_VISIBLE std_category: public std::error_category { private: @@ -39,20 +42,22 @@ public: public: - explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc ) + template + explicit std_category( boost::system::error_category const * pc, id_wrapper ): 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 + // We used to assign to the protected _Addr member of std::error_category + // here when Id != 0, but this should never happen now because this code + // path is no longer used - _Addr = id; +#if !defined(BOOST_NO_CXX11_STATIC_ASSERT) + + static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" ); + +#endif #endif - } } const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE