Compare commits

..

56 Commits

Author SHA1 Message Date
648a35838b Remove unnecessary overloads 2022-05-05 05:12:08 +03:00
256fe92dbb Add error_code(error_code const& ec, source_location const* loc) and a corresponding assign 2022-05-05 05:02:37 +03:00
5debb8a041 Update revision history 2022-05-05 02:30:07 +03:00
a97e5a0546 Move BOOST_NOINLINE to operator std::error_category 2022-04-22 22:41:26 +03:00
dc17edfa07 Remove clang-win from appveyor.yml 2022-04-22 21:16:09 +03:00
65da7dfd56 Update result_error_construct tests to use sys::error_code instead of (erroneously) std::error_code 2022-04-22 19:52:19 +03:00
9279001b8c Check BOOST_NO_CXX11_HDR_MUTEX when enabling <system_error> integration 2022-04-22 16:49:03 +03:00
616e652bd7 Suppress strict-aliasing warning for gcc 4.8 to 6 2022-04-21 21:06:14 +03:00
98439855bd Use static_cast instead of reinterpret_cast 2022-04-21 20:52:02 +03:00
986efb1420 Rework conversion to std::error_category to not allocate (closes #78) 2022-04-21 20:32:25 +03:00
28a13571b9 Restore the original system::error_code from std::error_code (refs #79) 2022-03-18 18:24:01 +02:00
65ed1eef66 Add std_interop_test14.cpp (refs #79) 2022-03-18 08:12:05 +02:00
6de20eeebc Add std_interop_test13 2022-03-18 08:12:05 +02:00
0a9266ea7e Add a comment explaining the one-time allocation in error_category_impl.hpp. Fixes #78. 2022-03-18 08:11:16 +02:00
adb9fc54cb Remove msvc-14.1 from ci.yml 2022-03-18 07:51:38 +02:00
e197c5e803 Update documentation 2022-02-18 19:43:08 +02:00
6d7a57a970 Add throw_exception_from_error overload for std::exception_ptr 2022-02-18 02:55:34 +02:00
00c71cf388 Add throw_exception_from_error overloads for boost::system::errc, std::errc 2022-02-17 21:55:47 +02:00
d930cea481 Update documentation 2022-02-14 02:05:44 +02:00
4f09f4adde Use throw_with_location in throw_exception_from_error 2022-02-13 22:50:20 +02:00
abd62362ef Update documentation 2022-02-09 20:52:23 +02:00
8d8e6a90de Add an errc::make_error_code overload taking a source location 2022-02-09 20:41:34 +02:00
716c2ed8ef Disable result tests on GCC 4.7 2022-02-07 21:40:26 +02:00
46a5ecd490 Do not include boost/system/result.hpp on GCC 4.7 2022-02-07 21:38:14 +02:00
79f4ef0416 Remove .drone.star 2022-02-07 21:34:11 +02:00
d0a8f7fbb7 Squash-merge feature/drone-jsonnet into develop 2022-02-07 21:33:48 +02:00
bc07ab1e25 Update .drone.star 2022-02-07 05:09:49 +02:00
c6bff94709 Update std_interop_test12.cpp 2022-02-07 04:35:44 +02:00
ae079810be Add std_interop_test12.cpp 2022-02-07 04:30:50 +02:00
928de55563 Update .drone.star 2022-02-07 03:47:42 +02:00
442138de0a Update .drone.star 2022-02-07 03:41:35 +02:00
de610efd53 Move conditions to detail/config.hpp 2022-02-07 03:16:23 +02:00
4b143cdacc Use BOOST_LIBSTDCXX_VERSION instead of BOOST_GCC; update syscat condition 2022-02-07 03:02:57 +02:00
a1cb578f52 Update .drone.star 2022-02-07 02:55:54 +02:00
96b5073b79 Update .drone.star 2022-02-07 02:03:13 +02:00
2bff5c7071 Update .drone.star 2022-02-07 01:27:59 +02:00
137128176d Update .drone.star 2022-02-07 01:14:28 +02:00
e0e0f56eae Update .drone.star 2022-02-07 00:54:07 +02:00
58d55a67e5 Update .drone.star 2022-02-07 00:01:53 +02:00
34dcb59ee8 Update drone.bat 2022-02-06 23:30:19 +02:00
33f6ecba31 Update Drone files 2022-02-06 23:21:40 +02:00
23fbfb1ffa Update .drone.star 2022-02-06 22:55:48 +02:00
5366407135 Add Windows jobs to Drone 2022-02-06 22:42:19 +02:00
72a79b1dcb Disable -Wsign-compare for GCC 4.4 2022-02-06 22:29:28 +02:00
a5c1ab042e Update Drone files 2022-02-06 22:25:45 +02:00
c2beb75d66 Merge pull request #59 from sdarwin/drone
Drone config
2022-02-06 22:08:07 +02:00
54d9f4f38a Update documentation 2022-02-05 19:25:43 +02:00
b92be6417a Add a source_location parameter to throw_exception_from_error 2022-02-05 05:24:29 +02:00
245fff8af3 Update ci.yml 2022-02-05 03:11:09 +02:00
c359af3141 Update system_error constructors 2022-02-04 21:34:14 +02:00
50cad72fac Update system_error_test3.cpp 2022-02-04 21:22:35 +02:00
9554d8bbd3 Suppress incorrect warnings from GCC 7/8 2022-02-03 19:02:19 +02:00
cf9d986871 Update documentation 2022-02-03 18:47:53 +02:00
a5d68e52e6 Add throw_exception_from_error overload for std::error_code 2022-02-03 18:35:42 +02:00
9c6a09f41d Mark throw_exception_from_error as noinline 2022-02-03 09:37:59 +02:00
a688d7834a add drone config [ci skip] 2021-01-21 19:45:47 +00:00
31 changed files with 1434 additions and 219 deletions

253
.drone.jsonnet Normal file
View File

@ -0,0 +1,253 @@
# Copyright 2022 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
local library = "system";
local triggers =
{
branch: [ "master", "develop", "feature/*" ]
};
local ubsan = { UBSAN: '1', UBSAN_OPTIONS: 'print_stacktrace=1' };
local asan = { ASAN: '1' };
local linux_pipeline(name, image, environment, packages = "", sources = [], arch = "amd64") =
{
name: name,
kind: "pipeline",
type: "docker",
trigger: triggers,
platform:
{
os: "linux",
arch: arch
},
steps:
[
{
name: "everything",
image: image,
environment: environment,
commands:
[
'set -e',
'wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -',
] +
(if sources != [] then [ ('apt-add-repository "' + source + '"') for source in sources ] else []) +
(if packages != "" then [ 'apt-get update', 'apt-get -y install ' + packages ] else []) +
[
'export LIBRARY=' + library,
'./.drone/drone.sh',
]
}
]
};
local macos_pipeline(name, environment, xcode_version = "12.2", osx_version = "catalina", arch = "amd64") =
{
name: name,
kind: "pipeline",
type: "exec",
trigger: triggers,
platform: {
"os": "darwin",
"arch": arch
},
node: {
"os": osx_version
},
steps: [
{
name: "everything",
environment: environment + { "DEVELOPER_DIR": "/Applications/Xcode-" + xcode_version + ".app/Contents/Developer" },
commands:
[
'export LIBRARY=' + library,
'./.drone/drone.sh',
]
}
]
};
local windows_pipeline(name, image, environment, arch = "amd64") =
{
name: name,
kind: "pipeline",
type: "docker",
trigger: triggers,
platform:
{
os: "windows",
arch: arch
},
"steps":
[
{
name: "everything",
image: image,
environment: environment,
commands:
[
'cmd /C .drone\\\\drone.bat ' + library,
]
}
]
};
[
linux_pipeline(
"Linux 14.04 GCC 4.4",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.4', CXXSTD: '98,0x' },
"g++-4.4",
[ "ppa:ubuntu-toolchain-r/test" ],
),
linux_pipeline(
"Linux 14.04 GCC 4.6",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.6', CXXSTD: '98,0x' },
"g++-4.6",
[ "ppa:ubuntu-toolchain-r/test" ],
),
linux_pipeline(
"Linux 14.04 GCC 4.7",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.7', CXXSTD: '98,0x' },
"g++-4.7",
[ "ppa:ubuntu-toolchain-r/test" ],
),
linux_pipeline(
"Linux 14.04 GCC 4.8*",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11' },
),
linux_pipeline(
"Linux 14.04 GCC 4.9",
"cppalliance/droneubuntu1404:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-4.9', CXXSTD: '03,11' },
"g++-4.9",
[ "ppa:ubuntu-toolchain-r/test" ],
),
linux_pipeline(
"Linux 16.04 GCC 5*",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14' },
),
linux_pipeline(
"Linux 18.04 GCC 6",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-6', CXXSTD: '03,11,14' },
"g++-6",
),
linux_pipeline(
"Linux 18.04 GCC 7* 32/64",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17', ADDRMD: '32,64' },
),
linux_pipeline(
"Linux 18.04 GCC 8",
"cppalliance/droneubuntu1804:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-8', CXXSTD: '03,11,14,17' },
"g++-8",
),
linux_pipeline(
"Linux 20.04 GCC 9* 32",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32' },
),
linux_pipeline(
"Linux 20.04 GCC 9* 64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '64' },
),
linux_pipeline(
"Linux 20.04 GCC 9 ARM64 32/64",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32,64' },
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 10 32 ASAN",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32' } + asan,
"g++-10-multilib",
),
linux_pipeline(
"Linux 20.04 GCC 10 64 ASAN",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '64' } + asan,
"g++-10-multilib",
),
linux_pipeline(
"Linux 20.04 Clang 13",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' },
"clang-13",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-13 main"],
),
linux_pipeline(
"Linux 20.04 Clang 14 UBSAN",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + ubsan,
"clang-14",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"],
),
linux_pipeline(
"Linux 20.04 Clang 14 ASAN",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + asan,
"clang-14",
["deb http://apt.llvm.org/focal/ llvm-toolchain-focal-14 main"],
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 UBSAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + ubsan,
),
macos_pipeline(
"MacOS 10.15 Xcode 12.2 ASAN",
{ TOOLSET: 'clang', COMPILER: 'clang++', CXXSTD: '03,11,14,1z' } + asan,
),
windows_pipeline(
"Windows VS2015 msvc-14.0",
"cppalliance/dronevs2015",
{ TOOLSET: 'msvc-14.0', CXXSTD: '14,latest' },
),
windows_pipeline(
"Windows VS2017 msvc-14.1",
"cppalliance/dronevs2017",
{ TOOLSET: 'msvc-14.1', CXXSTD: '14,17,latest' },
),
windows_pipeline(
"Windows VS2019 msvc-14.2",
"cppalliance/dronevs2019",
{ TOOLSET: 'msvc-14.2', CXXSTD: '14,17,20,latest' },
),
windows_pipeline(
"Windows VS2022 msvc-14.3",
"cppalliance/dronevs2022:1",
{ TOOLSET: 'msvc-14.3', CXXSTD: '14,17,20,latest' },
),
]

23
.drone/drone.bat Normal file
View File

@ -0,0 +1,23 @@
@REM Copyright 2022 Peter Dimov
@REM Distributed under the Boost Software License, Version 1.0.
@REM https://www.boost.org/LICENSE_1_0.txt
@ECHO ON
set LIBRARY=%1
set DRONE_BUILD_DIR=%CD%
set BOOST_BRANCH=develop
if "%DRONE_BRANCH%" == "master" set BOOST_BRANCH=master
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
git submodule update --init tools/boostdep
xcopy /s /e /q %DRONE_BUILD_DIR% libs\%LIBRARY%\
python tools/boostdep/depinst/depinst.py %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker

24
.drone/drone.sh Executable file
View File

@ -0,0 +1,24 @@
#!/bin/bash
# Copyright 2022 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
set -ex
DRONE_BUILD_DIR=$(pwd)
BOOST_BRANCH=develop
if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
git submodule update --init tools/boostdep
cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY
python tools/boostdep/depinst/depinst.py $LIBRARY
./bootstrap.sh
./b2 -d0 headers
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
./b2 -j3 libs/$LIBRARY/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+undefined-sanitizer=norecover debug-symbols=on} ${ASAN:+address-sanitizer=norecover debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}

View File

@ -148,15 +148,15 @@ jobs:
cxxstd: "14"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.1
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2016
- toolset: msvc-14.2
cxxstd: "14,17,latest"
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: clang-win
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
@ -196,7 +196,7 @@ jobs:
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
posix-cmake-subdir:
strategy:

View File

@ -24,10 +24,6 @@ environment:
TOOLSET: msvc-14.1
CXXSTD: 14,17,latest
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
TOOLSET: clang-win
CXXSTD: 14,17,latest
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc

View File

@ -1,5 +1,5 @@
////
Copyright 2018-2021 Peter Dimov
Copyright 2018-2022 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////
@ -8,6 +8,22 @@ https://www.boost.org/LICENSE_1_0.txt
# Revision History
:idprefix:
## Changes in Boost 1.80
* When an `error_code` is converted to `std::error_code` and then back
to `error_code`, the original is now restored, if possible.
* Reworked the conversion from `error_category` to `std::error_category`
to avoid the one-time allocation that shows up on leak checkers.
## Changes in Boost 1.79
* Added a `boost::source_location` parameter to `throw_exception_from_error`.
* Added `throw_exception_from_error` overloads for `errc::errc_t`,
`std::error_code`, `std::errc`, `std::exception_ptr`.
* `result<T>::value` now automatically supplies `BOOST_CURRENT_LOCATION` to
`throw_exception_from_error` via a default argument.
* Added an `errc::make_error_code` overload taking a source location.
## Changes in Boost 1.78
* Added support for source locations to `error_code`.

View File

@ -14,6 +14,6 @@ http://www.boost.org/LICENSE_1_0.txt
This documentation is
* Copyright 2003-2017 Beman Dawes
* Copyright 2018-2021 Peter Dimov
* Copyright 2018-2022 Peter Dimov
and is distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].

