From 035248cefb7ba327b230f406c2a19e59649d8408 Mon Sep 17 00:00:00 2001 From: "Paul \"TBBle\" Hampson" Date: Mon, 8 Jan 2018 12:50:14 +1100 Subject: [PATCH] Use make_error_code for setting an error_code from errc: In Boost.System, `boost::system::errc` is a namespace containing ints. In C++11, std::errc is an enum marked as an `error_condition`. `error_code::assign` is specified as taking an int only, while make_error_code is able to deal correctly with both forms. --- CHANGELOG.md | 1 + include/boost/beast/core/impl/file_posix.ipp | 10 +++++----- include/boost/beast/core/impl/file_stdio.ipp | 10 +++++----- include/boost/beast/core/impl/file_win32.ipp | 10 +++++----- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0e674db3..0d280b42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 153: * Remove BOOST_VERSION checks +* Use make_error_code for setting an error_code from errc -------------------------------------------------------------------------------- diff --git a/include/boost/beast/core/impl/file_posix.ipp b/include/boost/beast/core/impl/file_posix.ipp index 96ccdc3b..c30a7d02 100644 --- a/include/boost/beast/core/impl/file_posix.ipp +++ b/include/boost/beast/core/impl/file_posix.ipp @@ -224,7 +224,7 @@ size(error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } struct stat st; @@ -244,7 +244,7 @@ pos(error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto const result = ::lseek(fd_, 0, SEEK_CUR); @@ -264,7 +264,7 @@ seek(std::uint64_t offset, error_code& ec) { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } auto const result = ::lseek(fd_, offset, SEEK_SET); @@ -283,7 +283,7 @@ read(void* buffer, std::size_t n, error_code& ec) const { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nread = 0; @@ -319,7 +319,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(fd_ == -1) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nwritten = 0; diff --git a/include/boost/beast/core/impl/file_stdio.ipp b/include/boost/beast/core/impl/file_stdio.ipp index ca5cb0cb..60a0f3fc 100644 --- a/include/boost/beast/core/impl/file_stdio.ipp +++ b/include/boost/beast/core/impl/file_stdio.ipp @@ -122,7 +122,7 @@ size(error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } long pos = std::ftell(f_); @@ -159,7 +159,7 @@ pos(error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } long pos = std::ftell(f_); @@ -179,7 +179,7 @@ seek(std::uint64_t offset, error_code& ec) { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } if(offset > (std::numeric_limits::max)()) @@ -202,7 +202,7 @@ read(void* buffer, std::size_t n, error_code& ec) const { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto nread = std::fread(buffer, 1, n, f_); @@ -221,7 +221,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(! f_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } auto nwritten = std::fwrite(buffer, 1, n, f_); diff --git a/include/boost/beast/core/impl/file_win32.ipp b/include/boost/beast/core/impl/file_win32.ipp index de4abae4..ad7f255e 100644 --- a/include/boost/beast/core/impl/file_win32.ipp +++ b/include/boost/beast/core/impl/file_win32.ipp @@ -216,7 +216,7 @@ size(error_code& ec) const { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } boost::winapi::LARGE_INTEGER_ fileSize; @@ -237,7 +237,7 @@ pos(error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } boost::winapi::LARGE_INTEGER_ in; @@ -261,7 +261,7 @@ seek(std::uint64_t offset, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return; } boost::winapi::LARGE_INTEGER_ in; @@ -283,7 +283,7 @@ read(void* buffer, std::size_t n, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nread = 0; @@ -324,7 +324,7 @@ write(void const* buffer, std::size_t n, error_code& ec) { if(h_ == boost::winapi::INVALID_HANDLE_VALUE_) { - ec.assign(errc::invalid_argument, generic_category()); + ec = make_error_code(errc::invalid_argument); return 0; } std::size_t nwritten = 0;