Compare commits

...

83 Commits

Author SHA1 Message Date
Peter Dimov
bb60a27b18 Update appveyor.yml 2023-01-12 20:38:54 +02:00
Peter Dimov
e478ba1a2b Update appveyor.yml 2023-01-12 15:18:11 +02:00
Peter Dimov
50100b0e81 Update CMakeLists.txt 2023-01-12 10:37:55 +02:00
Peter Dimov
bb502f5d67 Merge branch 'develop' into feature/pr-90 2023-01-12 10:36:56 +02:00
Peter Dimov
fa2349eee7 Add CMake tests to Appveyor 2023-01-12 05:45:30 +02:00
Peter Dimov
3d9acaf082 Update CMakeLists.txt 2023-01-12 05:41:30 +02:00
Peter Dimov
c6795eb9d0 Merge branch 'natvis' of https://github.com/vinniefalco/boost-system into feature/pr-90 2023-01-12 05:39:37 +02:00
Peter Dimov
57c295bbf7 Work around Clang 3.5 failures in result_value_access 2023-01-10 05:46:57 +02:00
Peter Dimov
36e3b2c6ae Work around Clang 3.5..3.8 failure in constexpr_test2 2023-01-10 05:14:36 +02:00
Peter Dimov
583cd8dba2 Update .drone.jsonnet 2023-01-10 04:36:37 +02:00
Peter Dimov
0c2de4cb2a Update .drone.jsonnet 2023-01-10 04:19:25 +02:00
Peter Dimov
3d595a6e79 Update ci.yml 2023-01-10 04:06:30 +02:00
Peter Dimov
b3faedfe3e Extend Clang 6 workaround to Clang 7 under Android. Fixes #100. 2023-01-10 03:09:20 +02:00
Peter Dimov
32bf67f748 error_code wrapping std::error_code should never compare equal to error_code not wrapping std (because of hash_value.) Fixes #101. 2023-01-07 19:56:34 +02:00
Peter Dimov
5d15aa1267 Add ec_hash_value_test 2023-01-07 19:42:59 +02:00
Peter Dimov
36e1236a0f Remove _Addr assignment from the constructor of std_category. Fixes #98. 2022-12-10 22:17:51 +02:00
Peter Dimov
2c20b6e7e5 Work around ERROR_INVALID_NAME failure on msvc-14.0, msvc-14.1 2022-12-10 19:45:14 +02:00
Peter Dimov
103f3b4f00 Print original error code in win32_generic_test 2022-12-10 18:47:54 +02:00
Peter Dimov
14f779e234 Update Win32 translation table. Closes #97. 2022-12-10 18:38:19 +02:00
Peter Dimov
bfccd4b4d9 Add win32_generic_test. Refs #97. 2022-12-10 18:24:34 +02:00
Peter Dimov
7ae6b317f3 Only disable C4351 on msvc-12.0 and earlier (refs #96) 2022-10-26 15:52:18 +03:00
Peter Dimov
9a6d79b841 Update revision history 2022-10-18 04:17:17 +03:00
Peter Dimov
ece71199a9 Document result<>::emplace 2022-10-18 04:15:40 +03:00
Peter Dimov
1e4c050d6c Add result<>::emplace (refs #85) 2022-10-18 00:46:59 +03:00
Peter Dimov
21115121bb Update ci.yml 2022-10-15 04:17:12 +03:00
Peter Dimov
956fa92a53 Update revision history 2022-09-27 20:32:03 +03:00
Peter Dimov
ee318f937f Document result<>::value_type, error_type, in_place_value, in_place_error. Closes #93. 2022-09-27 20:23:28 +03:00
Peter Dimov
19f99264de Document BOOST_SYSTEM_DISABLE_THREADS 2022-09-27 20:20:36 +03:00
Peter Dimov
3261bae6de Update .drone.jsonnet 2022-09-27 18:58:14 +03:00
Peter Dimov
20ce51858b Add in_place_value, in_place_error to result<>. Refs #93. 2022-09-27 18:18:16 +03:00
Peter Dimov
52d7429473 Add value_type, error_type typedefs to result. Refs #93. 2022-09-26 21:20:40 +03:00
Peter Dimov
53c00841fc Add support for BOOST_SYSTEM_DISABLE_THREADS (refs #92) 2022-09-08 18:32:26 +03:00
Peter Dimov
19e27a73e9 Disable failing test for msvc-12.0 2022-08-25 17:38:59 +03:00
Peter Dimov
19020ce925 Disable std_interop_test15 on g++ 4.8/4.9 2022-08-24 23:37:03 +03:00
Peter Dimov
3faf415026 Resolve ambiguities when comparing error_condition with std enums (refs #91) 2022-08-24 22:56:15 +03:00
Peter Dimov
a2df4d09da Update error_code_test3.cpp 2022-08-24 21:41:38 +03:00
Peter Dimov
455c6a6332 Add std_interop_test15.cpp 2022-08-24 21:40:20 +03:00
Peter Dimov
efb7634666 Move code/condition comparisons back outside class error_code; fixes #91 2022-08-24 21:10:05 +03:00
Peter Dimov
2bba3fd5e2 Add error_code_test3.cpp 2022-08-24 20:54:20 +03:00
Peter Dimov
8c740705e6 Add missing include 2022-08-21 19:42:10 +03:00
Peter Dimov
4708d95e80 Merge branch 'constexpr-default-ctor' of https://github.com/vinniefalco/boost-system into feature/pr-89 2022-08-21 19:13:48 +03:00
Peter Dimov
867f6d06d0 Add constexpr_test2.cpp 2022-08-21 19:13:12 +03:00
Vinnie Falco
ac1ed1ecc1 error_code default ctor is constexpr in c++11 2022-08-21 08:17:54 -07:00
Vinnie Falco
fe48c3058d add boost_system.natvis and interface source files 2022-08-19 11:40:36 -07:00
Peter Dimov
cc7c2f7ee4 Return v_.index() == 1 from has_error() to avoid -Wmaybe-uninitialized in error() 2022-08-02 22:44:34 +03:00
Peter Dimov
f2e1db8021 Constrain explicit value and error constructors to not accept zero arguments. Fixes #86. 2022-07-26 21:49:13 +03:00
Peter Dimov
ede243c42f Add (negative) tests for default constructability (refs #86) 2022-07-26 21:35:33 +03:00
Peter Dimov
1558aaa789 Update ci.yml 2022-07-26 20:41:24 +03:00
Peter Dimov
96b876d91a Add README.md 2022-06-19 02:19:58 +03:00
Peter Dimov
eb9ae4ac69 Update revision history 2022-06-19 01:30:17 +03:00
Peter Dimov
8fd487d496 Update documentation 2022-06-19 01:28:36 +03:00
Peter Dimov
5223c94aa9 Disable throws_assign_fail.cpp for GCC/release, because gcc-12 fails it at compile time 2022-06-18 23:07:41 +03:00
Peter Dimov
a5ee3f291c Update ci.yml 2022-06-18 21:47:57 +03:00
Peter Dimov
4200b00973 Add converting constructor to result (refs #82) 2022-06-18 18:12:06 +03:00
Peter Dimov
533dfe1688 Update revision history 2022-05-05 21:17:09 +03:00
Peter Dimov
7dec756a6f Update documentation 2022-05-05 21:15:03 +03:00
Peter Dimov
648a35838b Remove unnecessary overloads 2022-05-05 05:12:08 +03:00
Peter Dimov
256fe92dbb Add error_code(error_code const& ec, source_location const* loc) and a corresponding assign 2022-05-05 05:02:37 +03:00
Peter Dimov
5debb8a041 Update revision history 2022-05-05 02:30:07 +03:00
Peter Dimov
a97e5a0546 Move BOOST_NOINLINE to operator std::error_category 2022-04-22 22:41:26 +03:00
Peter Dimov
dc17edfa07 Remove clang-win from appveyor.yml 2022-04-22 21:16:09 +03:00
Peter Dimov
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
Peter Dimov
9279001b8c Check BOOST_NO_CXX11_HDR_MUTEX when enabling <system_error> integration 2022-04-22 16:49:03 +03:00
Peter Dimov
616e652bd7 Suppress strict-aliasing warning for gcc 4.8 to 6 2022-04-21 21:06:14 +03:00
Peter Dimov
98439855bd Use static_cast instead of reinterpret_cast 2022-04-21 20:52:02 +03:00
Peter Dimov
986efb1420 Rework conversion to std::error_category to not allocate (closes #78) 2022-04-21 20:32:25 +03:00
Peter Dimov
28a13571b9 Restore the original system::error_code from std::error_code (refs #79) 2022-03-18 18:24:01 +02:00
Peter Dimov
65ed1eef66 Add std_interop_test14.cpp (refs #79) 2022-03-18 08:12:05 +02:00
Peter Dimov
6de20eeebc Add std_interop_test13 2022-03-18 08:12:05 +02:00
Peter Dimov
0a9266ea7e Add a comment explaining the one-time allocation in error_category_impl.hpp. Fixes #78. 2022-03-18 08:11:16 +02:00
Peter Dimov
adb9fc54cb Remove msvc-14.1 from ci.yml 2022-03-18 07:51:38 +02:00
Peter Dimov
e197c5e803 Update documentation 2022-02-18 19:43:08 +02:00
Peter Dimov
6d7a57a970 Add throw_exception_from_error overload for std::exception_ptr 2022-02-18 02:55:34 +02:00
Peter Dimov
00c71cf388 Add throw_exception_from_error overloads for boost::system::errc, std::errc 2022-02-17 21:55:47 +02:00
Peter Dimov
d930cea481 Update documentation 2022-02-14 02:05:44 +02:00
Peter Dimov
4f09f4adde Use throw_with_location in throw_exception_from_error 2022-02-13 22:50:20 +02:00
Peter Dimov
abd62362ef Update documentation 2022-02-09 20:52:23 +02:00
Peter Dimov
8d8e6a90de Add an errc::make_error_code overload taking a source location 2022-02-09 20:41:34 +02:00
Peter Dimov
716c2ed8ef Disable result tests on GCC 4.7 2022-02-07 21:40:26 +02:00
Peter Dimov
46a5ecd490 Do not include boost/system/result.hpp on GCC 4.7 2022-02-07 21:38:14 +02:00
Peter Dimov
79f4ef0416 Remove .drone.star 2022-02-07 21:34:11 +02:00
Peter Dimov
d0a8f7fbb7 Squash-merge feature/drone-jsonnet into develop 2022-02-07 21:33:48 +02:00
Peter Dimov
bc07ab1e25 Update .drone.star 2022-02-07 05:09:49 +02:00
43 changed files with 2774 additions and 302 deletions

319
.drone.jsonnet Normal file
View File

@@ -0,0 +1,319 @@
# 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",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="arm64",
),
linux_pipeline(
"Linux 20.04 GCC 9* S390x",
"cppalliance/droneubuntu2004:multiarch",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a' },
arch="s390x",
),
linux_pipeline(
"Linux 20.04 GCC 10 32",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '32' },
"g++-10-multilib",
),
linux_pipeline(
"Linux 20.04 GCC 10 64",
"cppalliance/droneubuntu2004:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-10', CXXSTD: '03,11,14,17,20', ADDRMD: '64' },
"g++-10-multilib",
),
linux_pipeline(
"Linux 22.04 GCC 11* 32",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '32' },
),
linux_pipeline(
"Linux 22.04 GCC 11* 64",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++', CXXSTD: '03,11,14,17,2a', ADDRMD: '64' },
),
linux_pipeline(
"Linux 22.04 GCC 12 32 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '32' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 22.04 GCC 12 64 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'gcc', COMPILER: 'g++-12', CXXSTD: '03,11,14,17,20,2b', ADDRMD: '64' } + asan,
"g++-12-multilib",
),
linux_pipeline(
"Linux 16.04 Clang 3.5",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.5', CXXSTD: '03,11' },
"clang-3.5",
),
linux_pipeline(
"Linux 16.04 Clang 3.6",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.6', CXXSTD: '03,11,14' },
"clang-3.6",
),
linux_pipeline(
"Linux 16.04 Clang 3.7",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.7', CXXSTD: '03,11,14' },
"clang-3.7",
),
linux_pipeline(
"Linux 16.04 Clang 3.8",
"cppalliance/droneubuntu1604:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-3.8', CXXSTD: '03,11,14' },
"clang-3.8",
),
linux_pipeline(
"Linux 22.04 Clang 13",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-13', CXXSTD: '03,11,14,17,20' },
"clang-13",
),
linux_pipeline(
"Linux 22.04 Clang 14 UBSAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + ubsan,
"clang-14",
),
linux_pipeline(
"Linux 22.04 Clang 14 ASAN",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-14', CXXSTD: '03,11,14,17,20' } + asan,
"clang-14",
),
linux_pipeline(
"Linux 22.04 Clang 15",
"cppalliance/droneubuntu2204:1",
{ TOOLSET: 'clang', COMPILER: 'clang++-15', CXXSTD: '03,11,14,17,20,2b' },
"clang-15",
["deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 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' },
),
]

View File

@@ -1,32 +0,0 @@
# Copyright 2020 Rene Rivera
# Copyright 2022 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
globalenv={ 'UBSAN_OPTIONS': 'print_stacktrace=1' }
def main(ctx):
return [
linux_cxx("GCC 4.4 14.04", "", packages="g++-4.4", buildscript="drone", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.4', 'CXXSTD': '98,0x'}, globalenv=globalenv),
linux_cxx("GCC 4.6 14.04", "", packages="g++-4.6", buildscript="drone", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.6', 'CXXSTD': '03,0x'}, globalenv=globalenv),
linux_cxx("GCC 4.8* 14.04", "", packages="g++-multilib", buildscript="drone", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11', 'ADDRMD': '32,64'}, globalenv=globalenv),
linux_cxx("GCC 4.9 14.04", "", packages="g++-4.9", buildscript="drone", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-4.9', 'CXXSTD': '03,11'}, globalenv=globalenv),
linux_cxx("GCC 5* 16.04", "", packages="g++-multilib", buildscript="drone", image="cppalliance/droneubuntu1604:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11,14', 'ADDRMD': '32,64'}, globalenv=globalenv),
linux_cxx("GCC 6 16.04", "", packages="g++-6", buildscript="drone", image="cppalliance/droneubuntu1604:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-6', 'CXXSTD': '03,11'}, globalenv=globalenv),
linux_cxx("GCC 7* 18.04", "", packages="g++-multilib", buildscript="drone", image="cppalliance/droneubuntu1804:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11,14,1z', 'ADDRMD': '32,64'}, globalenv=globalenv),
#linux_cxx("GCC 8 18.04", "", packages="g++-8", buildscript="drone", image="cppalliance/droneubuntu1804:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++-8', 'CXXSTD': '03,11,14,1z', 'ADDRMD': '32,64'}, globalenv=globalenv),
linux_cxx("GCC 9* 20.04", "", packages="g++-multilib", buildscript="drone", image="cppalliance/droneubuntu2004:1", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11,14,17,2a', 'ADDRMD': '32,64'}, globalenv=globalenv),
linux_cxx("GCC 9* 20.04 UBSAN", "", packages="", buildscript="drone", image="cppalliance/droneubuntu2004:1", environment={'UBSAN': 1, 'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11,14,17,2a', 'LINKFLAGS': '-fuse-ld=gold'}, globalenv=globalenv),
linux_cxx("GCC 9* 20.04 ARM64", "", packages="", buildscript="drone", image="cppalliance/droneubuntu2004:multiarch", arch="arm64", environment={'TOOLSET': 'gcc', 'COMPILER': 'g++', 'CXXSTD': '03,11,14,17,2a', 'ADDRMD': '32,64'}, globalenv=globalenv),
linux_cxx("Clang 3.4 14.04", "", packages="clang-3.4", buildscript="drone", image="cppalliance/droneubuntu1404:1", environment={'TOOLSET': 'clang', 'COMPILER': '/usr/bin/clang++', 'CXXSTD': '03,11'}, globalenv=globalenv),
linux_cxx("Clang 13 20.04 UBSAN", "", packages="clang-13", llvm_os="focal", llvm_ver="13", buildscript="drone", image="cppalliance/droneubuntu2004:1", environment={'UBSAN': '1', 'TOOLSET': 'clang', 'COMPILER': 'clang++-13', 'CXXSTD': '03,11,14,17,20'}, globalenv=globalenv),
linux_cxx("Clang 14 20.04 UBSAN", "", packages="clang-14", llvm_os="focal", llvm_ver="14", buildscript="drone", image="cppalliance/droneubuntu2004:1", environment={'UBSAN': '1', 'TOOLSET': 'clang', 'COMPILER': 'clang++-14', 'CXXSTD': '03,11,14,17,20'}, globalenv=globalenv),
osx_cxx("Xcode 12.2 UBSAN", "", packages="", buildtype="boost", buildscript="drone", xcode_version="12.2", environment={'UBSAN': '1', 'TOOLSET': 'clang', 'COMPILER': 'clang++', 'CXXSTD': '03,11,14,1z'}, globalenv=globalenv),
windows_cxx("msvc-14.0", "", image="cppalliance/dronevs2015", buildscript="drone", environment={"TOOLSET": "msvc-14.0", "CXXSTD": "14,latest"}, globalenv=globalenv),
windows_cxx("msvc-14.1", "", image="cppalliance/dronevs2017", buildscript="drone", environment={"TOOLSET": "msvc-14.1", "CXXSTD": "14,17,latest"}, globalenv=globalenv),
windows_cxx("msvc-14.2", "", image="cppalliance/dronevs2019", buildscript="drone", environment={"TOOLSET": "msvc-14.2", "CXXSTD": "14,17,20,latest"}, globalenv=globalenv),
windows_cxx("msvc-14.3", "", image="cppalliance/dronevs2022:1", buildscript="drone", environment={"TOOLSET": "msvc-14.3", "CXXSTD": "14,17,20,latest"}, globalenv=globalenv)
]
# from https://github.com/boostorg/boost-ci
load("@boost_ci//ci/drone/:functions.star", "linux_cxx", "windows_cxx", "osx_cxx")

View File

@@ -1,24 +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%
IF "%DRONE_BRANCH%" == "" (
for /F %%i in ("%GITHUB_REF%") do @set DRONE_BRANCH=%%~nxi
)
for /F %%i in ("%DRONE_REPO%") do @set SELF=%%~nxi
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\%SELF%\
python tools/boostdep/depinst/depinst.py %SELF%
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/%SELF%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
b2 -j3 libs/%LIBRARY%/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker

View File

@@ -1,31 +1,24 @@
#!/bin/bash
# Copyright 2020 Rene Rivera, Sam Darwin
# Copyright 2022 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.txt or copy at http://boost.org/LICENSE_1_0.txt)
# https://www.boost.org/LICENSE_1_0.txt
set -e
export TRAVIS_BUILD_DIR=$(pwd)
export DRONE_BUILD_DIR=$(pwd)
export TRAVIS_BRANCH=$DRONE_BRANCH
export VCS_COMMIT_ID=$DRONE_COMMIT
export GIT_COMMIT=$DRONE_COMMIT
export REPO_NAME=$DRONE_REPO
export PATH=~/.local/bin:/usr/local/bin:$PATH
set -ex
echo '==================================> INSTALL'
DRONE_BUILD_DIR=$(pwd)
BOOST_BRANCH=develop
if [ "$DRONE_BRANCH" = "master" ]; then BOOST_BRANCH=master; fi
BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
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 $TRAVIS_BUILD_DIR/* libs/system
python tools/boostdep/depinst/depinst.py system
cp -r $DRONE_BUILD_DIR/* libs/$LIBRARY
python tools/boostdep/depinst/depinst.py $LIBRARY
./bootstrap.sh
./b2 -d0 headers
echo '==================================> SCRIPT'
echo "using $TOOLSET : : $COMPILER ;" > ~/user-config.jam
./b2 -j3 libs/system/test toolset=$TOOLSET cxxstd=$CXXSTD variant=debug,release ${ADDRMD:+address-model=$ADDRMD} ${UBSAN:+cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined linkflags=-fsanitize=undefined define=UBSAN=1 debug-symbols=on} ${LINKFLAGS:+linkflags=$LINKFLAGS}
./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

@@ -19,22 +19,26 @@ jobs:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
os: ubuntu-20.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
@@ -47,30 +51,37 @@ jobs:
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: gcc-12
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: g++-12
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
os: ubuntu-latest
container: ubuntu:18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
os: ubuntu-20.04
install: clang-7
- toolset: clang
compiler: clang++-8
@@ -92,20 +103,44 @@ jobs:
os: ubuntu-20.04
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,2a"
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20,2b"
os: ubuntu-22.04
install: clang-14
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
os: macos-11
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-12
runs-on: ${{matrix.os}}
container: ${{matrix.container}}
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup container environment
if: matrix.container
run: |
apt-get update
apt-get -y install sudo python git g++
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -148,10 +183,6 @@ 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,20,latest"
addrmd: 32,64
@@ -172,7 +203,7 @@ jobs:
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Setup Boost
shell: cmd
@@ -207,18 +238,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -253,18 +285,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |
@@ -309,18 +342,19 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: macos-10.15
- os: ubuntu-22.04
- os: macos-11
- os: macos-12
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
run: sudo apt-get -y install ${{matrix.install}}
- name: Setup Boost
run: |

View File

@@ -2,7 +2,7 @@
# 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
cmake_minimum_required(VERSION 3.5...3.16)
cmake_minimum_required(VERSION 3.5...3.20)
project(boost_system VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
@@ -20,6 +20,15 @@ target_link_libraries(boost_system
Boost::winapi
)
if(CMAKE_VERSION VERSION_GREATER 3.18 AND CMAKE_GENERATOR MATCHES "Visual Studio")
file(GLOB_RECURSE boost_system_IDEFILES CONFIGURE_DEPENDS include/*.hpp)
source_group(TREE ${PROJECT_SOURCE_DIR}/include FILES ${boost_system_IDEFILES} PREFIX "Header Files")
list(APPEND boost_system_IDEFILES extra/boost_system.natvis)
target_sources(boost_system PRIVATE ${boost_system_IDEFILES})
endif()
if(BUILD_TESTING)
add_subdirectory(test)

25
README.md Normal file
View File

@@ -0,0 +1,25 @@
# Boost.System
The Boost.System library, part of [Boost C++ Libraries](https://boost.org),
implements an extensible framework for error reporting in the form of an
`error_code` class and supporting facilities.
It has been proposed for the C++11 standard, has been accepted, and
is now available as part of the standard library in the `<system_error>`
header. However, the Boost implementation has continued to evolve and
gain enhancements and additional functionality, such as support for
attaching [source locations](https://www.boost.org/doc/libs/release/libs/assert/doc/html/assert.html#source_location_support)
to `error_code`, and a `result<T>` class that can carry either a value
or an error code.
See [the documentation of System](http://boost.org/libs/system) for more
information.
Since `<system_error>` is a relatively undocumented portion of the C++
standard library, the documentation of Boost.System may be useful to you
even if you use the standard components.
## License
Distributed under the
[Boost Software License, Version 1.0](http://boost.org/LICENSE_1_0.txt).

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
@@ -44,6 +40,12 @@ environment:
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
CMAKE: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_SUBDIR: 1
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
CMAKE_INSTALL: 1
install:
- set BOOST_BRANCH=develop
@@ -63,4 +65,27 @@ test_script:
- PATH=%ADDPATH%%PATH%
- if not "%CXXSTD%" == "" set CXXSTD=cxxstd=%CXXSTD%
- if not "%ADDRMD%" == "" set ADDRMD=address-model=%ADDRMD%
- b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
- if "%CMAKE%%CMAKE_SUBDIR%%CMAKE_INSTALL%" == "" b2 -j3 libs/system/test toolset=%TOOLSET% %CXXSTD% %ADDRMD% variant=debug,release embed-manifest-via=linker
- if not "%CMAKE%" == "" mkdir __build__ && cd __build__
- if not "%CMAKE%" == "" cmake -DBUILD_TESTING=ON -DBOOST_INCLUDE_LIBRARIES=system -DBoost_VERBOSE=ON ..
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Debug & ctest --output-on-failure --no-tests=error -j 3 -C Debug
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config Release & ctest --output-on-failure --no-tests=error -j 3 -C Release
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config MinSizeRel & ctest --output-on-failure --no-tests=error -j 3 -C MinSizeRel
- if not "%CMAKE%" == "" cmake --build . --target tests -j 3 --config RelWithDebInfo & ctest --output-on-failure --no-tests=error -j 3 -C RelWithDebInfo
- if not "%CMAKE_SUBDIR%" == "" cd libs/system/test/cmake_subdir_test && mkdir __build__ && cd __build__
- if not "%CMAKE_SUBDIR%" == "" cmake ..
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config Release && cmake --build . --target check --config Release
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config MinSizeRel && cmake --build . --target check --config MinSizeRel
- if not "%CMAKE_SUBDIR%" == "" cmake --build . --config RelWithDebInfo && cmake --build . --target check --config RelWithDebInfo
- if not "%CMAKE_INSTALL%" == "" mkdir __build__ && cd __build__
- if not "%CMAKE_INSTALL%" == "" cmake -DBOOST_INCLUDE_LIBRARIES=system -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Debug
- if not "%CMAKE_INSTALL%" == "" cmake --build . --target install --config Release
- if not "%CMAKE_INSTALL%" == "" cd ../libs/system/test/cmake_install_test && mkdir __build__ && cd __build__
- if not "%CMAKE_INSTALL%" == "" cmake -DCMAKE_INSTALL_PREFIX=C:/cmake-prefix ..
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Debug && cmake --build . --target check --config Debug
- if not "%CMAKE_INSTALL%" == "" cmake --build . --config Release && cmake --build . --target check --config Release

View File

@@ -8,12 +8,32 @@ https://www.boost.org/LICENSE_1_0.txt
# Revision History
:idprefix:
## Changes in Boost 1.81
* The macro `BOOST_SYSTEM_DISABLE_THREADS` can now be defined to disable
the use of `<mutex>` (e.g. on single-threaded libstdc++).
* Added `value_type`, `error_type`, `in_place_value`, `in_place_error`
to `result<>`.
* Added `emplace` to `result<>`.
## 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.
* Added a constructor that allows replacing the source location of an
`error_code`, and a corresponding `assign`.
* Added a converting constructor to `result`.
## Changes in Boost 1.79
* Added a `throw_exception_from_error` overload for `std::error_code`.
* 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

View File

@@ -29,6 +29,11 @@ When `BOOST_SYSTEM_USE_UTF8` is defined, on Windows the library returns
UTF-8 messages using code page `CP_UTF8` instead of the default `CP_ACP`.
This macro has no effect on POSIX.
When `BOOST_SYSTEM_DISABLE_THREADS` is defined, the library assumes that
the current platform doesn't support multiple threads and disables the use
of the standard header `<mutex>`, eliminating the mutex locks. The single
threaded `libstdc++` is one such platform.
## Deprecated Names
In the process of adding Boost.System to the {cpp}11 standard library, the
@@ -185,9 +190,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 +265,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
@@ -574,9 +615,8 @@ public:
template<class ErrorCodeEnum>
constexpr error_code( ErrorCodeEnum e ) noexcept;
template<class ErrorCodeEnum>
error_code( ErrorCodeEnum e, boost::source_location const * loc )
noexcept;
error_code( error_code const& ec,
boost::source_location const * loc ) noexcept;
error_code( std::error_code const& ec ) noexcept;
@@ -590,9 +630,8 @@ public:
template<class ErrorCodeEnum>
constexpr error_code & operator=( ErrorCodeEnum e ) noexcept;
template<class ErrorCodeEnum>
void assign( ErrorCodeEnum e,
boost::source_location const * loc ) noexcept;
void assign( error_code const& ec,
boost::source_location const * loc ) noexcept;
constexpr void clear() noexcept;
@@ -721,17 +760,17 @@ Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
```
template<class ErrorCodeEnum>
error_code( ErrorCodeEnum e, boost::source_location const * loc ) noexcept;
error_code( error_code const& ec,
boost::source_location const * loc ) noexcept;
```
[none]
* {blank}
+
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This constructor is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
When `make_error_code( e )` is not a default-constructed `error_code` and doesn't wrap a
`std::error_code`, `has_location()` is `true` and `&location()` is `loc`.
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration, or is `nullptr`.
Ensures: :: `*this == ec`.
Remarks: :: When `ec` is a default-constructed `error_code` or wraps a `std::error_code`,
or when `loc` is `nullptr`, `*this` stores no location (`has_location()` is `false`).
Otherwise, `*this` stores `loc` (`has_location()` is `true` and `&location()` is `loc`.)
```
error_code( std::error_code const & ec ) noexcept;
@@ -772,16 +811,13 @@ Ensures: :: `*this == make_error_code( e )`.
Remarks: :: This operator is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
```
template<class ErrorCodeEnum>
void assign( ErrorCodeEnum e,
boost::source_location const * loc ) noexcept;
void assign( error_code const& ec,
boost::source_location const * loc ) noexcept;
```
[none]
* {blank}
+
Requires: :: `loc` points to a valid `boost::source_location` object with static storage duration.
Effects: :: `*this = error_code( e, loc )`.
Remarks: :: This function is only enabled when `is_error_code_enum<ErrorCodeEnum>::value` is `true`.
Effects: :: `*this = error_code( ec, loc )`.
```
constexpr void clear() noexcept;
@@ -1460,6 +1496,15 @@ BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
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_*
using in_place_value_t = /*unspecified*/;
@@ -1497,7 +1542,7 @@ BOOST_NORETURN inline void throw_exception_from_error( error_code const & e,
* {blank}
+
Effects: ::
`boost::throw_exception( system_error( e ), loc )`.
`boost::throw_with_location( system_error( e ), loc )`.
```
BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e,
@@ -1507,7 +1552,40 @@ BOOST_NORETURN inline void throw_exception_from_error( std::error_code const & e
* {blank}
+
Effects: ::
`boost::throw_exception( std::system_error( e ), loc )`.
`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>
@@ -1522,6 +1600,12 @@ template<class T, class E = error_code> class result
{
public:
using value_type = T;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
// constructors
constexpr result();
@@ -1535,6 +1619,12 @@ public:
template<class... A>
constexpr result( in_place_error_t, A&&... a );
template<class T2, class E2>
constexpr result( result<T2, E2> const& r2 );
template<class T2, class E2>
constexpr result( result<T2, E2>&& r2 );
// queries
constexpr bool has_value() const noexcept;
@@ -1569,6 +1659,11 @@ public:
constexpr E error() const;
// emplace
template<class... A>
constexpr T& emplace( A&&... a );
// swap
constexpr void swap( result& r );
@@ -1643,6 +1738,30 @@ Ensures: ::
Remarks: ::
This constructor is only enabled when `std::is_constructible<E, A...>::value` is `true`.
```
template<class T2, class E2>
constexpr result( result<T2, E2> const& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds the value `T( *r2 )`, otherwise `*this` holds the value `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
```
template<class T2, class E2>
constexpr result( result<T2, E2>&& r2 );
```
[none]
* {blank}
+
Ensures: ::
If `r2.has_value()` is `true`, `*this` holds the value `T( std::move( *r2 ) )`, otherwise `*this` holds the value `E( r2.error() )`.
Remarks: ::
This constructor is only enabled when `std::is_convertible<T2, T>::value && std::is_convertible<E2, E>::value` is `true`.
#### Queries
```
@@ -1740,6 +1859,20 @@ constexpr E error() const;
Effects: ::
If `*this` holds an error, returns it. Otherwise, returns `E()`.
#### emplace
```
template<class... A>
constexpr T& emplace( A&&... a );
```
[none]
* {blank}
+
Ensures: ::
`*this` holds the value `T( std::forward<A>(a)... )`.
Returns: ::
A reference to the contained value.
#### swap
```
@@ -1808,6 +1941,12 @@ template<class E> class result<void, E>
{
public:
using value_type = void;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
// constructors
constexpr result() noexcept;
@@ -1842,6 +1981,10 @@ public:
constexpr E error() const;
// emplace
constexpr void emplace();
// swap
constexpr void swap( result& r );
@@ -1985,6 +2128,17 @@ constexpr E error() const;
Effects: ::
If `*this` holds an error, returns it. Otherwise, returns `E()`.
#### emplace
```
constexpr void emplace();
```
[none]
* {blank}
+
Ensures: ::
`*this` holds an unspecified value.
#### swap
```

53
extra/boost_system.natvis Normal file
View File

@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<Type Name="boost::system::error_category">
<DisplayString Condition="id_ == 0xb2ab117a257edfd0">[generic]</DisplayString>
<DisplayString Condition="id_ == 0xb2ab117a257edfd1">[system]</DisplayString>
<DisplayString Condition="id_ == 0xb2ab117a257edfd2">[interop]</DisplayString>
<DisplayString Condition="id_ != 0">[{id_,x}]</DisplayString>
<DisplayString>@{((uintptr_t)this),x}</DisplayString>
</Type>
<Type Name="boost::system::error_code">
<DisplayString Condition="lc_flags_ == 0">{d1_.val_} [system] ✓</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==1">{((std::error_code*)d2_)->_Myval} [std:future]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==3">{((std::error_code*)d2_)->_Myval} [std:generic]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==5">{((std::error_code*)d2_)->_Myval} [std:iostream]</DisplayString>
<DisplayString Condition="lc_flags_ == 1 &amp;&amp; ((std::error_code*)d2_)->_Mycat->_Addr==7">{((std::error_code*)d2_)->_Myval} [std:system]</DisplayString>
<DisplayString Condition="lc_flags_ == 1">{((std::error_code*)d2_)->_Myval} std@{((uintptr_t)((std::error_code*)d2_)->_Mycat),x}</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [generic] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [system] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [interop] ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ != 0 &amp;&amp;
(lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 )))">{d1_.val_} [{d1_.cat_->id_,x}] ✓</DisplayString>
<DisplayString Condition=
"lc_flags_ == 2 || (lc_flags_ &gt; 3 &amp;&amp; ( lc_flags_ % 2 == 0 ))">{d1_.val_} @{((uintptr_t)d1_.cat_),x} ✓</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd0 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [generic]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd1 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [system]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ == 0xb2ab117a257edfd2 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [interop]</DisplayString>
<DisplayString Condition="d1_.cat_->id_ != 0 &amp;&amp;
(lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 ))">{d1_.val_} [{d1_.cat_->id_,x}]</DisplayString>
<DisplayString Condition=
"lc_flags_ &gt;= 3 &amp;&amp; ( lc_flags_ % 2 == 1 )">{d1_.val_} @{((uintptr_t)d1_.cat_),x}</DisplayString>
<Expand>
<Item Name="std::error_code" Condition="lc_flags_ == 1">(std::error_code*)d2_</Item>
<Item Name="[location]" Condition="lc_flags_ &gt; 3">*((boost::source_location*)(lc_flags_ &amp; ~1))</Item>
</Expand>
</Type>
<Type Name="boost::system::result&lt;*,*&gt;">
<DisplayString>{v_}</DisplayString>
</Type>
</AutoVisualizer>

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

@@ -12,8 +12,14 @@
#include <boost/config/workaround.hpp>
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
//
// The macro BOOST_SYSTEM_DISABLE_THREADS can be defined on configurations
// that provide <system_error> and <atomic>, but not <mutex>, such as the
// single-threaded libstdc++.
//
// https://github.com/boostorg/system/issues/92
#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) || defined(BOOST_SYSTEM_DISABLE_THREADS) )
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
@@ -58,7 +64,9 @@
// BOOST_SYSTEM_CLANG_6
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11))
// Android NDK r18b has Clang 7.0.2 that still needs the workaround
// https://github.com/boostorg/system/issues/100
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11) || (defined(__ANDROID__) && __clang_major__ == 7))
# define BOOST_SYSTEM_CLANG_6
#endif

View File

@@ -48,6 +48,11 @@ class std_category;
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
#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) && BOOST_MSVC < 1900
#pragma warning(pop)
#endif
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif

View File

@@ -97,26 +97,75 @@ 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 <new>
#if !defined(BOOST_SYSTEM_DISABLE_THREADS)
# include <mutex>
#endif
namespace boost
{
namespace system
{
inline error_category::operator std::error_category const & () const
#if !defined(BOOST_SYSTEM_DISABLE_THREADS)
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
#endif
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
#if !defined(BOOST_SYSTEM_DISABLE_THREADS)
std::lock_guard<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
#endif
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, system::detail::id_wrapper<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_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, system::detail::id_wrapper<0x1F4D3>() );
return generic_instance;
#else
return std::generic_category();
return std::generic_category();
#endif
}
@@ -126,36 +175,28 @@ inline error_category::operator std::error_category const & () const
// This condition must be the same as the one in error_code.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
static const boost::system::detail::std_category system_instance( this, 0x1F4D7 );
return system_instance;
static const boost::system::detail::std_category system_instance( this, system::detail::id_wrapper<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,9 +21,15 @@
#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>
#include <boost/config/workaround.hpp>
#include <ostream>
#include <new>
#include <cstdio>
@@ -52,12 +58,14 @@ namespace system
// and error_code containing a pointer to an object of a type derived
// from error_category.
bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
std::size_t hash_value( error_code const & ec );
class error_code
{
private:
friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT;
friend std::size_t hash_value( error_code const & ec );
private:
@@ -109,7 +117,10 @@ public:
// constructors:
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
#if !BOOST_WORKAROUND(BOOST_GCC, < 40800)
BOOST_CONSTEXPR
#endif
error_code() BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
}
@@ -139,28 +150,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 +195,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 +208,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();
@@ -387,7 +403,12 @@ public:
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;
if( s1 != s2 ) return false;
if( s1 && s2 )
{
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
@@ -405,7 +426,13 @@ public:
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
bool s1 = lhs.lc_flags_ == 1;
bool s2 = rhs.lc_flags_ == 1;
if( s1 < s2 ) return true;
if( s2 < s1 ) return false;
if( s1 && s2 )
{
std::error_code const& e1 = *reinterpret_cast<std::error_code const*>( lhs.d2_ );
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( rhs.d2_ );
@@ -424,48 +451,6 @@ public:
return !( lhs == rhs );
}
inline friend bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline friend bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
inline friend bool operator==( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
@@ -668,6 +653,37 @@ public:
}
};
inline bool operator==( const error_code & code, const error_condition & condition ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( code.lc_flags_ == 1 )
{
return static_cast<std::error_code>( code ) == static_cast<std::error_condition>( condition );
}
else
#endif
{
return code.category().equivalent( code.value(), condition ) || condition.category().equivalent( code, condition.value() );
}
}
inline bool operator==( const error_condition & condition, const error_code & code ) BOOST_NOEXCEPT
{
return code == condition;
}
inline bool operator!=( const error_code & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline bool operator!=( const error_condition & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline std::size_t hash_value( error_code const & ec )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)

View File

@@ -261,6 +261,58 @@ public:
return !( lhs == rhs );
}
//
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return lhs == make_error_condition( rhs );
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return make_error_condition( lhs ) == rhs;
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
//
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator==( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return lhs == make_error_code( rhs );
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator==( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return make_error_code( lhs ) == rhs;
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator!=( error_condition const & lhs, E rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
template<class E, class N1 = void, class N2 = typename detail::enable_if<std::is_error_code_enum<E>::value>::type>
inline friend bool operator!=( E lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#endif
std::string to_string() const

View File

@@ -11,9 +11,7 @@
// 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 <boost/config.hpp>
#include <system_error>
//
@@ -27,6 +25,8 @@ namespace system
namespace detail
{
template<unsigned Id> struct id_wrapper {};
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
{
private:
@@ -35,20 +35,29 @@ private:
public:
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
boost::system::error_category const & original_category() const BOOST_NOEXCEPT
{
return *pc_;
}
public:
template<unsigned Id>
explicit std_category( boost::system::error_category const * pc, id_wrapper<Id> ): pc_( pc )
{
if( id != 0 )
{
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000
// Poking into the protected _Addr member of std::error_category
// is not a particularly good programming practice, but what can
// you do
// We used to assign to the protected _Addr member of std::error_category
// here when Id != 0, but this should never happen now because this code
// path is no longer used
_Addr = id;
#if !defined(BOOST_NO_CXX11_STATIC_ASSERT)
static_assert( Id == 0, "This constructor should only be called with Id == 0 under MS STL 14.0+" );
#endif
#endif
}
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
@@ -66,72 +75,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

@@ -59,6 +59,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_ACCESS_DENIED_: return permission_denied;
case ERROR_ALREADY_EXISTS_: return file_exists;
case ERROR_BAD_NETPATH_: return no_such_file_or_directory;
case ERROR_BAD_NET_NAME_: return no_such_file_or_directory;
case ERROR_BAD_UNIT_: return no_such_device;
case ERROR_BROKEN_PIPE_: return broken_pipe;
case ERROR_BUFFER_OVERFLOW_: return filename_too_long;
@@ -75,6 +76,7 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_DIR_NOT_EMPTY_: return directory_not_empty;
case ERROR_DIRECTORY_: return invalid_argument; // WinError.h: "The directory name is invalid"
case ERROR_DISK_FULL_: return no_space_on_device;
case ERROR_FILENAME_EXCED_RANGE_: return filename_too_long;
case ERROR_FILE_EXISTS_: return file_exists;
case ERROR_FILE_NOT_FOUND_: return no_such_file_or_directory;
case ERROR_HANDLE_DISK_FULL_: return no_space_on_device;
@@ -100,12 +102,16 @@ inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
case ERROR_REPARSE_TAG_INVALID_: return invalid_argument;
case ERROR_RETRY_: return resource_unavailable_try_again;
case ERROR_SEEK_: return io_error;
case ERROR_SEM_TIMEOUT_: return timed_out;
case ERROR_SHARING_VIOLATION_: return permission_denied;
case ERROR_NOT_SUPPORTED_: return not_supported; // WinError.h: "The request is not supported."
case ERROR_TIMEOUT_: return timed_out;
case ERROR_TOO_MANY_OPEN_FILES_: return too_many_files_open;
case ERROR_WRITE_FAULT_: return io_error;
case ERROR_WRITE_PROTECT_: return permission_denied;
case 258: return timed_out; // WAIT_TIMEOUT
case WSAEACCES_: return permission_denied;
case WSAEADDRINUSE_: return address_in_use;
case WSAEADDRNOTAVAIL_: return address_not_available;

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

@@ -18,6 +18,7 @@
#include <utility>
#include <iosfwd>
#include <system_error>
#include <exception>
//
@@ -35,12 +36,34 @@ namespace system
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 ), loc );
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_exception( std::system_error( e ), 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
@@ -72,6 +95,14 @@ private:
variant2::variant<T, E> v_;
public:
using value_type = T;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
public:
// constructors
@@ -112,7 +143,8 @@ public:
template<class... A, class En = typename std::enable_if<
std::is_constructible<T, A...>::value &&
!(detail::is_errc_t<A...>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A...>::value
!std::is_constructible<E, A...>::value &&
sizeof...(A) >= 1
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<T, A...>::value )
@@ -123,7 +155,8 @@ public:
// explicit, error
template<class... A, class En2 = void, class En = typename std::enable_if<
!std::is_constructible<T, A...>::value &&
std::is_constructible<E, A...>::value
std::is_constructible<E, A...>::value &&
sizeof...(A) >= 1
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
@@ -151,6 +184,43 @@ public:
{
}
// converting
template<class T2, class E2, class En = typename std::enable_if<
std::is_convertible<T2, T>::value &&
std::is_convertible<E2, E>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<T2, E2> const& r2 )
noexcept(
std::is_nothrow_constructible<T, T2 const&>::value &&
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
v_.template emplace<0>( *r2 );
}
}
template<class T2, class E2, class En = typename std::enable_if<
std::is_convertible<T2, T>::value &&
std::is_convertible<E2, E>::value
>::type>
BOOST_CXX14_CONSTEXPR result( result<T2, E2>&& r2 )
noexcept(
std::is_nothrow_constructible<T, T2&&>::value &&
std::is_nothrow_constructible<E, E2>::value &&
std::is_nothrow_default_constructible<E2>::value &&
std::is_nothrow_copy_constructible<E2>::value )
: v_( in_place_error, r2.error() )
{
if( r2 )
{
v_.template emplace<0>( std::move( *r2 ) );
}
}
// queries
constexpr bool has_value() const noexcept
@@ -160,7 +230,7 @@ public:
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
return v_.index() == 1;
}
constexpr explicit operator bool() const noexcept
@@ -331,6 +401,14 @@ public:
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
// emplace
template<class... A>
BOOST_CXX14_CONSTEXPR T& emplace( A&&... a )
{
return v_.template emplace<0>( std::forward<A>(a)... );
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
@@ -382,6 +460,14 @@ private:
variant2::variant<variant2::monostate, E> v_;
public:
using value_type = void;
using error_type = E;
static constexpr in_place_value_t in_place_value{};
static constexpr in_place_error_t in_place_error{};
public:
// constructors
@@ -449,7 +535,7 @@ public:
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
return v_.index() == 1;
}
constexpr explicit operator bool() const noexcept
@@ -495,6 +581,13 @@ public:
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
// emplace
BOOST_CXX14_CONSTEXPR void emplace()
{
v_.template emplace<0>();
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )

View File

@@ -15,6 +15,7 @@ macro(system_run s1)
boost_test(SOURCES ${s1} ${ARGN})
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_NO_ANSI_APIS NAME ${n1}_no_ansi)
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_USE_UTF8 NAME ${n1}_utf8)
boost_test(SOURCES ${s1} ${ARGN} COMPILE_DEFINITIONS BOOST_SYSTEM_DISABLE_THREADS NAME ${n1}_nthr)
endmacro()
@@ -116,6 +117,23 @@ 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)
boost_test(TYPE compile SOURCES constexpr_test2.cpp)
boost_test(TYPE run SOURCES error_code_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test15.cpp)
boost_test(TYPE run SOURCES win32_generic_test.cpp)
boost_test(TYPE run SOURCES ec_hash_value_test.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
@@ -134,3 +152,7 @@ boost_test(TYPE run SOURCES result_eq.cpp)
boost_test(TYPE run SOURCES result_range_for.cpp)
boost_test(TYPE run SOURCES result_value_construct2.cpp)
boost_test(TYPE run SOURCES result_error_construct2.cpp)
boost_test(TYPE run SOURCES result_convert_construct.cpp)
boost_test(TYPE run SOURCES result_typedefs.cpp)
boost_test(TYPE run SOURCES result_value_construct3.cpp)
boost_test(TYPE run SOURCES result_error_construct3.cpp)

View File

@@ -33,6 +33,7 @@ rule system-run ( sources + )
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>shared : $(sources[1]:B)_shared ] ;
result += [ run $(sources) : : : <define>BOOST_NO_ANSI_APIS : $(sources[1]:B)_no_ansi ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_USE_UTF8 : $(sources[1]:B)_utf8 ] ;
result += [ run $(sources) : : : <define>BOOST_SYSTEM_DISABLE_THREADS : $(sources[1]:B)_nthr ] ;
return $(result) ;
}
@@ -61,7 +62,11 @@ run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <li
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>shared : single_instance_lib_shared ;
system-run before_main_test.cpp ;
run-fail throws_assign_fail.cpp ;
run-fail throws_assign_fail.cpp : : :
# GCC 12 catches this at compile time with a warning
<toolset>gcc,<variant>release:<build>no ;
system-run constexpr_test.cpp ;
system-run win32_hresult_test.cpp ;
@@ -140,11 +145,28 @@ 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 ;
compile constexpr_test2.cpp ;
run error_code_test3.cpp ;
run std_interop_test15.cpp ;
run win32_generic_test.cpp ;
run ec_hash_value_test.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) ;
@@ -161,3 +183,8 @@ run result_range_for.cpp : : : $(CPP11) ;
run result_value_construct2.cpp : : : $(CPP11) ;
run result_error_construct2.cpp : : : $(CPP11) ;
run result_errc_construct.cpp : : : $(CPP11) ;
run result_convert_construct.cpp : : : $(CPP11) ;
run result_typedefs.cpp : : : $(CPP11) ;
run result_value_construct3.cpp : : : $(CPP11) ;
run result_error_construct3.cpp : : : $(CPP11) ;
run result_emplace.cpp : : : $(CPP11) ;

35
test/constexpr_test2.cpp Normal file
View File

@@ -0,0 +1,35 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_code.hpp>
#include <boost/config.hpp>
#include <boost/config/pragma_message.hpp>
#if defined(BOOST_GCC) && BOOST_GCC >= 40700 && BOOST_GCC < 40800
BOOST_PRAGMA_MESSAGE("Skipping test, BOOST_GCC is 407xx")
#else
struct X
{
boost::system::error_code ec;
};
X const& f()
{
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30900
BOOST_STATIC_CONSTEXPR X x = {};
return x;
#else
BOOST_STATIC_CONSTEXPR X x;
return x;
#endif
}
#endif

132
test/ec_hash_value_test.cpp Normal file
View File

@@ -0,0 +1,132 @@
// Copyright 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/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <system_error>
#endif
namespace sys = boost::system;
int main()
{
// normal against normal (equal, system)
{
sys::error_code e2( 0, sys::system_category() );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (equal, generic)
{
sys::error_code e2( EINVAL, sys::generic_category() );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, value, generic)
{
sys::error_code e2( 0, sys::generic_category() );
sys::error_code e3( EINVAL, sys::generic_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, value, system)
{
sys::error_code e2( 1, sys::system_category() );
sys::error_code e3( 2, sys::system_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal against normal (inequal, category)
{
sys::error_code e2( 0, sys::system_category() );
sys::error_code e3( 0, sys::generic_category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against normal
{
sys::error_code e2;
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
// std:: wrapping against normal
{
std::error_code e1( EINVAL, std::generic_category() );
sys::error_code e2( e1 );
sys::error_code e3( e2.value(), e2.category() );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against wrapping std:: empty
{
std::error_code e1;
sys::error_code e2( e1 );
sys::error_code e3;
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// empty against roundtrip via std
{
sys::error_code e2;
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal/generic against roundtrip via std
{
sys::error_code e2( EINVAL, boost::system::generic_category() );
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
// normal/system against roundtrip via std
{
sys::error_code e2( 0, boost::system::system_category() );
std::error_code e1( e2 );
sys::error_code e3( e1 );
BOOST_TEST( e2 != e3 || hash_value( e2 ) == hash_value( e3 ) );
BOOST_TEST( e2 == e3 || hash_value( e2 ) != hash_value( e3 ) );
}
#endif
return boost::report_errors();
}

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();
}

69
test/error_code_test3.cpp Normal file
View File

@@ -0,0 +1,69 @@
// Copyright 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_condition.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
enum my_errc
{
enomem_c = ENOMEM
};
enum my_errn
{
enomem_n = ENOMEM
};
namespace boost {
namespace system {
template<> struct is_error_code_enum<my_errc>
{
static const bool value = true;
};
template<> struct is_error_condition_enum<my_errn>
{
static const bool value = true;
};
} // namespace system
} // namespace boost
sys::error_code make_error_code( my_errc e )
{
return sys::error_code( e, sys::generic_category() );
}
sys::error_condition make_error_condition( my_errn e )
{
return sys::error_condition( e, sys::generic_category() );
}
int main()
{
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
sys::error_condition en( sys::errc::not_enough_memory );
BOOST_TEST_EQ( ec, en );
BOOST_TEST_EQ( en, ec );
BOOST_TEST_EQ( ec, enomem_c );
BOOST_TEST_EQ( enomem_c, ec );
BOOST_TEST_EQ( ec, enomem_n );
BOOST_TEST_EQ( enomem_n, ec );
BOOST_TEST_EQ( en, enomem_c );
BOOST_TEST_EQ( enomem_c, en );
BOOST_TEST_EQ( en, enomem_n );
BOOST_TEST_EQ( enomem_n, en );
return boost::report_errors();
}

View File

@@ -0,0 +1,202 @@
// 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>
using namespace boost::system;
struct X
{
static int instances;
int v_;
X(): v_() { ++instances; }
X( int v ): v_( v ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X& operator=( X const& ) = delete;
~X() { --instances; }
};
bool operator==( X const & x1, X const & x2 )
{
return x1.v_ == x2.v_;
}
std::ostream& operator<<( std::ostream& os, X const & x )
{
os << "X:" << x.v_;
return os;
}
int X::instances = 0;
int main()
{
{
result<int> r( 5 );
result<long> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 5 );
}
{
result<int> const r( 6 );
result<long> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 6 );
}
{
result<long> r2 = result<int>( 7 );
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 7 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int> r( 5 );
result<X> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 5 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<int> const r( 6 );
result<X> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 6 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r2 = result<int>( 7 );
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, 7 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<long> r2 = r;
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<int> r( ec );
result<long> r2 = r;
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), ec );
}
{
auto ec = make_error_code( errc::invalid_argument );
result<long> r2 = result<int>( ec );
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), ec );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<char const*, int> r( "test" );
result<std::string, X> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
BOOST_TEST_EQ( X::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<char const*, int> const r( "test" );
result<std::string, X> r2 = r;
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
BOOST_TEST_EQ( X::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<std::string, X> r2 = result<char const*, int>( "test" );
BOOST_TEST( r2 ) && BOOST_TEST_EQ( *r2, std::string( "test" ) );
BOOST_TEST_EQ( X::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<char const*, int> r( 5 );
result<std::string, X> r2 = r;
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), X(5) );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<char const*, int> const r( 6 );
result<std::string, X> r2 = r;
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), X(6) );
BOOST_TEST_EQ( X::instances, 1 );
}
{
result<std::string, X> r2 = result<char const*, int>( 7 );
BOOST_TEST( !r2 );
BOOST_TEST_EQ( r2.error(), X(7) );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
BOOST_TEST_TRAIT_TRUE((std::is_constructible<result<long>, result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_convertible<result<int>, result<long>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, result<void*>>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<void*>, result<int>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int>, result<void>>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<void>, result<int>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<void>, result<int>>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<int>, result<void>>));
BOOST_TEST_TRAIT_FALSE((std::is_constructible<result<int, void*>, result<int, int>>));
BOOST_TEST_TRAIT_FALSE((std::is_convertible<result<int, int>, result<int, void*>>));
}
return boost::report_errors();
}

View File

@@ -12,6 +12,11 @@ struct X
{
};
struct Y
{
Y( int );
};
int main()
{
{
@@ -37,5 +42,17 @@ int main()
BOOST_TEST( !r.has_error() );
}
{
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<int, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<X, int>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void>>));
BOOST_TEST_TRAIT_TRUE((std::is_default_constructible<result<void, int>>));
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y>>));
BOOST_TEST_TRAIT_FALSE((std::is_default_constructible<result<Y, int>>));
}
return boost::report_errors();
}

176
test/result_emplace.cpp Normal file
View File

@@ -0,0 +1,176 @@
// 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 <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
struct Y
{
static int instances;
Y() noexcept { ++instances; }
Y( Y const& ) noexcept { ++instances; }
Y& operator=( Y const& ) = default;
~Y() { --instances; }
};
int Y::instances = 0;
int main()
{
{
result<int> r;
BOOST_TEST( r.has_value() );
r.emplace( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value(), 1 );
}
{
result<int> r( ENOENT, generic_category() );
BOOST_TEST( !r.has_value() );
r.emplace( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value(), 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( 0 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value().v_, 0 );
BOOST_TEST_EQ( X::instances, 1 );
r.emplace( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
r.emplace( 1, 2 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
r.emplace( 1, 2, 3 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
result<X> r( ENOENT, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST_EQ( X::instances, 0 );
r.emplace( 1, 2 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r.value().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<int, Y> r( Y{} );
BOOST_TEST( !r.has_value() );
BOOST_TEST_EQ( Y::instances, 1 );
r.emplace( 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( *r, 1 );
BOOST_TEST_EQ( Y::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<X, Y> r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 1 );
r.emplace( 1, 2, 3 );
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( r->v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
BOOST_TEST_EQ( Y::instances, 0 );
}
BOOST_TEST_EQ( X::instances, 0 );
BOOST_TEST_EQ( Y::instances, 0 );
{
result<void> r;
BOOST_TEST( r.has_value() );
r.emplace();
BOOST_TEST( r.has_value() );
}
{
result<void> r( ENOENT, generic_category() );
BOOST_TEST( !r.has_value() );
r.emplace();
BOOST_TEST( r.has_value() );
}
BOOST_TEST_EQ( Y::instances, 0 );
{
result<void, Y> r( in_place_error );
BOOST_TEST( !r.has_value() );
BOOST_TEST_EQ( Y::instances, 1 );
r.emplace();
BOOST_TEST( r.has_value() );
BOOST_TEST_EQ( Y::instances, 0 );
}
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

@@ -0,0 +1,161 @@
// 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 <string>
#include <cerrno>
using namespace boost::system;
struct X
{
static int instances;
int v_;
X(): v_() { ++instances; }
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& r ): v_( r.v_ ) { ++instances; }
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
auto ec = make_error_code( errc::invalid_argument );
using R = result<int>;
R r( R::in_place_error, ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
using R = result<int>;
R r( R::in_place_error, EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
{
auto ec = make_error_code( errc::invalid_argument );
using R = result<error_code>;
R r( R::in_place_error, ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
using R = result<error_code>;
R r( R::in_place_error, EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<std::string, X>;
R r( R::in_place_error, 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<int, X>;
R r( R::in_place_error, 1, 2 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<int, X>;
R r( R::in_place_error, 1, 2, 3 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X, X>;
R r( R::in_place_error, 1 );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
auto ec = make_error_code( errc::invalid_argument );
using R = result<void>;
R r( R::in_place_error, ec );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), ec );
}
{
using R = result<void>;
R r( R::in_place_error, EINVAL, generic_category() );
BOOST_TEST( !r.has_value() );
BOOST_TEST( r.has_error() );
BOOST_TEST_EQ( r.error(), error_code( EINVAL, generic_category() ) );
}
return boost::report_errors();
}

22
test/result_typedefs.cpp Normal file
View File

@@ -0,0 +1,22 @@
// Copyright 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_trait.hpp>
using namespace boost::system;
struct X {};
int main()
{
BOOST_TEST_TRAIT_SAME( result<int>::value_type, int );
BOOST_TEST_TRAIT_SAME( result<X>::value_type, X );
BOOST_TEST_TRAIT_SAME( result<void>::value_type, void );
BOOST_TEST_TRAIT_SAME( result<int>::error_type, error_code );
BOOST_TEST_TRAIT_SAME( result<int, X>::error_type, X );
return boost::report_errors();
}

View File

@@ -5,6 +5,7 @@
#include <boost/system/result.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/config.hpp>
#include <system_error>
using namespace boost::system;
@@ -32,6 +33,10 @@ BOOST_NORETURN void throw_exception_from_error( Y const &, boost::source_locatio
throw E();
}
struct E2
{
};
int main()
{
{
@@ -182,6 +187,65 @@ int main()
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 );
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
#else
BOOST_TEST_THROWS( r.value(), E2 );
#endif
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 );
@@ -374,5 +438,64 @@ int main()
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 );
#if defined(BOOST_CLANG_VERSION) && BOOST_CLANG_VERSION < 30600
#else
BOOST_TEST_THROWS( r.value(), E2 );
#endif
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();
}

View File

@@ -0,0 +1,118 @@
// 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>
using namespace boost::system;
struct X
{
static int instances;
int v_;
explicit X( int v ): v_( v ) { ++instances; }
X( int v1, int v2 ): v_( v1+v2 ) { ++instances; }
X( int v1, int v2, int v3 ): v_( v1+v2+v3 ) { ++instances; }
X( X const& ) = delete;
X& operator=( X const& ) = delete;
~X() { --instances; }
};
int X::instances = 0;
int main()
{
{
using R = result<int>;
R r( R::in_place_value, 0 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value(), 0 );
}
{
using R = result<int, int>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( *r, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1, 2 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X>;
R r( R::in_place_value, 1, 2, 3 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r.value().v_, 1+2+3 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<X, X>;
R r( R::in_place_value, 1 );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
BOOST_TEST_EQ( r->v_, 1 );
BOOST_TEST_EQ( X::instances, 1 );
}
BOOST_TEST_EQ( X::instances, 0 );
{
using R = result<void>;
R r( R::in_place_value );
BOOST_TEST( r.has_value() );
BOOST_TEST( !r.has_error() );
}
return boost::report_errors();
}

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

@@ -0,0 +1,94 @@
// 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_condition.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "BOOST_SYSTEM_HAS_SYSTEM_ERROR not defined, test will be skipped" )
int main() {}
#elif defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY is defined" )
int main() {}
#else
#include <system_error>
namespace sys = boost::system;
enum my_errc
{
enomem_c = ENOMEM
};
enum my_errn
{
enomem_n = ENOMEM
};
namespace std {
template<> struct is_error_code_enum<my_errc>
{
static const bool value = true;
};
template<> struct is_error_condition_enum<my_errn>
{
static const bool value = true;
};
} // namespace std
std::error_code make_error_code( my_errc e )
{
return std::error_code( e, std::generic_category() );
}
std::error_condition make_error_condition( my_errn e )
{
return std::error_condition( e, std::generic_category() );
}
int main()
{
sys::error_code ec = make_error_code( sys::errc::not_enough_memory );
sys::error_condition en( sys::errc::not_enough_memory );
BOOST_TEST_EQ( ec, en );
BOOST_TEST_EQ( en, ec );
BOOST_TEST_EQ( ec, enomem_c );
BOOST_TEST_EQ( enomem_c, ec );
BOOST_TEST_EQ( ec, enomem_n );
BOOST_TEST_EQ( enomem_n, ec );
BOOST_TEST_EQ( en, enomem_c );
BOOST_TEST_EQ( enomem_c, en );
#if BOOST_WORKAROUND(BOOST_MSVC, == 1800)
// msvc-12.0 has op== as a member of std::error_condition
#else
BOOST_TEST_EQ( en, enomem_n );
#endif
BOOST_TEST_EQ( enomem_n, en );
return boost::report_errors();
}
#endif

View File

@@ -0,0 +1,52 @@
// Copyright 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/config.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_SYSTEM_HAS_SYSTEM_ERROR is not defined" )
int main() {}
#elif !defined(BOOST_MSSTL_VERSION) || BOOST_MSSTL_VERSION < 140
BOOST_PRAGMA_MESSAGE( "Skipping test, BOOST_MSSTL_VERSION is not defined or is less than 140" )
int main() {}
#else
#include <system_error>
#include <iostream>
int main()
{
namespace sys = boost::system;
int n = 0;
for( int i = 0; i < 65000; ++i )
{
sys::error_code ec1( i, sys::system_category() );
sys::error_condition en1 = ec1.default_error_condition();
std::error_code ec2( i, std::system_category() );
std::error_condition en2 = ec2.default_error_condition();
if( en1 != en2 )
{
std::cout << i << ": " << en1 << " (" << en1.message() << ") != cond:" << en2.category().name() << ":" << en2.value() << " (" << en2.message() << ")\n";
if( en2.category() == std::generic_category() && i != 123 ) // msvc-14.0, msvc-14.1 disagree with us on ERROR_INVALID_NAME
{
++n;
}
}
}
return n < 256 ? n: 255;
}
#endif