View File

@ -1,6 +1,6 @@
////
Copyright 2003-2017 Beman Dawes
Copyright 2018-2021 Peter Dimov
Copyright 2018-2022 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
@ -185,9 +185,13 @@ namespace errc {
template<> struct is_error_condition_enum<errc::errc_t>
{ static const bool value = true; };
constexpr error_code make_error_code( errc::errc_t e ) noexcept;
constexpr error_condition make_error_condition( errc::errc_t e ) noexcept;
constexpr error_code make_error_code( errc::errc_t e ) noexcept;
error_code make_error_code( errc::errc_t e,
boost::source_location const * loc ) noexcept;
} // namespace system
} // namespace boost
```
@ -256,6 +260,38 @@ void my_api_function( boost::system::error_code& ec )
}
```
```
constexpr error_code make_error_code( errc::errc_t e,
boost::source_location const * loc ) noexcept;
```
[none]
* {blank}
+
Returns: :: `error_code( e, generic_category(), loc )`.
Same as the above overload, but takes a source location.
* {blank}
+
```
void my_api_function( boost::system::error_code& ec )
{
void* p = std::malloc( 16 );
if( p == 0 )
{
// return ENOMEM
BOOST_STATIC_CONSTEXPR boost::source_location loc =
BOOST_CURRENT_LOCATION;
ec = make_error_code( boost::system::errc::out_of_memory, &loc );
return;
}
// use p
}
```
## <boost/system/{zwsp}error_category.hpp>
### error_category
@ -1454,7 +1490,20 @@ namespace system {
// throw_exception_from_error
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e );
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
boost::source_location const & loc );
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
boost::source_location const & loc );
BOOST_NORETURN inline void throw_exception_from_error( errc::errc_t const & e,
boost::source_location const & loc );
BOOST_NORETURN inline void throw_exception_from_error( std::errc const & e,
boost::source_location const & loc );
BOOST_NORETURN inline void throw_exception_from_error( std::exception_ptr & e,
boost::source_location const & loc );
// in_place_*
@ -1486,13 +1535,57 @@ If `result<T, E>` is used with other error types, the user is expected to provid
an appropriate overload of `throw_exception_from_error` in the namespace of `E`.
```
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e );
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
boost::source_location const & loc );
```
[none]
* {blank}
+
Effects: ::
`boost::throw_exception( system_error( e ) )`.
`boost::throw_with_location( system_error( e ), loc )`.
```
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
boost::source_location const & loc );
```
[none]
* {blank}
+
Effects: ::
`boost::throw_with_location( std::system_error( e ), loc )`.
```
BOOST_NORETURN inline void throw_exception_from_error( errc::errc_t const & e,
boost::source_location const & loc );
```
[none]
* {blank}
+
Effects: ::
`boost::throw_with_location( system_error( make_error_code( e ) ), loc )`.
```
BOOST_NORETURN inline void throw_exception_from_error( std::errc const & e,
boost::source_location const & loc );
```
[none]
* {blank}
+
Effects: ::
`boost::throw_with_location( std::system_error( make_error_code( e ) ), loc )`.
```
BOOST_NORETURN inline void throw_exception_from_error( std::exception_ptr & e,
boost::source_location const & loc );
```
[none]
* {blank}
+
Effects: ::
+
[disc]
** If `e` isn't null, `std::rethrow_exception( e )`.
** Otherwise, `boost::throw_with_location( std::bad_exception(), loc )`.
### result<T, E>
@ -1528,10 +1621,17 @@ public:
// checked value access
constexpr T& value() & ;
constexpr T const& value() const& ;
constexpr T&& value() && ;
constexpr T const&& value() const&& ;
constexpr T& value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) & ;
constexpr T const& value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) const& ;
constexpr T&& value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) && ;
constexpr T const&& value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) const&& ;
// unchecked value access
@ -1653,10 +1753,17 @@ Returns: ::
#### Checked Value Access
```
constexpr T& value() & ;
constexpr T const& value() const& ;
constexpr T&& value() && ;
constexpr T const&& value() const&& ;
constexpr T& value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) & ;
constexpr T const& value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const& ;
constexpr T&& value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) && ;
constexpr T const&& value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const&& ;
```
[none]
* {blank}
@ -1664,7 +1771,7 @@ constexpr T const&& value() const&& ;
Effects: ::
If `*this` holds a value, returns a reference to it. Otherwise,
calls `throw_exception_from_error`, passing it a reference to
the held error.
the held error, and `loc`.
#### Unchecked Value Access
@ -1799,7 +1906,8 @@ public:
// checked value access
constexpr void value() const;
constexpr void value( boost::source_location const & loc =
BOOST_CURRENT_LOCATION ) const;
// unchecked value access
@ -1912,14 +2020,15 @@ Returns: ::
#### Checked Value Access
```
constexpr void value() const;
constexpr void value(
boost::source_location const & loc = BOOST_CURRENT_LOCATION ) const;
```
[none]
* {blank}
+
Effects: ::
If `*this` doesn't hold a value, calls `throw_exception_from_error`,
passing it a reference to the held error.
passing it a reference to the held error, and `loc`.
#### Unchecked Value Access

