From 8d8e6a90dec37c771aff0ab7832f7e0ffa51403c Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 9 Feb 2022 20:41:34 +0200 Subject: [PATCH] Add an errc::make_error_code overload taking a source location --- include/boost/system/errc.hpp | 7 +++++++ test/CMakeLists.txt | 2 ++ test/Jamfile.v2 | 2 ++ test/errc_test4.cpp | 17 +++++++++++++++++ 4 files changed, 28 insertions(+) create mode 100644 test/errc_test4.cpp diff --git a/include/boost/system/errc.hpp b/include/boost/system/errc.hpp index ba70e26..0cdccbc 100644 --- a/include/boost/system/errc.hpp +++ b/include/boost/system/errc.hpp @@ -16,6 +16,7 @@ #include #include #include +#include #include namespace boost @@ -35,6 +36,12 @@ BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXC return error_code( e, generic_category() ); } +// explicit conversion: +inline error_code make_error_code( errc_t e, boost::source_location const* loc ) BOOST_NOEXCEPT +{ + return error_code( e, generic_category(), loc ); +} + // implicit conversion: BOOST_SYSTEM_CONSTEXPR inline error_condition make_error_condition( errc_t e ) BOOST_NOEXCEPT { diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7532ae7..122ade4 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -116,6 +116,8 @@ boost_test(TYPE run SOURCES ec_wstream_test.cpp) boost_test(TYPE run SOURCES std_interop_test12.cpp) +boost_test(TYPE run SOURCES errc_test4.cpp) + # result set(BOOST_TEST_COMPILE_FEATURES cxx_std_11) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 83def84..6dbe139 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -140,6 +140,8 @@ run ec_wstream_test.cpp ; run std_interop_test12.cpp ; +run errc_test4.cpp ; + # result import ../../config/checks/config : requires ; diff --git a/test/errc_test4.cpp b/test/errc_test4.cpp new file mode 100644 index 0000000..7401d2c --- /dev/null +++ b/test/errc_test4.cpp @@ -0,0 +1,17 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// http://www.boost.org/LICENSE_1_0.txt + +#include +#include +#include + +int main() +{ + BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION; + + BOOST_TEST( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).has_location() ); + BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).location().to_string(), loc.to_string() ); + + return boost::report_errors(); +}