From 85c7d9230236d5a0ccbd6808e110b7be09a2bf58 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Fri, 24 Sep 2021 15:24:45 +0300 Subject: [PATCH] Avoid instantiating the system category in error_code::operator std::error_code --- include/boost/system/detail/error_category_impl.hpp | 2 ++ include/boost/system/detail/error_code.hpp | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/boost/system/detail/error_category_impl.hpp b/include/boost/system/detail/error_category_impl.hpp index acb25de..af93c1a 100644 --- a/include/boost/system/detail/error_category_impl.hpp +++ b/include/boost/system/detail/error_category_impl.hpp @@ -107,6 +107,7 @@ inline error_category::operator std::error_category const & () const { if( id_ == detail::generic_category_id ) { +// This condition must be the same as the one in error_condition.hpp #if defined(BOOST_GCC) && BOOST_GCC < 50000 static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 ); @@ -121,6 +122,7 @@ inline error_category::operator std::error_category const & () const if( id_ == detail::system_category_id ) { +// This condition must be the same as the one in error_code.hpp #if defined(__CYGWIN__) || defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER == 1800) || (defined(BOOST_GCC) && BOOST_GCC < 50000) // Under Cygwin (and MinGW!), std::system_category() is POSIX diff --git a/include/boost/system/detail/error_code.hpp b/include/boost/system/detail/error_code.hpp index 6f4adef..847c895 100644 --- a/include/boost/system/detail/error_code.hpp +++ b/include/boost/system/detail/error_code.hpp @@ -504,8 +504,16 @@ public: } else if( lc_flags_ == 0 ) { - //return std::error_code(); +// This condition must be the same as the one in error_category_impl.hpp +#if defined(__CYGWIN__) || defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER == 1800) || (defined(BOOST_GCC) && BOOST_GCC < 50000) + return std::error_code( 0, boost::system::system_category() ); + +#else + + return std::error_code(); + +#endif } else {