View File

@ -9,8 +9,9 @@
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/config.hpp>
#if (__cplusplus >= 201103L) || (defined(_MSC_VER) && _MSC_VER >= 1900)
#if (__cplusplus >= 201103L) && !(defined(BOOST_GCC) && BOOST_GCC < 40800) || (defined(_MSC_VER) && _MSC_VER >= 1900)
# include <boost/system/result.hpp>
#endif

View File

@ -1,7 +1,7 @@
#ifndef BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
// Copyright 2018 Peter Dimov
// Copyright 2018-2022 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -13,7 +13,7 @@
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC)
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_NO_CXX11_HDR_MUTEX)
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
@ -62,4 +62,20 @@
# define BOOST_SYSTEM_CLANG_6
#endif
//
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000
# define BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER == 1800) || (defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 90000)
// Under Cygwin (and MinGW!), std::system_category() is POSIX
// Under VS2013, std::system_category() isn't quite right
// Under libstdc++ before 7.4, before 8.3, before 9.1, default_error_condition
// for the system category returns a condition from the system category
# define BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY
#endif
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED

View File

@ -48,6 +48,11 @@ class std_category;
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
#if defined(BOOST_MSVC)
#pragma warning(push)
#pragma warning(disable: 4351) // new behavior: elements of array will be default initialized
#endif
class BOOST_SYMBOL_VISIBLE error_category
{
private:
@ -76,13 +81,21 @@ private:
boost::ulong_long_type id_;
static std::size_t const stdcat_size_ = 4 * sizeof( void const* );
union
{
mutable unsigned char stdcat_[ stdcat_size_ ];
void const* stdcat_align_;
};
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
mutable std::atomic< boost::system::detail::std_category* > ps_;
mutable std::atomic< unsigned > sc_init_;
#else
boost::system::detail::std_category* ps_;
unsigned sc_init_;
#endif
@ -103,11 +116,11 @@ protected:
#endif
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), ps_()
BOOST_SYSTEM_CONSTEXPR error_category() BOOST_NOEXCEPT: id_( 0 ), stdcat_(), sc_init_()
{
}
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), ps_()
explicit BOOST_SYSTEM_CONSTEXPR error_category( boost::ulong_long_type id ) BOOST_NOEXCEPT: id_( id ), stdcat_(), sc_init_()
{
}
@ -158,14 +171,22 @@ public:
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
void init_stdcat() const;
# if defined(__SUNPRO_CC) // trailing __global is not supported
operator std::error_category const & () const;
# else
operator std::error_category const & () const BOOST_SYMBOL_VISIBLE;
# endif
#endif
};
#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif

