From 4ec1e54099ff5f3d4e6533b9849af03d9a82a171 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 11 Oct 2021 02:02:22 +0300 Subject: [PATCH] Enable error_code construction from enums specializing std::is_error_code_enum. Fixes #70. --- include/boost/system/detail/error_code.hpp | 8 +++-- test/CMakeLists.txt | 2 ++ test/Jamfile.v2 | 2 ++ test/std_interop_test11.cpp | 42 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 test/std_interop_test11.cpp diff --git a/include/boost/system/detail/error_code.hpp b/include/boost/system/detail/error_code.hpp index 494167c..1f0ac5d 100644 --- a/include/boost/system/detail/error_code.hpp +++ b/include/boost/system/detail/error_code.hpp @@ -107,8 +107,12 @@ public: } template BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e, - typename detail::enable_if::value>::type* = 0 ) BOOST_NOEXCEPT: - d1_(), lc_flags_( 0 ) + typename detail::enable_if< + is_error_code_enum::value +#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR) + || std::is_error_code_enum::value +#endif + >::type* = 0 ) BOOST_NOEXCEPT: d1_(), lc_flags_( 0 ) { *this = make_error_code( e ); } diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6f8e34c..758b560 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -110,6 +110,8 @@ boost_test(TYPE run SOURCES ec_location_test2.cpp) boost_test(TYPE run SOURCES ec_what_test.cpp) boost_test(TYPE run SOURCES system_error_test3.cpp) +boost_test(TYPE run SOURCES std_interop_test11.cpp) + # result set(BOOST_TEST_COMPILE_FEATURES cxx_std_11) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 77ec80d..0a6bc3e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -132,6 +132,8 @@ run ec_location_test2.cpp ; run ec_what_test.cpp ; run system_error_test3.cpp ; +run std_interop_test11.cpp ; + # result import ../../config/checks/config : requires ; diff --git a/test/std_interop_test11.cpp b/test/std_interop_test11.cpp new file mode 100644 index 0000000..144f1c1 --- /dev/null +++ b/test/std_interop_test11.cpp @@ -0,0 +1,42 @@ +// Copyright 2021 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include +#include +#include + +#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR) + +BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" ) +int main() {} + +#else + +#include + +int main() +{ + { + boost::system::error_code ec = std::io_errc::stream; + + BOOST_TEST( ec == std::io_errc::stream ); + BOOST_TEST_NOT( ec != std::io_errc::stream ); + + ec.clear(); + + BOOST_TEST_NOT( ec == std::io_errc::stream ); + BOOST_TEST( ec != std::io_errc::stream ); + + ec = std::io_errc::stream; + + BOOST_TEST( ec == std::io_errc::stream ); + BOOST_TEST_NOT( ec != std::io_errc::stream ); + } + + return boost::report_errors(); +} + +#endif