View File

@ -14,6 +14,7 @@
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/snprintf.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
#include <string>
#include <cstring>
@ -96,26 +97,66 @@ inline char const * error_category::message( int ev, char * buffer, std::size_t
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <boost/system/detail/std_category.hpp>
#include <boost/system/detail/std_category_impl.hpp>
#include <mutex>
#include <new>
namespace boost
{
namespace system
{
inline error_category::operator std::error_category const & () const
namespace detail
{
template<class = void> struct stdcat_mx_holder
{
static std::mutex mx_;
};
template<class T> std::mutex stdcat_mx_holder<T>::mx_;
} // namespace detail
inline void error_category::init_stdcat() const
{
static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" );
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
// no alignof
#else
static_assert( alignof( decltype(stdcat_align_) ) >= alignof( boost::system::detail::std_category ), "alignof(stdcat_) is not enough for std_category" );
#endif
std::lock_guard<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, 0 );
sc_init_.store( 1, std::memory_order_release );
}
}
#if defined( BOOST_GCC ) && BOOST_GCC >= 40800 && BOOST_GCC < 70000
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
inline BOOST_NOINLINE 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
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
return generic_instance;
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
return generic_instance;
#else
return std::generic_category();
return std::generic_category();
#endif
}
@ -123,41 +164,30 @@ 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)
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
// Under Cygwin (and MinGW!), std::system_category() is POSIX
// Under VS2013, std::system_category() isn't quite right
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
return system_instance;
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
return system_instance;
#else
return std::system_category();
return std::system_category();
#endif
}
detail::std_category* p = ps_.load( std::memory_order_acquire );
if( p != 0 )
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
return *p;
init_stdcat();
}
detail::std_category* q = new detail::std_category( this, 0 );
if( ps_.compare_exchange_strong( p, q, std::memory_order_release, std::memory_order_acquire ) )
{
return *q;
}
else
{
delete q;
return *p;
}
return *static_cast<boost::system::detail::std_category const*>( static_cast<void const*>( stdcat_ ) );
}
#if defined( BOOST_GCC ) && BOOST_GCC >= 40800 && BOOST_GCC < 70000
#pragma GCC diagnostic pop
#endif
} // namespace system
} // namespace boost

View File

@ -21,6 +21,11 @@
#include <boost/system/detail/append_int.hpp>
#include <boost/system/detail/snprintf.hpp>
#include <boost/system/detail/config.hpp>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <boost/system/detail/std_category.hpp>
#endif
#include <boost/assert/source_location.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
@ -139,28 +144,35 @@ public:
*this = make_error_code( e );
}
template<class ErrorCodeEnum> error_code( ErrorCodeEnum e, source_location const * loc,
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value>::type* = 0 ) BOOST_NOEXCEPT:
error_code( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
error_code e2 = make_error_code( e );
*this = ec;
if( e2.lc_flags_ == 0 || e2.lc_flags_ == 1 )
if( ec.lc_flags_ != 0 && ec.lc_flags_ != 1 )
{
*this = e2;
}
else
{
*this = error_code( e2.d1_.val_, *e2.d1_.cat_, loc );
lc_flags_ = ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | ( ec.lc_flags_ & 1 );
}
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
error_code( std::error_code const& ec ) BOOST_NOEXCEPT:
lc_flags_( 1 )
d1_(), lc_flags_( 0 )
{
::new( d2_ ) std::error_code( ec );
#ifndef BOOST_NO_RTTI
if( detail::std_category const* pc2 = dynamic_cast< detail::std_category const* >( &ec.category() ) )
{
*this = boost::system::error_code( ec.value(), pc2->original_category() );
}
else
#endif
{
::new( d2_ ) std::error_code( ec );
lc_flags_ = 1;
}
}
#endif
@ -177,6 +189,11 @@ public:
*this = error_code( val, cat, loc );
}
void assign( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT
{
*this = error_code( ec, loc );
}
template<typename ErrorCodeEnum>
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, error_code>::type &
operator=( ErrorCodeEnum val ) BOOST_NOEXCEPT
@ -185,13 +202,6 @@ public:
return *this;
}
template<typename ErrorCodeEnum>
typename detail::enable_if<is_error_code_enum<ErrorCodeEnum>::value, void>::type
assign( ErrorCodeEnum val, source_location const * loc ) BOOST_NOEXCEPT
{
*this = error_code( val, loc );
}
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
{
*this = error_code();
@ -575,7 +585,7 @@ public:
else if( lc_flags_ == 0 )
{
// 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)
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
return std::error_code( 0, boost::system::system_category() );

View File

@ -223,7 +223,7 @@ public:
operator std::error_condition () const
{
// This condition must be the same as the one in error_category_impl.hpp
#if defined(BOOST_GCC) && BOOST_GCC < 50000
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
return std::error_condition( value(), category() );

View File

@ -11,9 +11,6 @@
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/error_category.hpp>
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/generic_category.hpp>
#include <system_error>
//
@ -33,6 +30,13 @@ private:
boost::system::error_category const * pc_;
public:
boost::system::error_category const & original_category() const BOOST_NOEXCEPT
{
return *pc_;
}
public:
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
@ -66,72 +70,10 @@ public:
return pc_->default_error_condition( ev );
}
bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
inline bool equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
inline bool equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
};
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
{
if( condition.category() == *this )
{
boost::system::error_condition bn( condition.value(), *pc_ );
return pc_->equivalent( code, bn );
}
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
{
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
return pc_->equivalent( code, bn );
}
#ifndef BOOST_NO_RTTI
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
{
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
return pc_->equivalent( code, bn );
}
#endif
else
{
return default_error_condition( code ) == condition;
}
}
inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
{
if( code.category() == *this )
{
boost::system::error_code bc( code.value(), *pc_ );
return pc_->equivalent( bc, condition );
}
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
{
boost::system::error_code bc( code.value(), boost::system::generic_category() );
return pc_->equivalent( bc, condition );
}
#ifndef BOOST_NO_RTTI
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
{
boost::system::error_code bc( code.value(), *pc2->pc_ );
return pc_->equivalent( bc, condition );
}
#endif
else if( *pc_ == boost::system::generic_category() )
{
return std::generic_category().equivalent( code, condition );
}
else
{
return false;
}
}
} // namespace detail
} // namespace system

View File

@ -0,0 +1,97 @@
#ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED
// Support for interoperability between Boost.System and <system_error>
//
// Copyright 2018, 2021 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/std_category.hpp>
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/generic_category.hpp>
//
namespace boost
{
namespace system
{
namespace detail
{
inline bool std_category::equivalent( int code, const std::error_condition & condition ) const BOOST_NOEXCEPT
{
if( condition.category() == *this )
{
boost::system::error_condition bn( condition.value(), *pc_ );
return pc_->equivalent( code, bn );
}
else if( condition.category() == std::generic_category() || condition.category() == boost::system::generic_category() )
{
boost::system::error_condition bn( condition.value(), boost::system::generic_category() );
return pc_->equivalent( code, bn );
}
#ifndef BOOST_NO_RTTI
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &condition.category() ) )
{
boost::system::error_condition bn( condition.value(), *pc2->pc_ );
return pc_->equivalent( code, bn );
}
#endif
else
{
return default_error_condition( code ) == condition;
}
}
inline bool std_category::equivalent( const std::error_code & code, int condition ) const BOOST_NOEXCEPT
{
if( code.category() == *this )
{
boost::system::error_code bc( code.value(), *pc_ );
return pc_->equivalent( bc, condition );
}
else if( code.category() == std::generic_category() || code.category() == boost::system::generic_category() )
{
boost::system::error_code bc( code.value(), boost::system::generic_category() );
return pc_->equivalent( bc, condition );
}
#ifndef BOOST_NO_RTTI
else if( std_category const* pc2 = dynamic_cast< std_category const* >( &code.category() ) )
{
boost::system::error_code bc( code.value(), *pc2->pc_ );
return pc_->equivalent( bc, condition );
}
#endif
else if( *pc_ == boost::system::generic_category() )
{
return std::generic_category().equivalent( code, condition );
}
else
{
return false;
}
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_IMPL_HPP_INCLUDED

View File

@ -16,6 +16,7 @@
#include <boost/system/detail/generic_category.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/config.hpp>
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
{

View File

@ -1,7 +1,7 @@
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
#define BOOST_SYSTEM_RESULT_HPP_INCLUDED
// Copyright 2017, 2021 Peter Dimov.
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
@ -11,11 +11,14 @@
#include <boost/system/detail/error_category_impl.hpp>
#include <boost/variant2/variant.hpp>
#include <boost/throw_exception.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <type_traits>
#include <utility>
#include <iosfwd>
#include <system_error>
#include <exception>
//
@ -26,11 +29,47 @@ namespace system
// throw_exception_from_error
BOOST_NORETURN inline void throw_exception_from_error( error_code const & e )
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wattributes"
#endif
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code const & e, boost::source_location const& loc )
{
boost::throw_exception( system_error( e ) );
boost::throw_with_location( system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( errc::errc_t const & e, boost::source_location const& loc )
{
boost::throw_with_location( system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::errc const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::exception_ptr const & p, boost::source_location const& loc )
{
if( p )
{
std::rethrow_exception( p );
}
else
{
boost::throw_with_location( std::bad_exception(), loc );
}
}
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic pop
#endif
// in_place_*
using in_place_value_t = variant2::in_place_index_t<0>;
@ -155,7 +194,7 @@ public:
// checked value access
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
BOOST_CXX14_CONSTEXPR T value() const
BOOST_CXX14_CONSTEXPR T value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
@ -163,13 +202,13 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
#else
BOOST_CXX14_CONSTEXPR T& value() &
BOOST_CXX14_CONSTEXPR T& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &
{
if( has_value() )
{
@ -177,11 +216,11 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
BOOST_CXX14_CONSTEXPR T const& value() const&
BOOST_CXX14_CONSTEXPR T const& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const&
{
if( has_value() )
{
@ -189,24 +228,24 @@ public:
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
value() &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value() );
return std::move( value( loc ) );
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
value() &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value() );
return std::move( value( loc ) );
}
template<class U = T>
@ -217,9 +256,9 @@ public:
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
value() const &&
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const &&
{
return std::move( value() );
return std::move( value( loc ) );
}
#endif
@ -443,14 +482,14 @@ public:
// checked value access
BOOST_CXX14_CONSTEXPR void value() const
BOOST_CXX14_CONSTEXPR void value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ) );
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}

View File

@ -23,46 +23,25 @@ private:
error_code code_;
private:
static std::string build_message( char const * prefix, error_code const & ec )
{
std::string r;
if( prefix )
{
r += prefix;
r += ": ";
}
r += ec.what();
return r;
}
static std::string build_message( char const * prefix, int ev, error_category const & cat )
{
return build_message( prefix, error_code( ev, cat ) );
}
public:
explicit system_error( error_code const & ec )
: std::runtime_error( build_message( 0, ec ) ), code_( ec ) {}
explicit system_error( error_code const & ec ):
std::runtime_error( ec.what() ), code_( ec ) {}
system_error( error_code const & ec, std::string const & prefix )
: std::runtime_error( build_message( prefix.c_str(), ec ) ), code_( ec ) {}
system_error( error_code const & ec, std::string const & prefix ):
std::runtime_error( prefix + ": " + ec.what() ), code_( ec ) {}
system_error( error_code const & ec, char const * prefix )
: std::runtime_error( build_message( prefix, ec ) ), code_( ec ) {}
system_error( error_code const & ec, char const * prefix ):
std::runtime_error( std::string( prefix ) + ": " + ec.what() ), code_( ec ) {}
system_error( int ev, error_category const & ecat )
: std::runtime_error( build_message( 0, ev, ecat ) ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat ):
std::runtime_error( error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, std::string const & prefix )
: std::runtime_error( build_message( prefix.c_str(), ev, ecat ) ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, std::string const & prefix ):
std::runtime_error( prefix + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, char const * prefix )
: std::runtime_error( build_message( prefix, ev, ecat ) ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, char const * prefix ):
std::runtime_error( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
error_code code() const BOOST_NOEXCEPT
{

View File

@ -114,6 +114,16 @@ boost_test(TYPE run SOURCES std_interop_test11.cpp)
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)
boost_test(TYPE run SOURCES std_interop_test13.cpp)
boost_test(TYPE run SOURCES std_interop_test14.cpp)
boost_test(TYPE run SOURCES ec_location_test3.cpp)
boost_test(TYPE run SOURCES ec_location_test4.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)

View File

@ -20,6 +20,8 @@ project
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
<toolset>gcc-4.4:<cxxflags>-Wno-sign-compare
;
rule system-run ( sources + )
@ -136,11 +138,21 @@ run std_interop_test11.cpp ;
run ec_wstream_test.cpp ;
run std_interop_test12.cpp ;
run errc_test4.cpp ;
run std_interop_test13.cpp ;
run std_interop_test14.cpp ;
run ec_location_test3.cpp ;
run ec_location_test4.cpp ;
# result
import ../../config/checks/config : requires ;
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] ;
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] <toolset>gcc-4.7:<build>no ;
run result_default_construct.cpp : : : $(CPP11) ;
run result_value_construct.cpp : : : $(CPP11) ;

View File

@ -0,0 +1,90 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
int main()
{
int const val = ENOENT;
boost::system::error_category const & cat = boost::system::generic_category();
{
boost::system::error_code ec;
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
boost::system::error_code ec2( ec, &loc );
BOOST_TEST_EQ( ec2, ec );
BOOST_TEST( !ec2.has_location() );
BOOST_TEST_EQ( ec2.location(), boost::source_location() );
boost::system::error_code ec3( ec2, 0 );
BOOST_TEST_EQ( ec3, ec2 );
BOOST_TEST( !ec3.has_location() );
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
}
{
boost::system::error_code ec( val, cat );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
boost::system::error_code ec2( ec, &loc );
BOOST_TEST_EQ( ec2, ec );
BOOST_TEST( ec2.has_location() );
BOOST_TEST_EQ( ec2.location(), loc );
boost::system::error_code ec3( ec2, 0 );
BOOST_TEST_EQ( ec3, ec2 );
BOOST_TEST( !ec3.has_location() );
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code e2( val, std::generic_category() );
boost::system::error_code ec( e2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
boost::system::error_code ec2( ec, &loc );
BOOST_TEST_EQ( ec2, ec );
BOOST_TEST( !ec2.has_location() );
BOOST_TEST_EQ( ec2.location(), boost::source_location() );
boost::system::error_code ec3( ec2, 0 );
BOOST_TEST_EQ( ec3, ec2 );
BOOST_TEST( !ec3.has_location() );
BOOST_TEST_EQ( ec3.location(), boost::source_location() );
}
#endif
return boost::report_errors();
}

View File

@ -0,0 +1,93 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
int main()
{
int const val = ENOENT;
boost::system::error_category const & cat = boost::system::generic_category();
{
boost::system::error_code ec;
boost::system::error_code ec2( ec );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( ec, &loc );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
ec.assign( ec, 0 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
}
{
boost::system::error_code ec( val, cat );
boost::system::error_code ec2( ec );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( ec, &loc );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location(), loc );
ec.assign( ec, 0 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code e2( val, std::generic_category() );
boost::system::error_code ec( e2 );
boost::system::error_code ec2( ec );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( ec, &loc );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
ec.assign( ec, 0 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location(), boost::source_location() );
}
#endif
return boost::report_errors();
}

17
test/errc_test4.cpp Normal file
View File

@ -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 <boost/system/errc.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/core/lightweight_test.hpp>
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();
}

View File

@ -62,13 +62,13 @@ int main()
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<std::error_code> r( in_place_error, ec );
result<error_code> r( in_place_error, ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
@ -77,12 +77,12 @@ int main()
}
{
result<std::error_code> r( in_place_error, EINVAL, generic_category() );
result<error_code> r( in_place_error, EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
BOOST_TEST_EQ( X::instances, 0 );
@ -140,8 +140,8 @@ int main()
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, std::error_code>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<std::error_code, result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<int>, error_code>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<error_code, result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<std::string, X>, int>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<int, result<std::string, X>>));
@ -178,7 +178,7 @@ int main()
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
return boost::report_errors();

View File

@ -41,7 +41,7 @@ int main()
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), std::error_code( EINVAL, generic_category() ) );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
{

View File

@ -1,10 +1,11 @@
// Copyright 2017, 2021 Peter Dimov.
// Copyright 2017, 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <system_error>
using namespace boost::system;
@ -26,11 +27,15 @@ struct E
{
};
BOOST_NORETURN void throw_exception_from_error( Y const & )
BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_location const& )
{
throw E();
}
struct E2
{
};
int main()
{
{
@ -165,6 +170,78 @@ int main()
BOOST_TEST_EQ( result<int>( ec ).operator->(), static_cast<int*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<int, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<int, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<int*>(0) );
}
{
result<X> r( 1 );
@ -341,5 +418,77 @@ int main()
BOOST_TEST_EQ( result<void>( ec ).operator->(), static_cast<void*>(0) );
}
{
auto ec = make_error_code( std::errc::invalid_argument );
result<void, std::error_code> const r( ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, errc::errc_t> const r( in_place_error, errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::errc> const r( std::errc::invalid_argument );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::system_error );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( std::make_exception_ptr( E2() ) );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), E2 );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
{
result<void, std::exception_ptr> const r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_NOT( r );
BOOST_TEST( !r );
BOOST_TEST_THROWS( r.value(), std::bad_exception );
BOOST_TEST_EQ( r.operator->(), static_cast<void*>(0) );
}
return boost::report_errors();
}

127
test/std_interop_test12.cpp Normal file
View File

@ -0,0 +1,127 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_category.hpp>
#include <boost/system/errc.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#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 <system_error>
enum my_errc
{
my_enoent = ENOENT
};
class my_category: public boost::system::error_category
{
public:
char const* name() const BOOST_NOEXCEPT
{
return "mycat";
}
boost::system::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT
{
switch( ev )
{
case my_enoent:
return boost::system::error_condition( ENOENT, boost::system::generic_category() );
default:
return boost::system::error_condition( ev, *this );
}
}
std::string message( int ev ) const
{
switch( ev )
{
case my_enoent:
return "No such entity";
default:
return "Unknown error";
}
}
};
#if defined(BOOST_GCC) && BOOST_GCC < 70000
// g++ 6 and earlier do not allow specializations outside the namespace
namespace boost
{
namespace system
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace system
} // namespace boost
namespace std
{
template<> struct is_error_code_enum<my_errc>: std::true_type {};
} // namespace std
#else
template<> struct boost::system::is_error_code_enum<my_errc>: std::true_type {};
template<> struct std::is_error_code_enum<my_errc>: std::true_type {};
#endif
boost::system::error_code make_error_code( my_errc e )
{
// If `cat` is declared constexpr or const, msvc-14.1 and
// msvc-14.2 before 19.29 put it in read-only memory,
// despite the `ps_` member being mutable. So it crashes.
static /*BOOST_SYSTEM_CONSTEXPR*/ my_category cat;
return boost::system::error_code( e, cat );
}
int main()
{
{
boost::system::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
BOOST_TEST( e1 == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
}
{
std::error_code e1 = my_enoent;
BOOST_TEST( e1 == my_enoent );
BOOST_TEST_NOT( e1 != my_enoent );
BOOST_TEST( e1 == std::errc::no_such_file_or_directory );
}
return boost::report_errors();
}
#endif

View File

@ -0,0 +1,77 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#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 <system_error>
class my_category_impl: public std::error_category
{
public:
char const* name() const BOOST_NOEXCEPT
{
return "mycat";
}
std::string message( int /*ev*/ ) const
{
return "Unknown error";
}
};
std::error_category const& my_category()
{
static my_category_impl mycat;
return mycat;
}
int main()
{
{
std::error_code e1( 5, boost::system::system_category() );
boost::system::error_code e2( e1 );
std::error_code e3( e2 );
BOOST_TEST_EQ( e1, e3 );
BOOST_TEST_EQ( e1.value(), e3.value() );
BOOST_TEST_EQ( &e1.category(), &e3.category() );
}
{
std::error_code e1( 5, boost::system::generic_category() );
boost::system::error_code e2( e1 );
std::error_code e3( e2 );
BOOST_TEST_EQ( e1, e3 );
BOOST_TEST_EQ( e1.value(), e3.value() );
BOOST_TEST_EQ( &e1.category(), &e3.category() );
}
{
std::error_code e1( 5, my_category() );
boost::system::error_code e2( e1 );
std::error_code e3( e2 );
BOOST_TEST_EQ( e1, e3 );
BOOST_TEST_EQ( e1.value(), e3.value() );
BOOST_TEST_EQ( &e1.category(), &e3.category() );
}
return boost::report_errors();
}
#endif

View File

@ -0,0 +1,57 @@
// Copyright 2021, 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/system/error_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <cerrno>
#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 <system_error>
class my_category_impl: public boost::system::error_category
{
public:
char const* name() const BOOST_NOEXCEPT
{
return "mycat";
}
std::string message( int /*ev*/ ) const
{
return "Unknown error";
}
};
boost::system::error_category const& my_category()
{
static my_category_impl mycat;
return mycat;
}
int main()
{
{
boost::system::error_code e1( 5, my_category() );
std::error_code e2( e1 );
boost::system::error_code e3( e2 );
BOOST_TEST_EQ( e1, e3 );
BOOST_TEST_EQ( e1.value(), e3.value() );
BOOST_TEST_EQ( &e1.category(), &e3.category() );
}
return boost::report_errors();
}
#endif

View File

@ -1,4 +1,4 @@
// Copyright 2021 Peter Dimov
// Copyright 2021, 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// https://www.boost.org/LICENSE_1_0.txt
@ -14,22 +14,36 @@ int main()
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec );
BOOST_TEST_EQ( std::string( x1.what() ), ec.what() );
BOOST_TEST_EQ( std::string( x1.what() ), ec.what() );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::system_category(), &loc );
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec, "prefix" );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + ec.what() );
}
{
sys::system_error x1( 5, sys::generic_category() );
sys::error_code ec( 5, sys::generic_category() );
sys::system_error x1( ec, std::string( "prefix2" ) );
BOOST_TEST_EQ( std::string( x1.what() ), sys::error_code( 5, sys::generic_category() ).what() );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + ec.what() );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::generic_category(), &loc );
sys::system_error x1( ec, "prefix3" );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix3: " + ec.what() );
}
{
sys::system_error x1( 5, sys::system_category() );
BOOST_TEST_EQ( std::string( x1.what() ), sys::error_code( 5, sys::system_category() ).what() );
}
{
@ -38,5 +52,11 @@ int main()
BOOST_TEST_EQ( std::string( x1.what() ), "prefix: " + sys::error_code( 5, sys::system_category() ).what() );
}
{
sys::system_error x1( 5, sys::system_category(), std::string( "prefix2" ) );
BOOST_TEST_EQ( std::string( x1.what() ), "prefix2: " + sys::error_code( 5, sys::system_category() ).what() );
}
return boost::report_errors();
}