Compare commits

...

667 Commits

Author SHA1 Message Date
9e1ea0296e glob headers 2022-07-05 10:48:40 +02:00
96b876d91a Add README.md 2022-06-19 02:19:58 +03:00
eb9ae4ac69 Update revision history 2022-06-19 01:30:17 +03:00
8fd487d496 Update documentation 2022-06-19 01:28:36 +03:00
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
a5ee3f291c Update ci.yml 2022-06-18 21:47:57 +03:00
4200b00973 Add converting constructor to result (refs #82) 2022-06-18 18:12:06 +03:00
533dfe1688 Update revision history 2022-05-05 21:17:09 +03:00
7dec756a6f Update documentation 2022-05-05 21:15:03 +03:00
648a35838b Remove unnecessary overloads 2022-05-05 05:12:08 +03:00
256fe92dbb Add error_code(error_code const& ec, source_location const* loc) and a corresponding assign 2022-05-05 05:02:37 +03:00
5debb8a041 Update revision history 2022-05-05 02:30:07 +03:00
a97e5a0546 Move BOOST_NOINLINE to operator std::error_category 2022-04-22 22:41:26 +03:00
dc17edfa07 Remove clang-win from appveyor.yml 2022-04-22 21:16:09 +03:00
65da7dfd56 Update result_error_construct tests to use sys::error_code instead of (erroneously) std::error_code 2022-04-22 19:52:19 +03:00
9279001b8c Check BOOST_NO_CXX11_HDR_MUTEX when enabling <system_error> integration 2022-04-22 16:49:03 +03:00
616e652bd7 Suppress strict-aliasing warning for gcc 4.8 to 6 2022-04-21 21:06:14 +03:00
98439855bd Use static_cast instead of reinterpret_cast 2022-04-21 20:52:02 +03:00
986efb1420 Rework conversion to std::error_category to not allocate (closes #78) 2022-04-21 20:32:25 +03:00
28a13571b9 Restore the original system::error_code from std::error_code (refs #79) 2022-03-18 18:24:01 +02:00
65ed1eef66 Add std_interop_test14.cpp (refs #79) 2022-03-18 08:12:05 +02:00
6de20eeebc Add std_interop_test13 2022-03-18 08:12:05 +02:00
0a9266ea7e Add a comment explaining the one-time allocation in error_category_impl.hpp. Fixes #78. 2022-03-18 08:11:16 +02:00
adb9fc54cb Remove msvc-14.1 from ci.yml 2022-03-18 07:51:38 +02:00
e197c5e803 Update documentation 2022-02-18 19:43:08 +02:00
6d7a57a970 Add throw_exception_from_error overload for std::exception_ptr 2022-02-18 02:55:34 +02:00
00c71cf388 Add throw_exception_from_error overloads for boost::system::errc, std::errc 2022-02-17 21:55:47 +02:00
d930cea481 Update documentation 2022-02-14 02:05:44 +02:00
4f09f4adde Use throw_with_location in throw_exception_from_error 2022-02-13 22:50:20 +02:00
abd62362ef Update documentation 2022-02-09 20:52:23 +02:00
8d8e6a90de Add an errc::make_error_code overload taking a source location 2022-02-09 20:41:34 +02:00
716c2ed8ef Disable result tests on GCC 4.7 2022-02-07 21:40:26 +02:00
46a5ecd490 Do not include boost/system/result.hpp on GCC 4.7 2022-02-07 21:38:14 +02:00
79f4ef0416 Remove .drone.star 2022-02-07 21:34:11 +02:00
d0a8f7fbb7 Squash-merge feature/drone-jsonnet into develop 2022-02-07 21:33:48 +02:00
bc07ab1e25 Update .drone.star 2022-02-07 05:09:49 +02:00
c6bff94709 Update std_interop_test12.cpp 2022-02-07 04:35:44 +02:00
ae079810be Add std_interop_test12.cpp 2022-02-07 04:30:50 +02:00
928de55563 Update .drone.star 2022-02-07 03:47:42 +02:00
442138de0a Update .drone.star 2022-02-07 03:41:35 +02:00
de610efd53 Move conditions to detail/config.hpp 2022-02-07 03:16:23 +02:00
4b143cdacc Use BOOST_LIBSTDCXX_VERSION instead of BOOST_GCC; update syscat condition 2022-02-07 03:02:57 +02:00
a1cb578f52 Update .drone.star 2022-02-07 02:55:54 +02:00
96b5073b79 Update .drone.star 2022-02-07 02:03:13 +02:00
2bff5c7071 Update .drone.star 2022-02-07 01:27:59 +02:00
137128176d Update .drone.star 2022-02-07 01:14:28 +02:00
e0e0f56eae Update .drone.star 2022-02-07 00:54:07 +02:00
58d55a67e5 Update .drone.star 2022-02-07 00:01:53 +02:00
34dcb59ee8 Update drone.bat 2022-02-06 23:30:19 +02:00
33f6ecba31 Update Drone files 2022-02-06 23:21:40 +02:00
23fbfb1ffa Update .drone.star 2022-02-06 22:55:48 +02:00
5366407135 Add Windows jobs to Drone 2022-02-06 22:42:19 +02:00
72a79b1dcb Disable -Wsign-compare for GCC 4.4 2022-02-06 22:29:28 +02:00
a5c1ab042e Update Drone files 2022-02-06 22:25:45 +02:00
c2beb75d66 Merge pull request #59 from sdarwin/drone
Drone config
2022-02-06 22:08:07 +02:00
54d9f4f38a Update documentation 2022-02-05 19:25:43 +02:00
b92be6417a Add a source_location parameter to throw_exception_from_error 2022-02-05 05:24:29 +02:00
245fff8af3 Update ci.yml 2022-02-05 03:11:09 +02:00
c359af3141 Update system_error constructors 2022-02-04 21:34:14 +02:00
50cad72fac Update system_error_test3.cpp 2022-02-04 21:22:35 +02:00
9554d8bbd3 Suppress incorrect warnings from GCC 7/8 2022-02-03 19:02:19 +02:00
cf9d986871 Update documentation 2022-02-03 18:47:53 +02:00
a5d68e52e6 Add throw_exception_from_error overload for std::error_code 2022-02-03 18:35:42 +02:00
9c6a09f41d Mark throw_exception_from_error as noinline 2022-02-03 09:37:59 +02:00
b9c26b9fa0 Add detail::system_error_category_message, use it in error_code::message 2022-02-03 05:47:43 +02:00
2e2430c4fa Add error_code::category_name helper, use it in to_string 2022-02-03 04:36:58 +02:00
4b1caad727 Avoid sign conversion warnings in error_code::value 2022-01-19 17:30:56 +02:00
5b96abbaa8 Undeprecate linux_error.hpp (closes #77) 2021-12-27 02:53:04 +02:00
2e1c800d82 Update appveyor.yml 2021-12-21 22:35:10 +02:00
04a79d710f Merge branch 'fix_error_code_wostream' of https://github.com/MarcelRaad/system into feature/pr-76 2021-12-21 19:51:50 +02:00
5700936367 Add ec_wstream_test (refs #76) 2021-12-21 19:51:08 +02:00
86b031cab9 Fix error_code's operator<< for arbitrary basic_ostream specializations
This fixes a regression from commit
a9b64a888a.
Calling `operator<<` with `std::string` only works for `std::ostream`.
Use `c_str()` to restore the previous behavior of using `const char*`,
which works for any `basic_ostream` specialization.
2021-12-21 13:17:26 +01:00
204e65f725 Add msvc-14.0 to GHA 2021-12-11 03:42:52 +02:00
01ce081470 Disable errc_t -> arithmetic conversions when initializing result (closes #74) 2021-12-11 01:22:08 +02:00
8c9ceba775 Add negative test for constructing result<int> from errc_t (refs #74) 2021-12-09 20:19:05 +02:00
91c0dd9a74 Merge pull request #73 from kpushkaryov/patch-1
Fix a typo
2021-11-17 06:24:18 +02:00
189fff42fe Fix a typo 2021-11-17 10:59:03 +07:00
3b4045c149 Minor doc update 2021-11-17 04:11:15 +02:00
3d877a1fca Update meta/libraries.json 2021-11-11 04:51:03 +02:00
128bdf9db2 Minor usage section changes 2021-11-11 04:33:06 +02:00
0e84860604 Add another usage subsection 2021-11-11 04:09:49 +02:00
83a306f3bf Update introduction 2021-11-10 20:36:57 +02:00
7dce2e3f42 Change 'wrapping' to 'adapting' 2021-11-10 18:52:41 +02:00
292c6825c6 Add another usage subsection 2021-11-09 22:05:45 +02:00
0d90d3d883 Add myimg_category implementation to usage example 2021-11-08 20:50:41 +02:00
81fec2b171 Add another usage subsection 2021-11-07 23:45:25 +02:00
4e15afe5be Add error handling and programming categories to libraries.json 2021-11-07 20:32:42 +02:00
8d1a866920 Add a usage subsection on wrapping zlib errors 2021-11-05 22:05:23 +02:00
09466c85b4 Add another usage subsection 2021-11-05 20:38:03 +02:00
baef8e50ea Rename 'Usage Examples' to 'Usage', add another subsection 2021-11-05 16:48:33 +02:00
5034f11a3a Add usage examples 2021-11-02 03:12:26 +02:00
f78b036665 Update #if condition 2021-10-29 21:13:10 +03:00
9b0d735040 Add __attribute__((__format__)) to snprintf
This attribute will check format string bugs and is required for clean compile if -Wformat-nonliteral is enabled.
2021-10-29 11:59:03 +01:00
bfebaf53d7 Add static_assert to cmake_subdir_test 2021-10-28 23:48:03 +03:00
8338e80295 Enable syntax hightlighting 2021-10-28 23:17:20 +03:00
2b23aaab16 Add msvc-14.3 to ci.yml 2021-10-28 23:16:53 +03:00
7933300b6f Disable test on g++ 4.x because no std::io_errc 2021-10-11 03:30:50 +03:00
4ec1e54099 Enable error_code construction from enums specializing std::is_error_code_enum. Fixes #70. 2021-10-11 02:02:22 +03:00
5217e58a7d Enable implicit construction for aggregates using {{ ... }} 2021-10-02 22:07:05 +03:00
ce37e23491 Protect against dangling references in op* and value() 2021-10-02 19:16:04 +03:00
420a262733 Fix warnings_test.cpp 2021-10-02 17:25:31 +03:00
e15bccc09b Fix cmake_install_test/main.cpp 2021-10-02 16:57:38 +03:00
bb775c071a Update system_error::what to use error_code::what 2021-10-02 15:00:40 +03:00
01676ae42f Update documentation 2021-10-02 14:47:07 +03:00
eefcc5dcf6 Add error_code::what 2021-10-02 14:41:27 +03:00
f2d3a0decf Update documentation 2021-10-02 01:39:06 +03:00
0ccf08509b Add a constructor taking ErrorCodeEnum and a source location 2021-10-01 23:04:04 +03:00
7a72aee355 Merge branch 'develop' into feature/std-category-2 2021-09-24 23:54:51 +03:00
a8df99e927 Use source_location::to_string in system_error::build_message 2021-09-24 20:40:19 +03:00
85c7d92302 Avoid instantiating the system category in error_code::operator std::error_code 2021-09-24 15:24:45 +03:00
4c201d26b2 Update std_interop_test10 2021-09-24 04:29:29 +03:00
1659dfbeba Avoid instantiating generic_category in error_condition::operator std::error_condition 2021-09-24 04:27:08 +03:00
d2b8b54356 Do not use std::system_category under MinGW and g++ 4.x 2021-09-21 16:35:40 +03:00
41f7ea49cb Do not use std::system_category under VS2013 2021-09-21 16:02:12 +03:00
0b22dc595f Merge branch 'develop' into feature/std-category-2 2021-09-21 15:57:56 +03:00
aab58b0d5b Add std_interop_test10 2021-09-21 15:57:39 +03:00
ad66ea43a3 Revert addition of get_generic_std_category, get_system_std_category (they need this); do not use std::system_category on Cygwin 2021-09-21 15:45:00 +03:00
811564f186 Disable failing comparisons in std_interop_test6; stdlibs are at fault 2021-09-21 15:11:19 +03:00
a7e4879e55 Fix message comparisons in std_interop_test 2021-09-21 15:06:28 +03:00
9b11d864be Add helper functions get_generic_std_category, get_system_std_category 2021-09-21 15:01:44 +03:00
cc6a61b6c5 Convert system_category to std::system_category 2021-09-21 05:34:05 +03:00
9151633c95 Merge branch 'develop' into feature/std-category 2021-09-20 17:41:47 +03:00
5e0db22075 Include errc.hpp in system_error.hpp 2021-09-20 17:41:34 +03:00
60a20eeeb9 Retain old generic_category conversion behavior on g++ 4.8/4.9 2021-09-19 18:44:45 +03:00
1c8128e4cb Merge branch 'develop' into feature/std-category 2021-09-19 18:12:59 +03:00
1879ba6d35 Minor test update 2021-09-19 18:12:46 +03:00
b1dec88674 Convert generic_category to std::generic_category 2021-09-19 17:08:46 +03:00
5fd2535d9f Excise generic_category() references from error_condition 2021-09-19 16:04:16 +03:00
b39f239b3d Update documentation 2021-09-19 15:53:13 +03:00
abb13e707d Minor test fixes 2021-09-19 15:46:03 +03:00
bf34091cfe Add error_code_test2 2021-09-19 15:41:20 +03:00
e3f198e52c Add error_condition::to_string 2021-09-19 15:37:49 +03:00
05581aba03 Add error_condition_test3 2021-09-19 15:26:19 +03:00
47137ad116 Change predefined error_category identifiers to be contiguous for better codegen 2021-09-19 15:04:51 +03:00
c02cd2b004 Add private error_code::equals, use it in error_category::equivalent 2021-09-19 05:24:08 +03:00
c8c5ad1ce5 Rework error_condition::op== to not require the generic_category() instance 2021-09-19 04:49:35 +03:00
361834e49c Minor documentation corrections 2021-09-18 16:57:21 +03:00
360effcf1d Remove static/shared tests, System is header-only 2021-09-18 02:23:21 +03:00
aaa893b5d6 Add mp11 to cmake_subdir_test/CMakeLists.txt 2021-09-18 00:08:30 +03:00
ff0bd3294f Add back predef, winapi needs it 2021-09-17 23:54:33 +03:00
aedadc27ce Update test/cmake_subdir_test/CMakeLists.txt 2021-09-17 21:31:13 +03:00
aad1212cfd Update tests/CMakeLists.txt 2021-09-17 21:15:13 +03:00
c15c2eeb74 Update dependencies in CMakeLists.txt 2021-09-17 21:10:53 +03:00
0ea47dd886 Add CMake jobs to ci.yml 2021-09-17 21:00:18 +03:00
08c12e8ad5 Document result<void, E> 2021-09-17 20:16:01 +03:00
7d3cfdd09a Update test/result_value_construct 2021-09-17 19:54:53 +03:00
15f94537a6 Update test/result_value_access 2021-09-17 19:53:11 +03:00
c0f38e2f3e Update test/result_swap 2021-09-17 19:46:56 +03:00
ac28a8cec9 Update test/result_move_assign 2021-09-17 19:44:58 +03:00
4169ef3ce6 Update test/result_error_construct 2021-09-17 19:36:58 +03:00
ce49a7d1be Update test/result_move_construct 2021-09-17 19:35:20 +03:00
1a4eb29719 Update test/result_error_access 2021-09-17 19:35:05 +03:00
465f6c57da Update test/result_eq 2021-09-17 19:34:44 +03:00
cb8db34d7b Update test/result_copy_assign 2021-09-17 19:34:26 +03:00
2b6a708070 Update test/result_copy_construct 2021-09-17 19:25:20 +03:00
50f84f16dc Add result<void, E> specialization 2021-09-17 19:22:15 +03:00
fd21395802 Minor indentation fixes 2021-09-17 18:50:30 +03:00
cebb011a58 Update indentation in reference 2021-09-17 18:43:30 +03:00
3f67d3def5 Rename throw_exception_from_error_code to throw_exception_from_error 2021-09-17 18:33:04 +03:00
f2b3ae7e2b Document throw_exception_from_error_code 2021-09-17 18:28:53 +03:00
48e56b9874 Update revision history 2021-09-17 18:19:24 +03:00
967b7cbc98 Add result to reference 2021-09-17 18:16:54 +03:00
c8492a705d Use unsafe_get instead of *get_if 2021-09-17 15:47:35 +03:00
a3187439e3 Disable warning in after_main_test 2021-09-16 19:49:17 +03:00
19f9d0c5b4 Fix unused parameter error 2021-09-16 19:43:32 +03:00
d17f7d7fe6 Fix unused variable warning 2021-09-16 19:32:22 +03:00
36843a4e2d Fix unused variable warnings 2021-09-16 19:30:28 +03:00
a6c988181e Include result.hpp in <boost/system.hpp> 2021-09-16 19:25:26 +03:00
10572b7a59 Trim includes in system_error.hpp 2021-09-16 19:21:27 +03:00
fe3d0e6c14 Update all references to <system_error> to refer to Boost.System 2021-09-16 19:16:30 +03:00
ae77563039 Define result in boost::system instead of in boost::result 2021-09-16 18:56:35 +03:00
fd852c675e Add <boost/system/result.hpp> 2021-09-16 18:47:05 +03:00
6156076dab Specify assign in terms of construction and assignment 2021-09-16 18:13:55 +03:00
984f8f1a92 Reorder constructor overloads 2021-09-16 18:04:27 +03:00
b507b2294e Unbreak the loc == 0 case, even though the specification disallows it 2021-09-16 03:12:20 +03:00
39ad22d660 Update reference 2021-09-16 03:07:32 +03:00
3b70265ced Rearrange error_code::failed to improve codegen 2021-09-15 16:42:47 +03:00
a65b91b3fb Merge branch 'develop' into feature/source-location 2021-09-15 16:06:55 +03:00
bed0d59d22 Disable failing tests under g++ 7 -std=c++17 2021-09-15 15:23:52 +03:00
5e642b1d43 Remove error_condition::failed_ in order to prioritise construction efficiency over failed() efficiency (latter is rare for conditions) 2021-09-15 14:54:26 +03:00
b35b47d8c2 Reformat what() message slightly 2021-09-15 13:42:54 +03:00
f21035f8af Move location to the end of what() 2021-09-15 07:58:24 +03:00
cd98f4edd7 Update system_error to incorporate the source location in what() 2021-09-15 07:42:57 +03:00
a9b64a888a Add support for source_location to error_code 2021-09-15 07:03:18 +03:00
bb4b500cfc Update Windows error mapping to match msvc-14.2 <system_error> 2021-09-08 00:48:55 +03:00
d44dab91dc Merge pull request #62 from rohitk5252/patch-2
Update index.html
2021-09-08 00:24:46 +03:00
2b6498ad80 Merge pull request #63 from rohitk5252/patch-3
Update system.adoc
2021-09-08 00:24:30 +03:00
22072bfbc9 Merge pull request #64 from rohitk5252/patch-5
Update Jamfile.v2
2021-09-08 00:24:08 +03:00
65f644d5de Switch ubuntu-16.04 jobs to ubuntu-18.04 2021-09-07 21:57:40 +03:00
f967081d7e Merge pull request #69 from marc-groundctl/map-broken-pipe
Map ERROR_BROKEN_PIPE to errc_t::broken_pipe
2021-09-07 21:34:22 +03:00
19e9f08666 Map ERROR_BROKEN_PIPE to errc_t::broken_pipe 2021-09-07 12:02:02 -04:00
b41139b28e Update documentation 2021-06-16 03:06:26 +03:00
39a19f3c90 Add constexpr to op== against error code enums 2021-06-16 03:06:11 +03:00
b4dd5e98c9 Update appveyor.yml 2021-06-15 20:53:48 +03:00
41e3a7c8af Update appveyor.yml 2021-06-15 06:02:49 +03:00
aee97e91ce Update .travis.yml 2021-06-15 05:34:04 +03:00
98533dedb3 Disable failing tests on g++ 4.8 and 4.9 2021-06-15 05:32:04 +03:00
fe811d1dd1 Update .travis.yml 2021-06-15 03:17:42 +03:00
137ecb4abf Add more tests to std_interop_test7 2021-06-15 03:06:07 +03:00
e5cd7bf852 Placate g++ 6 and earlier 2021-06-15 02:25:13 +03:00
96cd1c0163 Add error_code comparisons against standard error code enums (to resolve the ambiguity when an enum is both standard and ours) 2021-06-15 02:17:26 +03:00
a9da17f2e2 Add std_interop_test9 2021-06-15 01:59:51 +03:00
f26dfd3dd7 Add error_code comparisons against standard error condition enums (to resolve the ambiguity when an enum is both standard and ours) 2021-06-15 01:52:32 +03:00
d09c998eb2 Add std_interop_test8 2021-06-15 01:43:49 +03:00
2374e85dc7 Add std_interop_test7 2021-06-14 22:25:31 +03:00
9167bf8ee8 Update documentation 2021-06-14 21:23:01 +03:00
7f7a9da4d5 Update revision history 2021-06-14 20:07:18 +03:00
67ae4d3c47 Disable std_interop_test5 on g++ 4.8 and 4.9, rather. 2021-06-14 19:04:15 +03:00
ee028e2f9d Remove tabs 2021-06-14 18:28:29 +03:00
7657188802 Disable std_interop_test5 on g++ 4.7 and 4.8; these crash on Xenial, but the real g++ 4.8 on CentOS 7 and Trusty works 2021-06-14 18:07:06 +03:00
210c54b09a Update .travis.yml 2021-06-14 17:36:29 +03:00
87bb5616a8 Update .travis.yml 2021-06-14 17:10:56 +03:00
6de562c79d Update .travis.yml 2021-06-14 15:10:36 +03:00
8efb96350f Clang 6 needs more help with mixed comparisons 2021-06-14 14:44:07 +03:00
88a7be42b5 Update Clang version check 2021-06-14 14:38:26 +03:00
a3225e78e2 Update GCC version check 2021-06-14 14:35:50 +03:00
3c469fe710 Update std_interop_test5.cpp 2021-06-14 04:19:45 +03:00
c2d044f34e Add std_interop_test6 2021-06-14 04:09:24 +03:00
9fdfa6c645 Move code == condition comparisons into error_code, unwrap std::error_code when needed 2021-06-14 04:06:24 +03:00
42a257e17c Add operator<< for error_condition 2021-06-14 03:59:44 +03:00
26d0d32c54 Add std_interop_test5 2021-06-14 03:53:55 +03:00
70b5449e99 Resolve ambiguity for std::error_code == boost::system::error_code 2021-06-14 03:53:00 +03:00
8043ce0278 Resolve ambiguity for std::error_code == boost::system::error_condition 2021-06-14 03:42:50 +03:00
83a2933afa Disable failing test cases on clang-6 and earlier 2021-06-14 02:54:40 +03:00
2e707ca921 Disable -Wstrict-aliasing on g++ 6, really 2021-06-14 02:50:31 +03:00
a6c4b6329c Add a deleted T const& conversion for clang-6 and earlier 2021-06-14 02:35:48 +03:00
5b1909eba4 Disable -Wstrict-aliasing on g++ 6 and below 2021-06-14 02:15:37 +03:00
9dc13fd82a Change value() when holding std::error_code 2021-06-14 02:09:31 +03:00
e9cdb10409 Use std::hash<std::error_code> in hash_value 2021-06-14 01:51:33 +03:00
e625bd0eea Do not access d2_ when <system_error> isn't available; use std::error_code comparisons in op== and op< 2021-06-13 22:48:31 +03:00
66656f7044 Use copy-init instead of direct-init for older clangs 2021-06-13 20:45:50 +03:00
0d8511f571 Use reinterpret_cast to pointer instead of to reference 2021-06-13 20:40:27 +03:00
fbc49bbaa0 Add more tests to std_interop_test3 2021-06-13 19:51:02 +03:00
344eb1e1f8 Rework error_code for better std interop 2021-06-13 19:47:37 +03:00
20b8e90dff Add detail/snprintf.hpp 2021-06-13 18:58:50 +03:00
a0136e570d Update tests/CMakeLists 2021-06-13 18:45:15 +03:00
6586fcb01e Add errc_test3.cpp 2021-06-13 18:42:59 +03:00
b74b1e3c8c Merge branch 'develop' into feature/error-condition 2021-06-13 07:12:16 +03:00
1caaacff57 Split reference into headers 2021-06-13 06:58:48 +03:00
75d5287558 Update copyright 2021-06-13 05:59:04 +03:00
25eaf0fdae Document comparisons as inline friends; use value() and category() instead of val_ and cat_; add subheadings 2021-06-13 05:58:16 +03:00
f43293f451 Increase ToC levels 2021-06-13 05:24:30 +03:00
f8ab3df822 Initialize failed_ in the other two constructors 2021-06-13 05:05:31 +03:00
f6fb85d7d3 Revert "Update Travis to use undefined-sanitizer; disable failed_constexpr_test"
This reverts commit c069ae048f.
2021-06-13 04:59:49 +03:00
9cd9d8732f Revert "Update test/Jamfile"
This reverts commit 3d4c31c213.
2021-06-13 04:59:38 +03:00
1b7fd6854d Revert "Disable failing tests on g++-7/c++17"
This reverts commit b20191f8d7.
2021-06-13 04:58:53 +03:00
610d5f3f78 Revert "Mark error_condition::failed, error_condition::message as deprecated; revert op bool"
This reverts commit 329e72fb92.
2021-06-13 04:56:18 +03:00
88f7c2bf53 Revert "Update documentation"
This reverts commit 8962c9101a.
2021-06-13 04:47:19 +03:00
723daf5d57 Update changelog 2021-06-13 04:39:39 +03:00
3d4c31c213 Update test/Jamfile 2021-06-13 01:13:48 +03:00
c069ae048f Update Travis to use undefined-sanitizer; disable failed_constexpr_test 2021-06-13 01:08:54 +03:00
28e1b919ac Disable failing test 2021-06-12 22:36:12 +03:00
b20191f8d7 Disable failing tests on g++-7/c++17 2021-06-12 22:20:38 +03:00
d019c1cdae Remove detail/is_generic_value.hpp 2021-06-12 22:01:16 +03:00
ff77d4c094 Do not call generic_category() in system_error_category 2021-06-12 21:59:22 +03:00
a21a3050a5 Use nullptr for &generic_category() in error_condition 2021-06-12 21:51:51 +03:00
08d62ac444 Restore Sun workaround 2021-06-12 05:42:03 +03:00
45e9dfeba9 Declare operator std::error_category as BOOST_SYMBOL_VISIBLE 2021-06-12 05:12:58 +03:00
7d9eb384c6 Make error_category comparisons inline friends, to avoid clang 'member call on mutable' constexpr errors 2021-06-12 04:52:21 +03:00
04bfb05b19 Improve the implementation of the std::category conversion 2021-06-12 04:29:13 +03:00
a650f5d676 Remove cmake_install_test dependency on Boost::core 2021-06-12 00:18:26 +03:00
6ab5fd9dac Update ci.yml 2021-06-11 22:15:46 +03:00
ed14d74323 Update .travis.yml 2021-06-11 22:12:35 +03:00
ff9bca96e3 Add boost/system.hpp 2021-06-11 21:15:17 +03:00
8560290b71 Merge pull request #67 from Lastique/feature/add_win32_error_not_supported
Add support for Windows error code ERROR_NOT_SUPPORTED
2021-05-29 03:36:51 +03:00
8b41ff22a6 Update ci.yml 2021-05-29 02:41:45 +03:00
79f9a297cd Update ci.yml 2021-05-29 01:15:51 +03:00
344ea58a77 Added support for Windows error code ERROR_NOT_SUPPORTED.
The error code description reads as "The request is not supported," which
is close to POSIX ENOTSUP "Not supported" and matches MSVC standard library
implementation.
2021-05-29 00:55:40 +03:00
5eae4824ab Update .github/workflows 2021-04-19 21:29:14 +03:00
f502e6cda4 Update .github/workflows 2021-04-19 20:30:50 +03:00
69bc20fb15 Merge pull request #66 from vahtis/vahtis-patch-1
Define BOOST_SYSTEM_DEPRECATED for Oracle Developer Studio
2021-03-22 17:23:49 +02:00
fbf7f4a417 Define BOOST_SYSTEM_DEPRECATED for Oracle Developer Studio
Added Oracle Developer Studio specific define.
2021-03-22 15:38:27 +02:00
a688d7834a add drone config [ci skip] 2021-01-21 19:45:47 +00:00
689e09e86f Merge pull request #65 from eldiener/develop
[skip ci] Add "cxxstd" json field
2021-01-21 18:58:57 +02:00
b92035d4d2 [skip ci] Add "cxxstd" json field. The "cxxstd" json field is being added to each Boost library's meta json information for libraries in order to specify the minumum C++ standard compilation level. The value of this field matches one of the values for 'cxxstd' in Boost.Build. The purpose of doing this is to provide information for the Boost website documentation for each library which will specify the minimum C++ standard compilation that an end-user must employ in order to use the particular library. This will aid end-users who want to know if they can successfully use a Boost library based on their C++ compiler's compilation level, without having to search the library's documentation to find this out. 2021-01-21 11:11:01 -05:00
1ba5c9efc4 Update Jamfile.v2 2021-01-20 16:35:23 +05:30
23db4e8d69 Update system.adoc 2021-01-20 16:31:00 +05:30
189cc0c185 Update index.html
Changed http:// to https://
2021-01-20 16:28:26 +05:30
63a32cea9a Remove deprecation message from windows_error.hpp (closes #57) 2021-01-02 22:16:39 +02:00
3e2cb8975f Update .travis.yml 2021-01-02 16:19:54 +02:00
4e7c88779b Merge branch 'patch-1' of https://github.com/tanzislam/system into feature/pr-56 2020-12-24 02:11:38 +02:00
3ee8200e75 Add .github/workflows 2020-12-24 02:10:50 +02:00
516484a821 Define BOOST_SYSTEM_DEPRECATED for other compilers
Currently compilation fails with Oracle Developer Studio 12.6, for example:

    $ ./b2 toolset=sun threading=multi variant=debug link=static cxxflags=-std=c++11 --with-system
    ...
    "./boost/system/detail/error_condition.hpp", line 96: Error: BOOST_SYSTEM_DEPRECATED is not defined.
    "./boost/system/detail/error_condition.hpp", line 96: Error: No direct declarator preceding ""this function is slated for removal"".
    "./boost/system/detail/error_condition.hpp", line 96: Error: No direct declarator preceding "(".
2020-12-23 23:57:18 +00:00
39bd8ba98f Use address-model=32 for msvc-9.0, 10.0, 11.0 2020-10-06 13:29:14 +03:00
f1c0a52426 Fix typo 2020-10-06 04:44:07 +03:00
8962c9101a Update documentation 2020-10-06 04:26:02 +03:00
329e72fb92 Mark error_condition::failed, error_condition::message as deprecated; revert op bool 2020-10-06 04:03:13 +03:00
6758690d2f Add BOOST_SYSTEM_DEPRECATED; mark deprecated categories 2020-10-06 03:42:00 +03:00
8f32183b63 Mark platform-specific error headers as deprecated; split tests 2020-10-06 03:21:38 +03:00
99db03ee96 Remove tab 2020-09-04 17:02:14 +03:00
2e1ae5bc7a Remove unnecessary includes 2020-08-28 15:20:13 +03:00
7236be0c58 Add errc_test2 2020-08-28 02:00:20 +03:00
776834b723 Rename std_interoperability.hpp to to_std_category.hpp, make it self-contained 2020-08-28 01:03:15 +03:00
7d6da0ad91 Add tests for failed() 2020-08-27 17:49:20 +03:00
999cf08bf5 Add system_category_test3 2020-08-27 17:47:06 +03:00
96418c1531 Add generic_category_test3 2020-08-27 17:41:33 +03:00
717867cf4e Remove unnecessary includes 2020-08-27 17:40:27 +03:00
7e2a02b16d Rename system_category_posix.hpp to is_generic_value.hpp 2020-08-27 17:31:52 +03:00
b7e3be2798 Add system_category.hpp 2020-08-27 17:22:24 +03:00
e919caa2b4 Add generic_category.hpp 2020-08-27 16:35:32 +03:00
b951517625 Move system_category implementation to system_category_impl.hpp 2020-08-27 16:25:34 +03:00
ff18f28684 Move make_ functions for errc to errc.hpp 2020-08-27 16:15:10 +03:00
96321beb88 Add error_condition.hpp 2020-08-27 15:45:07 +03:00
313982fa52 Move interoperability support to error_category_impl.hpp 2020-08-27 15:14:17 +03:00
cc2b081a9e Add boost/system/error_category.hpp 2020-08-27 03:38:30 +03:00
a93572ab16 Extract error_category implementation into its own header 2020-08-27 03:23:00 +03:00
cc49bc4457 Extract throws into its own header 2020-08-27 03:06:14 +03:00
6bc7edbfa8 Rename generic_category_impl.hpp to generic_category_message.hpp 2020-08-27 02:59:30 +03:00
c345b86b0a Restore generic_category_impl.hpp; functions are needed by system_category 2020-08-27 02:56:18 +03:00
13bac420ab Move op!= for error_condition 2020-08-27 02:26:32 +03:00
abc94afdb2 Extract error_code into its own header 2020-08-27 02:23:50 +03:00
867ac5b446 Move generic_category(), system_category() to their respective headers; extract error_condition into its own header 2020-08-27 02:07:22 +03:00
d50db54c44 Move failed_impl into error_category.hpp 2020-08-27 01:36:44 +03:00
72ea1ef846 Extract enable_if into its own header 2020-08-27 01:21:56 +03:00
d581eb203e Extract system_error_category into its own header 2020-08-27 01:15:28 +03:00
3047581c75 Remove generic_category_impl.hpp 2020-08-27 01:06:54 +03:00
ddd679e6d7 Extract generic_error_category into its own header 2020-08-27 01:06:07 +03:00
4ec6c99148 Rename detail/generic_category.hpp 2020-08-27 00:51:03 +03:00
7b56fd9acf Extract error_category into its own header 2020-08-27 00:47:48 +03:00
b6a447cdde Extract errc into its own header 2020-08-27 00:31:45 +03:00
83019b5822 Extract is_error_code_enum, is_error_condition_enum into their own headers 2020-08-26 22:46:27 +03:00
8220aa5700 Include and test system_error.hpp in test/quick.cpp 2020-06-17 01:21:42 +03:00
f00c76a3fc Include and test system_error.hpp in warnings_test 2020-06-17 01:13:16 +03:00
73bf30ae04 Enable -Wsuggest-override in warnings_test; add BOOST_OVERRIDE appropriately 2020-06-17 01:06:40 +03:00
63ac7fb9bc Use <warnings>pedantic for warnings_test 2020-06-17 00:45:29 +03:00
feb545a919 Add gcc 10, clang 10, freebsd to Travis 2020-06-16 21:26:17 +03:00
00b30343b9 Asciidoctor 2 fixes 2020-06-16 21:01:38 +03:00
c91dbc8249 Update footer for Asciidoctor 2 2020-06-16 20:44:31 +03:00
00d85d8d37 Update revision history 2020-06-16 20:44:09 +03:00
5d3365717e Revert "Revert operator bool() to its pre-failed value() != 0 meaning"
This reverts commit 3164b387a5.
2020-06-16 20:24:23 +03:00
6942dc454b Fix unsupported use of BOOST_SYMBOL_VISIBLE on Sun C++ 2020-01-24 20:59:12 +02:00
7ba160e443 Rename id to id_ to avoid ObjC++ parsing issues. Fixes #52. 2020-01-18 22:15:44 +02:00
d9bfbfc4d4 Disable BUILD_TESTING on the install test 2020-01-18 15:26:21 +02:00
90cb8254df Install Core as well; add EXCLUDE_FROM_ALL to test libraries 2020-01-18 07:12:06 +02:00
4d1486dec9 Update CMakeLists.txt 2020-01-18 05:28:55 +02:00
97665bf539 Remove duplicate clang-3.6 2020-01-02 04:17:38 +02:00
6d82346e0b Fix .travis.yml mistakes 2020-01-02 02:57:24 +02:00
673dd13eaa Switch UBSAN from g++-8 to g++-9 2020-01-01 23:47:39 +02:00
ca525cd7b2 Update Travis to Xenial 2020-01-01 23:32:04 +02:00
9fb5bbd448 Remove 32 bit configuration from clang-win on Appveyor to avoid mspdbcore.dll error 2019-12-09 01:47:54 +02:00
31152834ac Add VS2019 to Appveyor; separate clang-win into its own job 2019-11-24 00:04:25 +02:00
455946faac Merge pull request #49 from Thomas-Barbier-1A/cpp7_redundant_redeclar_constexpr
Fix c++17 warning redundant redeclaration of 'constexpr' static data
2019-10-02 02:55:45 -07:00
08370c9158 Fix c++17 warning redundant redeclaration of 'constexpr' static data
member [-Werror=deprecated]
2019-10-01 18:49:31 +02:00
c556aba559 Remove redundant Travis job 2019-06-18 12:50:59 +03:00
ecc4ddd87c Add gcc9, clang8 to Travis 2019-06-18 12:46:04 +03:00
f67827eee3 Add dist: trusty to .travis.yml 2019-06-18 01:08:17 +03:00
c08b8a94ea Fix sign extension (warning 4826.) Closes #48. 2019-05-24 18:55:27 +03:00
835e5de228 Add clang-win to Appveyor 2019-05-14 04:16:53 +03:00
dc2ad73e30 Merge pull request #47 from KABoissonneault/feature/issue_46
Added boost::winapi::ERROR_CONNECTION_ABORTED_ to handled error codes…
2019-05-13 18:14:54 -07:00
32a6c13533 Added boost::winapi::ERROR_CONNECTION_ABORTED_ to handled error codes in Win32's system_category, making it equivalent to errc::connection_aborted 2019-05-13 18:08:24 -04:00
bfbc5ec42f Remove BOOST_SYSTEM_REQUIRE_CONST_INIT; variables are constexpr, so no longer needed. Closes #45. 2019-05-12 04:15:35 +03:00
9deadda4b4 Merge branch 'feature/system-generic-visible' into feature/std-ec-mismatch 2019-04-25 20:54:01 +03:00
3b6315e4a1 Add BOOST_SYMBOL_VISIBLE to system_category(), generic_category() 2019-04-25 16:55:13 +03:00
1d845408dd Fix thread safety issue in std interop 2019-04-25 01:01:48 +03:00
e08e4253d0 Avoid allocation on interop for system/generic categories; fix DLL interoperability on msvc-14.x by poking into std::system_category::_Addr 2019-04-25 00:31:25 +03:00
afc51937be Mark to_std_category as BOOST_SYMBOL_VISIBLE 2019-04-24 23:18:19 +03:00
907c867cd1 Rename test/std_ec_mismatch to std_single_instance; test also static and shared libraries 2019-04-24 21:15:39 +03:00
9f225112f1 Add std_ec_mismatch_test 2019-04-24 18:19:21 +03:00
48b8a6c41c Switch Appveyor to 2015 image 2019-04-14 18:06:05 +03:00
9b8cb7f1f6 Fix wrong null character stripping for FormatMessage (Nikita Kniazev) 2019-03-24 01:59:23 +02:00
90b2356015 system_error_test: Increase tested messages range (Nikita Kniazev) 2019-03-24 00:24:05 +02:00
1c36a72b79 Merge pull request #40 from Kojoley/system_error_test-mingw-non-en
system_error_test: Enable locale query on MinGW-w64
2019-03-17 11:28:45 +02:00
7947d0ed0d system_error_test: Reenable locale query on MinGW and Cygwin 2019-03-17 01:53:37 +03:00
72d3e96c73 Disable English-dependent test; fixes #39. 2019-03-16 19:51:21 +02:00
ca882f286c Skip system_category_test_utf8; comparing against FormatMessageA isn't going to work. Fixes #38. 2019-03-16 19:44:43 +02:00
df78f08bd2 Merge pull request #37 from Kojoley/patch-1
system_category_test: Increase buffer size
2019-03-16 19:02:47 +02:00
f878f41fe7 system_category_test: Increase buffer size
The message for 5810 error does not fit into buffer on non-English locales.
2019-03-16 01:55:18 +03:00
0134441a6e Add warnings_test.cpp; disable -Wnon-virtual-dtor on g++ < 4.6 2019-03-04 19:23:32 +02:00
c705bab504 #pragma GCC diagnostic push/pop requires gcc 4.6 2019-03-04 17:38:52 +02:00
af1dc84160 Disable -Wnon-virtual-dtor 2019-03-04 16:35:35 +02:00
2d37749d00 Enable -Wnon-virtual-dtor in warnings_test 2019-03-04 15:40:03 +02:00
3164b387a5 Revert operator bool() to its pre-failed value() != 0 meaning 2019-02-27 21:10:57 +02:00
9753cf7668 Update test/Jamfile 2019-02-27 06:23:16 +02:00
ef7c34fc30 Remove use of _alloca 2019-02-26 17:22:58 +02:00
f726c068c3 Add UTF-8 tests 2019-02-26 16:42:47 +02:00
2929d2dea2 Fix .travis.yml 2019-01-06 04:38:22 +02:00
2c01c5d5c8 Add test/cmake_subdir_test 2019-01-05 19:55:38 +02:00
5ab9a5117d Update CMakeLists.txt 2019-01-04 19:38:01 +02:00
ee916382df [CMake] Generate cmake target that other libraries can use
... to express their dependency on this library and retrieve any
configuration information such as the include directory, binary
to link to (if any), transitive dependencies, necessary compiler
options or the required c++ standards level.
2018-12-23 22:47:51 +01:00
fc1f2f4845 Remove essentials from yml files 2018-12-22 05:14:53 +02:00
65daf972d3 Update .yml files 2018-12-18 21:56:44 +02:00
3a4fff686e Fix warnings on clang-win 2018-10-27 05:30:27 +03:00
054c0caf60 Add newline at end 2018-10-04 21:13:56 +03:00
b31fb4804d Document system_error changes; add example for message(ev, buffer, len) 2018-10-03 03:40:10 +03:00
7f303cc4b6 Remove old .html files; update redirect 2018-10-03 01:19:28 +03:00
504fb05c2f Make system_error(ec) explicit, return by value from system_error::code() 2018-10-03 01:15:43 +03:00
d13fa54450 Remove throws() from synopsis; document system_error 2018-10-03 00:24:10 +03:00
fb44b43f0a Merge branch 'develop' into feature/asciidoc 2018-10-02 23:02:24 +03:00
e87cd333a8 Work around 'unused variable' MSVC warning 2018-10-02 18:39:41 +03:00
3d01409fe6 Avoid long long warnings 2018-10-02 17:51:09 +03:00
25a34e1647 Merge branch 'develop' into feature/warnings-all 2018-10-02 17:15:40 +03:00
78a1813c13 Merge branch 'develop' into feature/use-utf8 2018-10-02 04:36:25 +03:00
342400c7ec Add a quick test with -Wall -Werror 2018-10-02 04:34:33 +03:00
1b4c7f366d Minor grammar fixes 2018-10-02 04:03:39 +03:00
af2edc5bea Add .gitignore 2018-10-02 02:59:42 +03:00
1e6dc86a68 Change code to match documentation 2018-10-02 02:59:03 +03:00
efff0260f7 Add changes, reference; fix trailing whitespace 2018-10-02 02:58:21 +03:00
62ca8e6d8c Add asciidoc documentation 2018-10-01 19:20:52 +03:00
584f9731ad Refactor BOOST_SYSTEM_USE_UTF8 code 2018-10-01 17:40:16 +03:00
f821d5e74a Add failed_constexpr_test.cpp 2018-09-22 21:06:31 +03:00
91aeb86f57 Disable constexpr on g++ 5 2018-09-22 21:00:06 +03:00
e7c1079c4f Try to work around g++-5 constexpr issue in failed_impl 2018-09-22 20:05:31 +03:00
be972baaa3 Add a constructor to http_category_impl to placate clang++-3.8 and below 2018-09-22 19:33:04 +03:00
f48cc5aec6 Add failed() 2018-09-22 17:34:40 +03:00
349fb30e8e Remove the user-provided ~error_category in C++03 mode, to fix use after main 2018-09-22 16:15:49 +03:00
08dc402e77 Simplify after_main_test 2018-09-22 15:40:19 +03:00
a627662e63 Add after_main_test 2018-09-22 15:17:47 +03:00
1d4de72899 Merge branch 'feature/message_r' into develop 2018-09-22 00:04:48 +03:00
d966de437e Update and collapse Appveyor configurations 2018-09-21 20:51:24 +03:00
b300fdeef4 Use CP_UTF8 when BOOST_SYSTEM_USE_UTF8 is defined 2018-09-21 20:45:44 +03:00
24179e73c9 Move message() at its standard place, next to its other overload 2018-09-21 17:19:50 +03:00
c182707dfe Merge branch 'develop' into feature/message_r 2018-09-21 17:08:31 +03:00
d79e38e5d5 Remove noexcept from conversions to std::error_code/condition; they allocate and can throw 2018-09-21 17:07:51 +03:00
73de31c541 MinGW32 doesn't have std::snprintf 2018-09-21 16:01:29 +03:00
7b401cef93 Improve Windows implementation of message() 2018-09-21 06:45:56 +03:00
e180bfe37e Add system_category_test; fix Windows implementation 2018-09-21 04:51:50 +03:00
ec93d058fe Add a noexcept overload of message() taking a buffer 2018-09-21 03:16:55 +03:00
a4e700ecf4 Merge branch 'feature/header-only' into feature/merge-header-only 2018-09-19 14:05:33 +03:00
af9646c582 Fix #endif placement 2018-09-19 01:10:12 +03:00
70d16a61e6 Merge branch 'feature/header-only' into feature/merge-header-only 2018-09-18 22:32:42 +03:00
3a41aaabad Revert "MSVC requires __declspec(dllimport) for variables"
This reverts commit 4b7018de85.
2018-09-18 22:32:26 +03:00
46d383b3bd Revert "Disable constexpr on msvc-14.1"
This reverts commit 3bdea5dfa3.
2018-09-18 22:30:56 +03:00
9afd678532 Revert "Add BOOST_SYMBOL_VISIBLE to generic_error_category and system_error_category, to placate ubsan"
This reverts commit a9909bb82b.
2018-09-18 22:30:54 +03:00
68c89304f2 Revert "Sprinkle more BOOST_SYMBOL_VISIBLE throughout"
This reverts commit bbd0a3766d.
2018-09-18 22:30:52 +03:00
0272ea0ea5 Revert "Revert "Use enable_if from type_traits""
This reverts commit ca68b08511.
2018-09-18 22:30:50 +03:00
c4626e0413 Revert "Normalize Core includes"
This reverts commit ff7116404b.
2018-09-18 22:30:40 +03:00
515fbb21b4 Use strerror_r on glibc 2018-09-18 22:21:13 +03:00
7d38263d71 Add an empty main() in win32_hresult_test when not on Windows 2018-09-17 20:25:13 +03:00
465e9e019e Remove noexcept from operator std::error_category const& (allocates and can throw) 2018-09-17 20:12:10 +03:00
11a908a3fe Fix hash_value 2018-09-17 18:18:37 +03:00
11b07164c1 Add win32_hresult_test 2018-09-17 17:29:50 +03:00
96320384cc Revert unnecessary changes to error_code.cpp 2018-09-17 17:08:25 +03:00
a9e56e1a6a Remove dependency on type_traits 2018-09-17 03:21:42 +03:00
041678752b Revert deletion of BOOST_*_API check 2018-09-17 02:55:40 +03:00
ff7116404b Normalize Core includes 2018-09-17 02:47:34 +03:00
ca68b08511 Revert "Use enable_if from type_traits"
This reverts commit f92c0fc9b7.
2018-09-17 02:39:32 +03:00
56651f6633 Disable <system_error> interoperation on g++ 4.4/4.5 2018-09-16 20:49:33 +03:00
fe1dbd9df9 Use g++-8, clang-6 with libstdc++-5 for UBSan (libstdc++-4.9's map triggers errors in end()) 2018-09-16 20:36:02 +03:00
6bd05dc92d Add BOOST_SYMBOL_VISIBLE to category classes to placate UBSan 2018-09-16 19:32:38 +03:00
bbd0a3766d Sprinkle more BOOST_SYMBOL_VISIBLE throughout 2018-09-16 13:53:11 +03:00
a9909bb82b Add BOOST_SYMBOL_VISIBLE to generic_error_category and system_error_category, to placate ubsan 2018-09-16 08:00:24 +03:00
81c34ab7a4 Remove autolink 2018-09-16 07:06:04 +03:00
9d86d0296e Revert boost/system/config.hpp 2018-09-16 07:04:27 +03:00
41de9d916a Fix throw_test.cpp to not meddle with BOOST_SYSTEM_SOURCE as it needs to import from Boost.System while exporting throw_test() 2018-09-16 06:27:52 +03:00
7a06df877d Revert changes to throw_test.cpp and dynamic_link_test.cpp 2018-09-16 06:27:30 +03:00
34600a62df The constexpr workarounds are no longer needed 2018-09-16 06:15:22 +03:00
57ecfeb2c2 Use map::insert instead of map::emplace, which doesn't work on g++ pre-6 (and msvc-10.0) 2018-09-16 05:58:29 +03:00
731df11ffd Add system_category_posix.hpp; remove BOOST_SYSTEM_WIN32 2018-09-16 05:44:58 +03:00
f14e9e7d5c Revert changes to api_config.hpp 2018-09-16 05:23:35 +03:00
3bdea5dfa3 Disable constexpr on msvc-14.1 2018-09-16 04:49:59 +03:00
02ea086173 Fix throw_test.cpp to not meddle with BOOST_SYSTEM_SOURCE as it needs to import from Boost.System while exporting throw_test() 2018-09-16 04:32:33 +03:00
4b7018de85 MSVC requires __declspec(dllimport) for variables 2018-09-16 04:23:37 +03:00
038786179a Remove unnecessary files 2018-09-16 03:05:17 +03:00
2fa0a00583 Make Boost.System header-only 2018-09-16 03:04:19 +03:00
053972643d Replace BOOST_SYSTEM_NOEXCEPT with BOOST_NOEXCEPT 2018-09-15 20:06:14 +03:00
736d618120 Reformat error_code.hpp 2018-09-15 20:05:10 +03:00
f92c0fc9b7 Use enable_if from type_traits 2018-09-15 01:50:41 +03:00
dc5a054d9e Remove unnecessary #include 2018-09-15 01:00:39 +03:00
13199e504c Reorder includes to avoid ::gets error under Clang 3.8, 3.9 2018-07-19 19:48:20 +03:00
3c59cea7ef Disable constexpr on Clang/libstdc++4.8 2018-07-19 19:04:53 +03:00
697c73ac57 Reorder Travis configurations 2018-07-19 19:00:14 +03:00
3afc9db9e6 Add Clang configurations using the default libstdc++ to Travis 2018-07-19 18:27:57 +03:00
e57cca107d Disable constexpr on Clang/Win 2018-07-09 13:50:27 +03:00
9e039cfaf9 Fix dllexport mismatch errors under clang++ 2018-06-29 05:39:42 +03:00
084d8e119e Update g++ workaround to exclude 7.4/8.1 2018-06-29 03:56:56 +03:00
0d2aeead38 Update workarounds to cover g++ 8.1 2018-06-29 02:29:23 +03:00
73b2805d63 Add g++ 8, clang++ 6 to Travis 2018-06-29 00:42:31 +03:00
6a71483984 Work around ld: unrecognized option '--push-state--no-as-needed' 2018-05-04 15:47:28 +03:00
2b1aa524d9 Merge pull request #23 from boostorg/feature/constexpr
Make error_code and error_condition constexpr, as proposed in https://cplusplus.github.io/LWG/issue2992
2018-05-04 15:06:41 +03:00
a9bb21507a Add Cygwin 64 to Appveyor 2018-03-09 05:12:03 +02:00
d1f3d3b349 Merge branch 'develop' into feature/constexpr 2018-01-29 14:57:30 +02:00
6ea02e2668 Reenable test_throws_usage() under UBSAN 2018-01-29 02:36:50 +02:00
0433e561b5 Change the invalid address of boost::throws() to 8 from 1, so that it's properly aligned 2018-01-29 02:29:14 +02:00
aec8d9056d Test that assigning to boost::throws() crashes 2018-01-28 17:29:13 +02:00
35e3e22c7e Add BOOST_SYSTEM_CONSTEXPR to operator bool 2018-01-22 23:39:59 +02:00
7b94454e7c Merge branch 'develop' into feature/constexpr 2018-01-22 21:13:37 +02:00
0b48bb8166 Use explicit operator bool when available 2018-01-22 21:13:02 +02:00
a413220f8d Add more constexpr tests 2018-01-22 19:43:28 +02:00
9f5272fa61 Install libstdc++-4.9 for clang++ 5.0 ubsan 2018-01-22 18:28:00 +02:00
19d5bf5f04 clang++ 3.8 and below requires a user-provided default constructor 2018-01-22 17:39:29 +02:00
9f5cbe223c Merge branch 'develop' into feature/constexpr 2018-01-22 08:07:54 +02:00
8cc57370ca Revert "Disable std_mismatch_test when UBSAN is defined"
This reverts commit 22189fce95.
2018-01-22 07:54:22 +02:00
42f2dbc32e Disable 03/11 tests when UBSAN is defined 2018-01-22 07:54:00 +02:00
a14074bafc Merge branch 'develop' into feature/constexpr 2018-01-22 07:19:19 +02:00
ca5357699a Enable stack trace on UBSAN Travis configurations 2018-01-22 07:17:56 +02:00
22189fce95 Disable std_mismatch_test when UBSAN is defined 2018-01-22 05:40:41 +02:00
0b18289a85 Avoid unused expression warning by using the expression 2018-01-22 05:21:08 +02:00
587ceaf739 Enable constexpr in header-only mode as well 2018-01-22 04:56:40 +02:00
8416ba067f Merge branch 'develop' into feature/constexpr 2018-01-22 03:20:23 +02:00
3b988e278b Use BOOST_SYMBOL_EXPORT instead of __declspec 2018-01-22 03:19:35 +02:00
6e87e44858 Add variant=debug,release to appveyor.yml 2018-01-22 02:21:53 +02:00
77817d8847 Fix MinGW link errors by properly exporting symbols 2018-01-22 02:20:01 +02:00
fe28fa163c Merge branch 'develop' into feature/constexpr 2018-01-21 22:32:19 +02:00
653f132147 Add -d0 to b2 headers in appveyor.yml 2018-01-21 22:31:37 +02:00
3ee2c53cbf Add equality tests using two libraries returning equivalent error codes, to check that the categories have sigle instances 2018-01-21 22:29:58 +02:00
61b4d8ef24 Fix variant=release link errors 2018-01-21 21:42:22 +02:00
3ba40116fe Merge branch 'develop' into feature/constexpr 2018-01-21 20:44:29 +02:00
ecb77edb81 Fix typo in test/Jamfile 2018-01-21 20:42:08 +02:00
d837670627 Merge branch 'develop' into feature/constexpr 2018-01-21 19:55:18 +02:00
8e631c9afd Add variant=debug,release to Travis 2018-01-21 18:22:49 +02:00
7f98fa58eb Refactor test/Jamfile 2018-01-21 18:21:34 +02:00
5866fbb2b2 Do not test boost::throws() under -fsanitize=undefined 2018-01-21 17:38:01 +02:00
f5f3652f30 Add -fsanitize=undefined to Travis 2018-01-20 18:54:38 +02:00
5f9b5d70d1 Add clang-3.3, 3.4 to Travis 2018-01-19 19:51:03 +02:00
f89fe0ea77 Merge branch 'develop' into feature/constexpr 2018-01-18 15:03:07 +02:00
b494f307b5 Fix g++ 4.4 again 2018-01-18 00:01:17 +02:00
344df6c0a0 Add support for g++ 4.4 to test/Jamfile 2018-01-17 19:06:44 +02:00
d2fdd3637a Add g++ 4.4, 4.6 to Travis 2018-01-16 19:11:33 +02:00
d0b3f59e63 Merge branch 'develop' into feature/constexpr 2018-01-16 16:12:18 +02:00
ef256b927b Add clang++-libc++ to Travis 2018-01-16 16:11:55 +02:00
83ddde6b78 Disable constexpr on g++ 7/8 in C++17 mode due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83835 2018-01-14 15:55:23 +02:00
fe55a4a963 Make error_category::op==, !=, < nonmembers (a non-literal class can't have constexpr members acc. to g++) 2018-01-14 08:49:25 +02:00
de5a0cf3ca Install libstdc++-4.9 for clang 4.0, 5.0 too 2018-01-14 07:56:11 +02:00
7b6dcf6ac6 Make error_code, error_condition literal if C++14 constexpr is available 2018-01-14 07:24:00 +02:00
d28c6ff128 Do not put categories in an unnamed namespace, as this is an ODR violation in header-only mode 2018-01-14 05:56:15 +02:00
f8ef12bcc4 Add before_main_test. 2018-01-14 05:29:02 +02:00
c3da8661dc Add test that checks for duplicate category instances 2018-01-14 05:10:44 +02:00
f69e195aaf Do not link to the library for the header-only tests 2018-01-14 04:56:58 +02:00
d0c6aae2b9 Merge pull request #22 from DanielaE/fix/narrowing
std::basic_string::size() may return a size_type which is wider than …
2017-12-16 18:58:38 +02:00
706659a97f std::basic_string::size() may return a size_type which is wider than an int.
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-12-16 10:40:49 +01:00
120860c397 Update Travis, Appveyor 2017-11-22 02:45:49 +02:00
e367d65b6e Fix use of _alloca under g++/clang (mingw/cygwin) 2017-11-01 20:59:34 +02:00
5e5cd0fda5 Merge branch 'bugfix' of https://github.com/kghost/boost-system into develop 2017-11-01 20:41:01 +02:00
a4955ec9c1 Test header-only w/ BOOST_NO_ANSI_APIS 2017-11-01 20:34:53 +02:00
0daba59730 Fix MSVC compile error 2017-11-02 01:32:18 +08:00
9cc189382d Fix .travis.yml to support branches 2017-10-27 15:33:49 +03:00
41c43b6129 Use <cxxstd> in .travis.yml 2017-10-25 17:20:32 +03:00
16fc70c76f Merge branch 'update_winapi' of https://github.com/Lastique/system into develop 2017-10-25 00:54:02 +03:00
a4b67129ff Updated Boost.WinAPI usage to the new location and namespace. 2017-10-25 00:44:18 +03:00
81619e13c3 Merge branch 'master' into develop 2017-10-24 23:39:47 +03:00
41e0404847 Merge pull request #18 from boostorg/pr/remove-no-deprecated
Replace BOOST_SYSTEM_NO_DEPRECATED with BOOST_SYSTEM_ENABLE_DEPRECATED
2017-10-23 00:12:19 +03:00
829a1320a7 Replace BOOST_SYSTEM_NO_DEPRECATED with BOOST_SYSTEM_ENABLE_DEPRECATED 2017-10-21 19:19:57 +03:00
1fab2e71cc Merge branch 'develop' 2017-09-14 08:06:21 -04:00
54de17d886 Merge commit 'c493242855219beb6476f3bb70e6b2df670852e7' 2017-09-13 15:27:26 +03:00
855fc96010 Merge branch 'master' into develop 2017-09-13 15:25:52 +03:00
fe1991c624 travis: install libstdc++ 4.9 for clang 14/1z 2017-09-11 01:31:51 +03:00
cd38d2f778 Remove unused assignment. This was pull request 15, which was made against master instead of develop. 2017-09-08 15:44:52 -04:00
49e2267c3e Merge pull request #15 from 8W9aG/fix-unread-assignment
Remove unread assignment
2017-09-08 15:36:56 -04:00
e039a454cf Hand add the fix from github.com/boostorg/system/pull/12. Note: This fix was verified by testing in release mode with clang 4.0 on Linux. It crashed before applying the P/R and passed afterwards. The pull request was applied by hand to add some new comments and do some other minor code rearrangements. Thanks to Visigoth for the P/R. 2017-09-07 16:36:48 -04:00
1bb5b95ebd Rewrite the boost::throws() reference documentation. Add tests of boost::throws() using the divide() function from the reference documentation. Having tests will allow us to change the implementation of throws() without fear of silently breaking it. 2017-09-07 15:00:26 -04:00
c493242855 Merge pull request #17 from Lastique/silence_msvc_warnings
Silence MSVC warnings about 'this' in base class initializer list.
2017-09-06 15:55:23 +03:00
b6ef4ad220 Silence MSVC warnings about 'this' in base class initializer list. 2017-09-05 21:32:25 +03:00
efe849862f travis: install libstdc++ 4.9 for clang 14/1z 2017-09-05 05:26:24 +03:00
d0fe891bb3 Add 'quick' test target 2017-09-05 04:52:08 +03:00
6087f1c529 Merge pull request #14 from DanielaE/feature/qoi-warning
fix narrowing conversion
2017-08-27 20:10:51 +03:00
d8d71216e9 fix narrowing conversion
Signed-off-by: Daniela Engert <dani@ngrt.de>
2017-08-27 07:11:04 +02:00
b97772973b Merge branch 'develop' 2017-07-24 13:15:37 +03:00
a0fb1f2d41 Simplify 03/11 mismatch test because of MinGW; message() doesn't work 2017-07-24 12:29:32 +03:00
c639237adf Maintain the same error_category class layout in 03/11 mode 2017-07-24 05:32:44 +03:00
d7ef760af7 Add g++-7, clang-4 to Travis 2017-07-24 05:31:23 +03:00
2f413abd8d Add more 03/11 mismatch tests 2017-07-24 05:15:49 +03:00
fe59bbdb3d Add 03/11 mismatch tests 2017-07-24 04:52:55 +03:00
2649b7e4a6 Merge branch 'develop' 2017-06-22 21:56:51 +03:00
29fda3272c Remove diagnostic options from appveyor.yml 2017-06-22 20:01:32 +03:00
87c427b5df Rework the equivalence logic in terms of the corresponding downstream equivalent 2017-06-22 19:27:55 +03:00
5eda96dcbc Fix Cygwin path 2017-06-22 18:10:55 +03:00
d6c950f534 Add missing #include 2017-06-22 18:09:33 +03:00
81880ba5ff Execute bootstrap in a subshell in Appveyor 2017-06-22 17:28:25 +03:00
483f3769e6 Add --debug-configuration to appveyor.yml 2017-06-22 16:21:08 +03:00
23e7c5d133 Add MinGW to Appveyor 2017-06-22 15:23:48 +03:00
138a7c0d27 Fix CXXFLAGS in appveyor.yml 2017-06-13 20:17:40 +03:00
473cf5ef91 Add import testing to test/Jamfile 2017-06-13 20:12:21 +03:00
62ecf74717 Add appveyor.yml 2017-06-13 19:58:16 +03:00
cc26feabef Fix error_code.ipp on Cygwin 2017-06-13 19:50:36 +03:00
ef2b755d77 Fix <winerror.h> include in error_code_test on cygwin/mingw 2017-06-13 19:34:28 +03:00
1ad099291d Add required #include 2017-06-13 19:22:48 +03:00
f26bfc87aa Fix typo 2017-06-04 11:28:14 -04:00
bd37d3b619 Reformat overly long lines of code. 2017-06-04 11:17:39 -04:00
4736079b2e Fix boost::detail::winapi::ERROR_INSUFFICIENT_BUFFER_ in error_code.ipp (Thanks to Lastique). Use <boost/detail/winapi/error_codes.hpp> in windows_error.hpp. Add msvc project to build header-only version of error_code_test. 2017-06-04 11:01:08 -04:00
9087c92cc7 Add std_interop_test to msvc solution. Add cout message indicating whether or not inter-operation will be tested. 2017-06-03 08:22:04 -04:00
47b4e4e7c2 Merge branch 'jlodos-feature/do_not_include_windows.h' into develop 2017-05-28 16:46:12 -04:00
67ae4c2aa7 Do not include windows.h in header only mode 2017-05-28 16:37:27 -04:00
4626b887be #define _CRT_SECURE_NO_WARNINGS to avoid spurious VC++ warning 2017-05-28 16:34:24 -04:00
c1d722543a Merge branch 'mkurdej-hotfix/deprecated-throw' into develop 2017-05-28 09:27:11 -04:00
b9eb153bac Merge branch 'hotfix/deprecated-throw' of git://github.com/mkurdej/system into mkurdej-hotfix/deprecated-throw 2017-05-28 09:15:27 -04:00
e84af437d8 Merge pull request #16 from boostorg/feature/std-interop
Add conversions to std:: counterparts when <system_error> is available
2017-05-21 11:26:49 -04:00
02262a4048 Test a user-defined error condition category; improve equivalent 2017-05-21 01:25:09 +03:00
bdd1613898 Do not map system::generic to std::generic directly 2017-05-20 19:33:03 +03:00
c4238c745c Add second overload of equivalent, improve first 2017-05-20 18:59:15 +03:00
2d18f66800 Try to fix g++ 4.x issue with generic_category 2017-05-20 18:43:31 +03:00
b722a1ebda Add a few more std interop tests 2017-05-20 15:53:02 +03:00
96db439aef Test exact generic condition values 2017-05-20 15:07:48 +03:00
044c0565b9 Add test for std interop; implement equivalent 2017-05-20 14:33:54 +03:00
6010be4144 Add conversions to std:: counterparts when <system_error> is available 2017-05-20 06:05:39 +03:00
ebda81008e Add .travis.yml 2017-05-20 05:45:24 +03:00
c62bbe9205 Remove unread assignment 2017-05-09 14:37:45 +02:00
a4120cdf1d Upgrade to Visual Studio 2017 2017-04-02 08:01:19 -04:00
504c5e95ee Merge branch 'develop' 2017-02-17 06:49:49 -05:00
dc985cb3bc Clean up some sloppy include guards that were clashing with other Boost projects 2017-01-23 17:08:17 -05:00
af1f767dfe Comment two lines of code to try to prevent user confusion error_codes and error_conditions, such exhibited by ticket #12574. 2016-11-28 08:32:26 -05:00
388b3497af Revert the prior change (do not include windows.h). It worked fine with the msvc toolset, testing with the last four VC++ versions. But it failed with GCC version 4.9.3 cygwin64. 2016-02-23 10:58:27 -05:00
b4aa25dc0e Merge pull request #9 from jlodos/feature/do_not_include_windows.h
Feature/do not include windows.h
2016-02-22 10:36:06 -05:00
4fecb0a505 Merge branch 'feature/do_not_include_windows.h' of github.com:jlodos/system into feature/do_not_include_windows.h
# Conflicts:
#	include/boost/system/detail/error_code.ipp
2016-02-18 22:02:43 -06:00
561ac00345 Do not include windows.h in header only mode 2016-02-18 22:00:34 -06:00
7c0e5f7c0d Do not include windows.h in header only mode 2016-02-18 21:49:53 -06:00
e374f766ea Merge pull request #7 from Lastique/patch-1
Fix gcc warnings about unused variables
2015-11-21 10:24:38 -05:00
241f69c55e Fix gcc warnings about unused variables 2015-11-16 16:42:21 +03:00
1f67456bcf Use BOOST_NOEXCEPT_OR_NOTHROW instead of throw() to avoid -Wdeprecated warning on clang (3.5+). 2015-10-23 11:54:17 +02:00
69252d03b1 Upgrade to VC++ 14.0 2015 2015-01-19 14:11:39 -05:00
db3dd13fb6 Rename test/system directory to test/msvc 2015-01-19 14:09:21 -05:00
e5da5ce2cf Merge remote-tracking branch 'remotes/origin/develop' 2015-01-06 11:08:27 -05:00
cd8828db96 Merge pull request #5 from danieljames/metadata
Create metadata file.
2015-01-06 10:58:04 -05:00
43b08da03a Add metadata file. 2014-08-18 15:11:09 +01:00
dcf45d36e5 Neither MinGW or Cygwin versions of winerror.h work if used alone, so on either of these platforms include the full windows.h. Move reporting of configuration to a separate config_test.cpp program, and expand the coverage to report more macros. 2014-08-03 13:44:11 -07:00
614ae2bd7f Merge branch 'MSOpenTech-fixforcygwin' into develop 2014-08-03 13:39:31 -07:00
9379d94b2a Show value of BOOST_PLAT_WINDOWS_DESKTOP 2014-08-02 08:11:13 -04:00
800fce3aaf Neither MinGW or Cygwin versions of winerror.h work if used alone, so on either of these platforms include the full windows.h. Move reporting of configuration to a separate config_test.cpp program, and expand the coverage to report more macros. 2014-08-01 10:49:40 -04:00
0d0e14b3c5 Show more macros as defined or not defined to aid regression test interpretation. 2014-08-01 07:19:58 -04:00
3d081e761d Merge branch 'MSOpenTech-fixforcygwin' into develop 2014-07-30 15:07:01 -04:00
3ec7345ba1 Merge branch 'develop' 2014-07-19 14:14:26 -04:00
2f2c97caa8 Fixing break on cygwin because local_free_on_destruction.hpp is not
included. Ticket #10137.
2014-06-19 20:30:41 -07:00
74601846e6 Add Boost.Predef include so that WindowsRT changes work even if config doesn't supply platform. 2014-06-04 11:41:30 -04:00
25e79b3492 Merge pull request #3 from MSOpenTech/winrt
[winrt support] Changes to make Boost System work on the Windows Runtime.
2014-06-04 11:06:40 -04:00
5a29c4458d Merge branch 'develop'
Conflicts:
	doc/reference.html
	include/boost/system/error_code.hpp
	test/system/error_code_test/error_code_test.vcxproj
	test/system/system-dll/system-dll.vcxproj
	test/system_msvc/system_msvc.sln
2014-06-02 08:14:58 -04:00
4b7573fd43 Fix table of contents 2014-06-02 07:23:08 -04:00
b790db0bb9 Add release history. 2014-06-02 07:07:13 -04:00
8c1549a307 Removed unneeded #include <boost/operators.hpp> 2014-05-31 13:58:40 -04:00
44c3566380 Update to Visual Studio 2013 2014-05-31 13:56:43 -04:00
9c23522b73 Changes to make Boost System work on the Windows Runtime.
Basically just use FormatMessageW without FORMAT_MESSAGE_FROM_SYSTEM.
2014-05-27 12:28:13 -07:00
d77fd95f8a Initial commit VC++ 2012 test solution 2014-01-06 17:41:36 -05:00
986e0f33ac Ensure generic_category() and system_category() linkage is correct on Windows when BOOST_ERROR_CODE_HEADER_ONLY is specified. 2014-01-06 17:38:20 -05:00
1a925ee17b Update docs to reflect library inclusion in C++11 and addition of BOOST_ERROR_CODE_HEADER_ONLY 2014-01-06 16:53:25 -05:00
459160d184 Move BOOST_SYSTEM_SOURCE definition to src/error_code.cpp so that automatic library variant selection is enabled. 2014-01-06 16:52:15 -05:00
42ee65f745 Move src/local_free_on_destruction.hpp to include/boost/detail. Was not being found by some VC++ versions, plus header only builds are supposed to be possible without non-header directories even being present. 2014-01-06 15:37:51 -05:00
199c0cfb0b Remove legacy VC++ solution. Easier to rebuild from scratch. 2014-01-06 15:33:39 -05:00
2c620a4f3a fix header-only use of error codes
BOOST_ERROR_CODE_HEADER_ONLY was not working when the headers are separated
from the sources (e.g. when installing the headers to fhs-style /usr/include
or the like). to avoid this, we move the implementation to an .ipp file

Signed-off-by: Tim Blechmann <tim@klingt.org>
2014-01-04 12:36:44 +01:00
85ba824b37 Create first merge point for Git 2013-12-20 08:04:18 -05:00
21563d532f Meaningless extra line added just to test modular boost. 2013-12-02 13:54:25 -05:00
067ff613b3 Merge from trunk.
------------------------------------------------------------------------
r86152 | chris_kohlhoff | 2013-10-04 09:59:54 +1000 (Fri, 04 Oct 2013) | 1 line

Fix WinRT detection.
------------------------------------------------------------------------
r86153 | chris_kohlhoff | 2013-10-04 10:00:46 +1000 (Fri, 04 Oct 2013) | 1 line

Add WinRT implementation notes.
------------------------------------------------------------------------
r86154 | chris_kohlhoff | 2013-10-04 10:03:36 +1000 (Fri, 04 Oct 2013) | 1 line

Fix dead links in documentation.
------------------------------------------------------------------------
r86462 | chris_kohlhoff | 2013-10-27 09:32:01 +1100 (Sun, 27 Oct 2013) | 1 line

Suppress conversion warnings reported by MSVC.
------------------------------------------------------------------------
r86463 | chris_kohlhoff | 2013-10-27 09:35:32 +1100 (Sun, 27 Oct 2013) | 1 line

Support older versions of OpenSSL that don't supply SSL_CTX_clear_options.
------------------------------------------------------------------------
r86464 | chris_kohlhoff | 2013-10-27 09:39:23 +1100 (Sun, 27 Oct 2013) | 1 line

Add a note to clarify that concurrent invocation is not guaranteed for handlers in different strands.
------------------------------------------------------------------------
r86465 | chris_kohlhoff | 2013-10-27 09:42:53 +1100 (Sun, 27 Oct 2013) | 1 line

Fix typos in spawn() documentation.
------------------------------------------------------------------------
r86468 | chris_kohlhoff | 2013-10-27 09:49:17 +1100 (Sun, 27 Oct 2013) | 1 line

Updated revision history.
------------------------------------------------------------------------


[SVN r86470]
2013-10-26 23:25:53 +00:00
ec47972526 Fix WinRT detection.
[SVN r86152]
2013-10-03 23:59:54 +00:00
94898ff8a6 Merge system from trunk.
------------------------------------------------------------------------
r85699 | chris_kohlhoff | 2013-09-16 23:29:47 +1000 (Mon, 16 Sep 2013) | 2 lines

Add Windows Runtime support to Boost.System.



[SVN r85837]
2013-09-22 21:51:30 +00:00
c64f27c9be Add Windows Runtime support to Boost.System.
[SVN r85699]
2013-09-16 13:29:47 +00:00
ec4d3bc41e System/FileSystem: merge from trunk to fix #7278.
[SVN r83550]
2013-03-24 20:20:29 +00:00
08ea984237 Use C++11 explicit conversion operator if available
[SVN r83210]
2013-02-28 20:55:07 +00:00
87130d1d73 Add BOOST_SYSTEM_NOEXCEPT to several functions previously missed. Update documentation to reflect use of noexcept with fallback to C++03 when C++11 feature not present.
[SVN r83197]
2013-02-28 02:13:56 +00:00
65e14ff167 System/FileSystem/Asio/Thread: ref #7278 Added noexcept to Boost.System to conform with C++11
[SVN r81808]
2012-12-09 14:47:39 +00:00
8fbde538f3 Add some infrastructure
[SVN r80281]
2012-08-28 14:53:18 +00:00
dc61a075b2 Add some infrastructure
[SVN r80280]
2012-08-28 14:51:55 +00:00
5430d82f9f System: merge trunk
[SVN r78528]
2012-05-21 13:39:58 +00:00
bdcfe61429 Revert portion of 68183. This changeset was aimed at other libraries, but inadvertently modified three boost/system headers.
[SVN r78325]
2012-05-04 20:12:58 +00:00
5183a336c2 Revert to BOOST_SYSTEM_STATIC_LINK as the default if no linkage macros supplied. See http://www.boost.org/doc/libs/1_49_0/libs/config/doc/html/boost_config/boost_macro_reference.html#boost_config.boost_macro_reference.macros_for_libraries_with_separate_source_code
[SVN r78267]
2012-04-30 14:01:34 +00:00
af17253f90 Make BOOST_x_DYN_LINK tbe default
[SVN r77999]
2012-04-15 20:16:18 +00:00
7671b1291c Tighten config.hpp and Jamfile logic before attaching static build problems.
[SVN r77997]
2012-04-15 19:16:49 +00:00
46d95f807c Fix comment typo (Rob Stewart)
[SVN r74599]
2011-09-28 15:57:44 +00:00
5c3a2b0481 Fix #5778 for INTEGRITY operating system
[SVN r73775]
2011-08-15 14:34:04 +00:00
322e46fc49 Boost.Ratio/Chrono: Added boost/ratio/include.hpp file and make use of boost/ratio/ratio.hpp when all the files are not needed
[SVN r68183]
2011-01-16 12:07:26 +00:00
d0cd2066d4 Merge from trunk
[SVN r67975]
2011-01-11 20:49:15 +00:00
2e93f04826 Fix PGI non-compliance (portability issue).
Patch supplied by William Bohnhoff at Sandia.



[SVN r66940]
2010-12-01 05:29:24 +00:00
7ffc036bc2 Merge trunk, including changes to come into closer conformance with C++0x FCD
[SVN r63685]
2010-07-06 10:47:30 +00:00
6888c0c7b8 Spirit: merging from trunk upto rev. 61489
[SVN r63640]
2010-07-04 22:38:38 +00:00
9415b8c12e Fix #4254 and other documentation mistakes and bring into closer conformance with the C++ standard library working paper.
[SVN r63426]
2010-06-29 12:33:26 +00:00
f1b9778af4 Fix #3474, memory leak on exception. First reported by Chis Kohlhoff.
[SVN r63184]
2010-06-21 12:25:40 +00:00
5dc1c47d21 Move minimal.css to doc/src.
[SVN r63148]
2010-06-20 18:02:14 +00:00
05a6666107 Fix typo
[SVN r62342]
2010-05-31 11:57:01 +00:00
baae3a392a Upgrade system and filesystem to conform system_category and generic_category interface to N3090, the current C++0x working paper, section 19.5, System error support.
Refactor API macros into a new header, boost/system/api_config.hpp.

Prohibit user definition of API macros. Rationale: ensure all translation units use same definitions, cut number of environments that need to be tested.

[SVN r62313]
2010-05-30 15:38:32 +00:00
2565e5307b Fix #3994, error values on some Broadcom chips
[SVN r62222]
2010-05-26 00:38:07 +00:00
6e8039cb2d fix lightweight test boo boo (Thanks to Peter Dimov)
[SVN r62149]
2010-05-22 16:10:49 +00:00
2bb0075e3f Major upgrade to Boost.Config symbol visibility macros for shared libraries, based on patches from Jürgen Hunold with mods by Beman Dawes. Upgrade Boost.System to use the new visibility macros. Fixes #3697 and provides foundation for fixing 2114, 2309, etc.
[SVN r62140]
2010-05-22 12:12:00 +00:00
eeb5844852 Merge standards-conformance fix for Boost.System
[SVN r61862]
2010-05-09 00:33:44 +00:00
ae67c86d2b Fix a standards-conformance problem where we default-initialize a const object of non-POD class type without a user-declared default constructor
[SVN r61672]
2010-04-29 04:58:39 +00:00
2fe5d75e37 Fixed various issues in docs (mostly duplicate bookmarks and broken links) found by inspect tool
[SVN r61437]
2010-04-20 18:49:18 +00:00
2f6659f39e Fix #3927
[SVN r59673]
2010-02-13 17:08:39 +00:00
f8ddc693ae System: merge trunk
[SVN r57634]
2009-11-13 14:37:32 +00:00
d493021c7d System: fix too_many_symbolic_link_levels typo
[SVN r57615]
2009-11-12 20:42:09 +00:00
6a925690ca System: Correct too_many_symbolic_link_levels misspelling. Fix #3559.
[SVN r57553]
2009-11-10 19:31:24 +00:00
f096d17176 rm cmake from trunk. I'm not entirely sure this is necessary to satisfy the inspect script, but I'm not taking any chances, and it is easy to put back
[SVN r56942]
2009-10-17 02:07:38 +00:00
b9fbd88eb6 System: minor code clean up
[SVN r56631]
2009-10-07 13:27:27 +00:00
165 changed files with 18699 additions and 2937 deletions

253
.drone.jsonnet Normal file
View File

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

23
.drone/drone.bat Normal file
View File

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

24
.drone/drone.sh Executable file
View File

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

372
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,372 @@
name: CI
on:
pull_request:
push:
branches:
- master
- develop
- feature/**
env:
UBSAN_OPTIONS: print_stacktrace=1
jobs:
posix:
strategy:
fail-fast: false
matrix:
include:
- toolset: gcc-4.8
cxxstd: "03,11"
os: ubuntu-18.04
install: g++-4.8
- toolset: gcc-5
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-5
- toolset: gcc-6
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: g++-6
- toolset: gcc-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
- toolset: gcc-8
cxxstd: "03,11,14,17,2a"
os: ubuntu-18.04
install: g++-8
- toolset: gcc-9
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: gcc-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-10
- toolset: gcc-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
install: g++-11
- toolset: gcc-12
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
install: g++-12
- toolset: clang
compiler: clang++-3.9
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-3.9
- toolset: clang
compiler: clang++-4.0
cxxstd: "03,11,14"
os: ubuntu-18.04
install: clang-4.0
- toolset: clang
compiler: clang++-5.0
cxxstd: "03,11,14,1z"
os: ubuntu-18.04
install: clang-5.0
- toolset: clang
compiler: clang++-6.0
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-6.0
- toolset: clang
compiler: clang++-7
cxxstd: "03,11,14,17"
os: ubuntu-18.04
install: clang-7
- toolset: clang
compiler: clang++-8
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-8
- toolset: clang
compiler: clang++-9
cxxstd: "03,11,14,17"
os: ubuntu-20.04
install: clang-9
- toolset: clang
compiler: clang++-10
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-11
cxxstd: "03,11,14,17,2a"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-12
cxxstd: "03,11,14,17,20"
os: ubuntu-20.04
- toolset: clang
compiler: clang++-13
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
install: clang-13
- toolset: clang
compiler: clang++-14
cxxstd: "03,11,14,17,20"
os: ubuntu-22.04
install: clang-14
- toolset: clang
cxxstd: "03,11,14,17,2a"
os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
./bootstrap.sh
./b2 -d0 headers
- name: Create user-config.jam
if: matrix.compiler
run: |
echo "using ${{matrix.toolset}} : : ${{matrix.compiler}} ;" > ~/user-config.jam
- name: Run tests
run: |
cd ../boost-root
./b2 -j3 libs/$LIBRARY/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} variant=debug,release
windows:
strategy:
fail-fast: false
matrix:
include:
- toolset: msvc-14.0
cxxstd: "14"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.2
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2019
- toolset: msvc-14.3
cxxstd: "14,17,20,latest"
addrmd: 32,64
os: windows-2022
- toolset: clang-win
cxxstd: "14,17,latest"
addrmd: 32,64
os: windows-2022
- toolset: gcc
cxxstd: "03,11,14,17,2a"
addrmd: 64
os: windows-2019
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Setup Boost
shell: cmd
run: |
echo GITHUB_REPOSITORY: %GITHUB_REPOSITORY%
for /f %%i in ("%GITHUB_REPOSITORY%") do set LIBRARY=%%~nxi
echo LIBRARY: %LIBRARY%
echo LIBRARY=%LIBRARY%>>%GITHUB_ENV%
echo GITHUB_BASE_REF: %GITHUB_BASE_REF%
echo GITHUB_REF: %GITHUB_REF%
if "%GITHUB_BASE_REF%" == "" set GITHUB_BASE_REF=%GITHUB_REF%
set BOOST_BRANCH=develop
for /f %%i in ("%GITHUB_BASE_REF%") do if "%%~nxi" == "master" set BOOST_BRANCH=master
echo BOOST_BRANCH: %BOOST_BRANCH%
cd ..
git clone -b %BOOST_BRANCH% --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
xcopy /s /e /q %GITHUB_WORKSPACE% libs\%LIBRARY%\
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" %LIBRARY%
cmd /c bootstrap
b2 -d0 headers
- name: Run tests
shell: cmd
run: |
cd ../boost-root
b2 -j3 libs/%LIBRARY%/test toolset=${{matrix.toolset}} cxxstd=${{matrix.cxxstd}} address-model=${{matrix.addrmd}} variant=debug,release embed-manifest-via=linker
posix-cmake-subdir:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Use library with add_subdirectory
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_subdir_test
mkdir __build__ && cd __build__
cmake ..
cmake --build .
ctest --output-on-failure --no-tests=error
posix-cmake-install:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DCMAKE_INSTALL_PREFIX=~/.local ..
- name: Install
run: |
cd ../boost-root/__build__
cmake --build . --target install
- name: Use the installed library
run: |
cd ../boost-root/libs/$LIBRARY/test/cmake_install_test && mkdir __build__ && cd __build__
cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
cmake --build .
ctest --output-on-failure --no-tests=error
posix-cmake-test:
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-18.04
- os: ubuntu-20.04
- os: ubuntu-22.04
- os: macos-10.15
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- name: Install packages
if: matrix.install
run: sudo apt install ${{matrix.install}}
- name: Setup Boost
run: |
echo GITHUB_REPOSITORY: $GITHUB_REPOSITORY
LIBRARY=${GITHUB_REPOSITORY#*/}
echo LIBRARY: $LIBRARY
echo "LIBRARY=$LIBRARY" >> $GITHUB_ENV
echo GITHUB_BASE_REF: $GITHUB_BASE_REF
echo GITHUB_REF: $GITHUB_REF
REF=${GITHUB_BASE_REF:-$GITHUB_REF}
REF=${REF#refs/heads/}
echo REF: $REF
BOOST_BRANCH=develop && [ "$REF" == "master" ] && BOOST_BRANCH=master || true
echo BOOST_BRANCH: $BOOST_BRANCH
cd ..
git clone -b $BOOST_BRANCH --depth 1 https://github.com/boostorg/boost.git boost-root
cd boost-root
cp -r $GITHUB_WORKSPACE/* libs/$LIBRARY
git submodule update --init tools/boostdep
python tools/boostdep/depinst/depinst.py --git_args "--jobs 3" $LIBRARY
- name: Configure
run: |
cd ../boost-root
mkdir __build__ && cd __build__
cmake -DBOOST_INCLUDE_LIBRARIES=$LIBRARY -DBUILD_TESTING=ON ..
- name: Build tests
run: |
cd ../boost-root/__build__
cmake --build . --target tests
- name: Run tests
run: |
cd ../boost-root/__build__
ctest --output-on-failure --no-tests=error

218
.travis.yml Normal file
View File

@ -0,0 +1,218 @@
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
language: cpp
dist: xenial
branches:
only:
- master
- develop
- /feature\/.*/
env:
matrix:
- BOGUS_JOB=true
matrix:
exclude:
- env: BOGUS_JOB=true
include:
- os: linux
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
addons:
apt:
packages:
- g++-multilib
- os: linux
arch: arm64
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
- os: linux
arch: ppc64le
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14
- os: linux
arch: s390x
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11,14 ADDRMD=32,64
- os: linux
compiler: g++-4.4
env: TOOLSET=gcc COMPILER=g++-4.4 CXXSTD=98,0x
addons:
apt:
packages:
- g++-4.4
sources:
- ubuntu-toolchain-r-test
- os: linux
compiler: g++-4.6
env: TOOLSET=gcc COMPILER=g++-4.6 CXXSTD=03,0x
addons:
apt:
packages:
- g++-4.6
sources:
- ubuntu-toolchain-r-test
- os: linux
dist: trusty
compiler: g++
env: TOOLSET=gcc COMPILER=g++ CXXSTD=03,11
- os: linux
dist: bionic
compiler: g++-11
env: UBSAN=1 TOOLSET=gcc COMPILER=g++-11 CXXSTD=03,11,14,17,20 UBSAN_OPTIONS=print_stacktrace=1 LINKFLAGS=-fuse-ld=gold
addons:
apt:
packages:
- g++-11
sources:
- sourceline: "ppa:ubuntu-toolchain-r/test"
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
addons:
apt:
packages:
- clang-3.3
- os: linux
dist: trusty
compiler: /usr/bin/clang++
env: TOOLSET=clang COMPILER=/usr/bin/clang++ CXXSTD=03,11
addons:
apt:
packages:
- clang-3.4
- os: linux
compiler: clang++-12
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-12 CXXSTD=03,11,14,17,20 UBSAN_OPTIONS=print_stacktrace=1
addons:
apt:
packages:
- clang-12
sources:
- ubuntu-toolchain-r-test
- sourceline: 'deb https://apt.llvm.org/xenial/ llvm-toolchain-xenial-12 main'
key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key'
- os: linux
dist: bionic
compiler: clang++-libc++
env: UBSAN=1 TOOLSET=clang COMPILER=clang++-libc++ CXXSTD=03,11,14,17,2a UBSAN_OPTIONS=print_stacktrace=1
addons:
apt:
packages:
- libc++-dev
- os: freebsd
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,17,2a
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
osx_image: xcode7.3
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
osx_image: xcode8.3
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z ADDRMD=32,64
osx_image: xcode9.4
- os: osx
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
osx_image: xcode10.1
- os: osx
osx_image: xcode11.3
compiler: clang++
env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z
- os: osx
osx_image: xcode12.2
compiler: clang++
env: UBSAN=1 TOOLSET=clang COMPILER=clang++ CXXSTD=03,11,14,1z UBSAN_OPTIONS=print_stacktrace=1
- os: linux
env: CMAKE=1
script:
- mkdir __build__ && cd __build__
- cmake -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
- cmake --build . --target tests
- ctest --output-on-failure --no-tests=error
- os: linux
env: CMAKE=1 BUILD_SHARED_LIBS=ON
script:
- mkdir __build__ && cd __build__
- cmake -DBUILD_SHARED_LIBS=ON -DBOOST_INCLUDE_LIBRARIES=system -DBUILD_TESTING=ON ..
- cmake --build . --target tests
- ctest --output-on-failure --no-tests=error
- os: linux
env: CMAKE_SUBDIR_TEST=1
install:
- BOOST_BRANCH=develop && [ "$TRAVIS_BRANCH" == "master" ] && BOOST_BRANCH=master || true
- git clone -b $BOOST_BRANCH https://github.com/boostorg/assert.git ../assert
- git clone -b $BOOST_BRANCH https://github.com/boostorg/config.git ../config
- git clone -b $BOOST_BRANCH https://github.com/boostorg/core.git ../core
- git clone -b $BOOST_BRANCH https://github.com/boostorg/predef.git ../predef
- git clone -b $BOOST_BRANCH https://github.com/boostorg/winapi.git ../winapi
script:
- cd test/cmake_subdir_test && mkdir __build__ && cd __build__
- cmake ..
- cmake --build .
- cmake --build . --target check
- os: linux
env: CMAKE_INSTALL=1
script:
- pip install --user cmake
- mkdir __build__ && cd __build__
- cmake -DBOOST_INCLUDE_LIBRARIES=system -DCMAKE_INSTALL_PREFIX=~/.local ..
- cmake --build . --target install
- cd ../libs/system/test/cmake_install_test && mkdir __build__ && cd __build__
- cmake -DCMAKE_INSTALL_PREFIX=~/.local ..
- cmake --build .
- cmake --build . --target check
install:
- 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
- ./bootstrap.sh
- ./b2 headers
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}
notifications:
email:
on_success: always

49
CMakeLists.txt Normal file
View File

@ -0,0 +1,49 @@
# 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
if(NOT DEFINED IDF_TARGET)
cmake_minimum_required(VERSION 3.5...3.16)
project(boost_system VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
add_library(boost_system INTERFACE)
add_library(Boost::system ALIAS boost_system)
target_include_directories(boost_system INTERFACE include)
target_link_libraries(boost_system
INTERFACE
Boost::assert
Boost::config
Boost::throw_exception
Boost::variant2
Boost::winapi
)
if(BUILD_TESTING)
add_subdirectory(test)
endif()
else()
FILE(GLOB_RECURSE headers include/*.h include/*.hpp)
idf_component_register(
SRCS
${headers}
INCLUDE_DIRS
include
REQUIRES
boost_assert
boost_config
boost_throw_exception
boost_variant2
# boost_winapi
)
endif()

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).

62
appveyor.yml Normal file
View File

@ -0,0 +1,62 @@
# Copyright 2016-2019 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt)
version: 1.0.{build}-{branch}
shallow_clone: true
branches:
only:
- master
- develop
- /feature\/.*/
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-9.0,msvc-10.0,msvc-11.0
ADDRMD: 32
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
TOOLSET: msvc-12.0,msvc-14.0
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
TOOLSET: msvc-14.1
CXXSTD: 14,17,latest
ADDRMD: 32,64
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\cygwin64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
ADDPATH: C:\mingw-w64\x86_64-6.3.0-posix-seh-rt_v5-rev1\mingw64\bin;
TOOLSET: gcc
CXXSTD: 03,11,14,1z
install:
- set BOOST_BRANCH=develop
- if "%APPVEYOR_REPO_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 %APPVEYOR_BUILD_FOLDER% libs\system\
- python tools/boostdep/depinst/depinst.py system
- cmd /c bootstrap
- b2 -d0 headers
build: off
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

View File

@ -5,7 +5,7 @@
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or www.boost.org/LICENSE_1_0.txt)
# See library home page at http://www.boost.org/libs/system
# See library home page at https://www.boost.org/libs/system
project boost/system
: source-location ../src
@ -22,4 +22,4 @@ lib boost_system
<link>static:<define>BOOST_SYSTEM_STATIC_LINK=1
;
boost-install boost_system ;
boost-install boost_system ;

2
doc/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/html/
/pdf/

23
doc/Jamfile Normal file
View File

@ -0,0 +1,23 @@
# Copyright 2017, 2018 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)
import asciidoctor ;
html system.html : system.adoc ;
install html_ : system.html : <location>html ;
pdf system.pdf : system.adoc ;
explicit system.pdf ;
install pdf_ : system.pdf : <location>pdf ;
explicit pdf_ ;
###############################################################################
alias boostdoc ;
explicit boostdoc ;
alias boostrelease : html_ ;
explicit boostrelease ;

View File

@ -1,147 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Boost System Library</title>
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css">
</head>
<body>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td width="277">
<a href="../../../index.html">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86" border="0"></a></td>
<td width="337" align="middle">
<font size="7">System Library</font>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
<tr>
<td><a href="../../../index.htm">Boost Home</a>&nbsp;&nbsp;&nbsp; <a href="index.html">
Library Home</a>&nbsp;&nbsp; Tutorial&nbsp;&nbsp; <a href="reference.html">
Reference</a></td>
</tr>
</table>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="right">
<tr>
<td width="100%" bgcolor="#D7EEFF" align="center">
<i><b>Contents</b></i></td>
</tr>
<tr>
<td width="100%" bgcolor="#E8F5FF">
<a href="#Introduction">Introduction</a><br>
<a href="#Design_Rationale">Design Rationale</a><br>
<a href="#History">History</a><br>
<a href="#Acknowledgements">Acknowledgements</a>
</td>
</tr>
<tr>
<td width="100%" bgcolor="#D7EEFF" align="center">
<b><i>Headers</i></b></td>
</tr>
<tr>
<td width="100%" bgcolor="#E8F5FF">
<a href="reference.html#Header-error_code">&lt;boost/system/error_code.hpp&gt;</a><br>
<a href="reference.html#Header-system_error">
&lt;boost/system/system_error.hpp&gt;</a><br>
<a href="../../../boost/system/cygwin_error.hpp">
&lt;boost/system/cygwin_error.hpp&gt;</a><br>
<a href="../../../boost/system/linux_error.hpp">
&lt;boost/system/linux_error.hpp&gt;</a><br>
<a href="../../../boost/system/windows_error.hpp">
&lt;boost/system/windows_error.hpp&gt;</a></td>
</tr>
</table>
<h2><a name="Introduction">Introduction</a></h2>
<p>Error conditions originating from the operating system or other low-level
application program interfaces (API's) are typically reported via an integer
representing an error code. When these low-level API calls are wrapped in
portable code, such as in a portable library, some users want to deal with the
error codes in portable ways. Other users need to get at the system specific
error codes, so they can deal with system specific needs. The Boost System
library provides simple, light-weight <a href="reference.html#Class-error_code">
error_code</a> objects that encapsulate system-specific error code values, yet
also provide access to more abstract and portable error conditions via
<a href="reference.html#Class-error_condition">error_condition</a> objects.
Because error_code objects can represent errors from sources other than the
operating system, including user-defined sources, each error_code and
error_condition has an associated <a href="reference.html#Class-error_category">
error_category</a>.</p>
<p>An exception class,&nbsp; <a href="reference.html#Class-system_error">
system_error</a>, is provided. Derived from std::runtime_error, it captures the
underlying error_code for the problem causing the exception so that this
important information is not lost.</p>
<p>While exceptions are the preferred C++ default error code reporting
mechanism, users of libraries dependent on low-level API's&nbsp;often need overloads
reporting error conditions via error code arguments and/or return values rather
than via throwing exceptions. Otherwise, when errors are not exceptional
occurrences and must be dealt with as they arise, programs become littered with
try/catch blocks, unreadable, and very inefficient. The Boost System library
supports both error reporting by exception and by error code.</p>
<p>In addition to portable errors codes and conditions supported by the <code>
error_code.hpp</code> header, system-specific headers support the Cygwin, Linux,
and Windows platforms. These headers are effectively no-ops if included for
platforms other than their intended target.</p>
<h2><a name="Design_Rationale">Design Rationale</a></h2>
<p>Class <code>error_code</code>&nbsp; and <code>error_condition</code> are designed as a value types so
they can be copied
without slicing and do not requiring heap allocation, but still have polymorphic
behavior based on the error category. This is achieved by abstract base class
<code>error_category</code> supplying the polymorphic behavior, and <code>
error_code</code> and <code>error_condition</code> containing a pointer to an object of a type derived from <code>
error_category</code>.</p>
<p>Many of the detailed design decisions were driven by the requirements that
users to be able to add additional error categories, and that it be no more
difficult to write portable code than system-specific code.</p>
<p>The <code>operator&lt;&lt;</code> overload for <code>error_code</code> eliminates a
misleading conversion to bool in code like <code>cout &lt;&lt; ec</code>, where <code>
ec</code> is of type <code>error_code</code>. It is also useful in its own
right.</p>
<h2><a name="History">History</a></h2>
<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html">
N1975</a>, Filesystem Library Proposal for TR2, accepted for Library Technical
Report 2 (TR2) at the Berlin meeting, included additional components to
supplement the Standard Library's Diagnostics clause. Since then, these error
reporting components have received wider public scrutiny and enhancements have
been made to the design. The enhanced version has been used by N2054, Networking
Library Proposal for TR2, demonstrating that these error reporting components
are useful beyond the original Filesystem Library.</p>
<p>The original proposal viewed error categories as a binary choice between
<code>errno</code> (i.e. POSIX-style) and the native operating system's error
codes. The proposed components now allow as many additional error categories as
are needed by either implementations or by users. The need to support additional
error categories, for example, occurs in some networking library implementations
because they are built on top of the POSIX <code>getaddrinfo</code> API that
uses error codes not based on <code>errno</code>.</p>
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
<p>Christopher Kohlhoff and Peter Dimov made important contributions to the
design. Comments and suggestions were also received from Pavel Vozenilek,
Gennaro Prota, Dave Abrahams, Jeff Garland, Iain Hanson, Oliver Kowalke, and
Oleg Abrosimov. Christopher Kohlhoff suggested several improvements to the N2066
paper. Johan Nilsson's comments led to several of the refinements in N2066 .</p>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->February 23, 2008<!--webbot bot="Timestamp" endspan i-checksum="41408" --> </font>
</p>
<p><EFBFBD> Copyright Beman Dawes, 1999</p>
<p>Distributed under the Boost Software License, Version 1.0.
(See file <a href="../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a>
or&nbsp; <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>) </p>
</body>
</html>

View File

@ -1,844 +0,0 @@
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>System Library Reference</title>
<link rel="stylesheet" type="text/css" href="../../../doc/html/minimal.css">
</head>
<body>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="637">
<tr>
<td width="277">
<a href="../../../index.htm">
<img src="../../../boost.png" alt="boost.png (6897 bytes)" align="middle" width="277" height="86" border="0"></a></td>
<td width="337" align="middle">
<font size="7">System Library</font>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#D7EEFF" width="100%">
<tr>
<td><a href="../../../index.htm">Boost Home</a>&nbsp;&nbsp;&nbsp; <a href="index.html">
Library Home</a>&nbsp;&nbsp; Tutorial&nbsp;&nbsp; <a href="reference.html">
Reference</a></td>
</tr>
</table>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" align="right">
<tr>
<td width="100%" bgcolor="#D7EEFF" align="center">
<i><b>Contents</b></i></td>
</tr>
<tr>
<td width="100%" bgcolor="#E8F5FF">
<a href="#Introduction">Introduction</a><br>
<a href="#Macros">Macros</a><br>
<a href="#Deprecated-names">Deprecated names</a><br>
<a href="#Header-error_code">Header &lt;boost/system/error_code.hpp&gt;</a><br>
<a href="#Class-error_category">Class <code>error_category</code></a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_category-synopsis">Class <code>error_category</code> synopsis</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_category-virtual-members">Class <code>error_category</code> virtual members</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_category-non-virtual-members">Class <code>error_category</code> non-virtual members</a><br>
&nbsp;&nbsp; <a href="#Class-error_category-non-member-functions">Class <code>error_category</code>
non-member functions</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_category-predefined-objects">Class <code>error_category</code> predefined objects</a><br>
<a href="#Class-error_code">Class <code>error_code</code></a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-synopsis">Class <code>error_code</code> synopsis</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-constructors">Class <code>error_code</code> constructors</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-modifiers">Class <code>error_code</code> modifiers</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_code-observers">Class <code>error_code</code> observers</a><br>
<a href="#Class-error_condition</code>">Class <code>error_condition</code></a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-synopsis">Class <code>error_condition</code> synopsis</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-constructors">Class <code>error_condition</code> constructors</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-modifiers">Class <code>error_condition</code> modifiers</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-error_condition-observers">Class <code>error_condition</code> observers</a><br>
<a href="#throws-object"><code>throws</code> object</a><br>
<a href="#Semantics-of-throws">Semantics of <code>throws</code> object</a><br>
<a href="#Non-member-functions">Non-member functions</a><br>
<a href="#Header-system_error">Header &lt;boost/system/system_error.hpp&gt;</a><br>
&nbsp;&nbsp;&nbsp;<a href="#Class-system_error">Class <code>system_error</code></a><br>
</td>
</tr>
</table>
<h2><a name="Introduction">Introduction</a></h2>
<p>This reference documentation describes components that&nbsp;
programs may use to report error conditions originating from the operating
system or other low-level application program interfaces.</p>
<p>Boost.System library components never change the value of <code>
errno</code>.</p>
<h2><a name="Macros">Macros</a></h2>
<p>Users may defined the following macros if desired. Sensible defaults are
provided, so users may ignore these macros if they prefer.</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td><b><i>Macro Name</i></b></td>
<td><b><i>Default</i></b></td>
<td><b><i>Effect if defined</i></b></td>
</tr>
<tr>
<td valign="top"><code>BOOST_WINDOWS_API</code></td>
<td valign="top">Defined if Windows is detected by Boost.System's automatic configuration
code, otherwise not defined.</td>
<td valign="top">Implementation uses the Microsoft Windows native
application program interface (API).</td>
</tr>
<tr>
<td valign="top"><code>BOOST_POSIX_API</code></td>
<td valign="top">Defined if Windows is not detected by Boost.System's automatic configuration
code.</td>
<td valign="top">Implementation uses the POSIX native
application program interface (API).</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_DYN_LINK</code></td>
<td valign="top">Defined if <code>BOOST_ALL_DYN_LINK</code> is defined,
otherwise not defined.</td>
<td valign="top">Boost.System library is dynamically linked. If not defined,
static linking is assumed.</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_NO_LIB</code></td>
<td valign="top">Defined if <code>BOOST_ALL_NO_LIB</code> is defined,
otherwise not defined.</td>
<td valign="top">Boost.System library does not use the Boost auto-link
facility.</td>
</tr>
<tr>
<td valign="top"><code>BOOST_SYSTEM_NO_DEPRECATED</code></td>
<td valign="top">Not defined.</td>
<td valign="top">Deprecated features are excluded.</td>
</tr>
</table>
<h2><a name="Deprecated-names">Deprecated names</a></h2>
<p>In the process of adding Boost.System to C++0x standard library, some of the
names are being changed. To ease transition, Boost.System deprecates the old
names, but continues to provide them unless macro <code>BOOST_SYSTEM_NO_DEPRECATED</code>
is defined.</p>
<table border="1" cellpadding="5" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td><b><i>Old name, now deprecated</i></b></td>
<td><b><i>New name</i></b></td>
</tr>
<tr>
<td><code>namespace posix</code></td>
<td><code>namespace errc</code></td>
</tr>
<tr>
<td><code>namespace posix_error</code></td>
<td><code>namespace errc</code></td>
</tr>
<tr>
<td><code>enum posix_errno</code></td>
<td><code>enum errc_t</code></td>
</tr>
<tr>
<td><code>get_posix_category()</code></td>
<td><code>get_generic_category()</code></td>
</tr>
<tr>
<td><code>posix_category</code></td>
<td><code>generic_category</code></td>
</tr>
<tr>
<td><code>errno_ecat</code></td>
<td><code>generic_category</code></td>
</tr>
<tr>
<td><code>native_ecat</code></td>
<td><code>system_category</code></td>
</tr>
</table>
<h2><a name="Header-error_code">Header &lt;boost/system/error_code.hpp&gt;</a></h2>
<h3>&lt;boost/system/error_code.hpp&gt; synopsis</h3>
<blockquote>
<pre>namespace boost
{
namespace system
{
class <a href="#Class-error_category">error_category</a>;
class <a href="#Class-error_code">error_code</a>;
class <a href="#Class-error_condition">error_condition</a>;
// "Concept" helpers
template< class T="" >
struct is_error_code_enum { static const bool value = false; };
template< class T="" >
struct is_error_condition_enum { static const bool value = false; };
// generic error_conditions
namespace errc
{
enum errc_t
{
success = 0,
address_family_not_supported, //EAFNOSUPPORT
address_in_use, //EADDRINUSE
address_not_available, //EADDRNOTAVAIL
already_connected, //EISCONN
argument_list_too_long, //E2BIG
argument_out_of_domain, //EDOM
bad_address, //EFAULT
bad_file_descriptor, //EBADF
bad_message, //EBADMSG
broken_pipe, //EPIPE
connection_aborted, //ECONNABORTED
connection_already_in_progress, //EALREADY
connection_refused, //ECONNREFUSED
connection_reset, //ECONNRESET
cross_device_link, //EXDEV
destination_address_required, //EDESTADDRREQ
device_or_resource_busy, //EBUSY
directory_not_empty, //ENOTEMPTY
executable_format_error, //ENOEXEC
file_exists, //EEXIST
file_too_large, //EFBIG
filename_too_long, //ENAMETOOLONG
function_not_supported, //ENOSYS
host_unreachable, //EHOSTUNREACH
identifier_removed, //EIDRM
illegal_byte_sequence, //EILSEQ
inappropriate_io_control_operation,//ENOTTY
interrupted, //EINTR
invalid_argument, //EINVAL
invalid_seek, //ESPIPE
io_error, //EIO
is_a_directory, //EISDIR
message_size, //EMSGSIZE
network_down, //ENETDOWN
network_reset, //ENETRESET
network_unreachable, //ENETUNREACH
no_buffer_space, //ENOBUFS
no_child_process, //ECHILD
no_link, //ENOLINK
no_lock_available, //ENOLCK
no_message_available, //ENODATA
no_message, //ENOMSG
no_protocol_option, //ENOPROTOOPT
no_space_on_device, //ENOSPC
no_stream_resources, //ENOSR
no_such_device_or_address, //ENXIO
no_such_device, //ENODEV
no_such_file_or_directory, //ENOENT
no_such_process, //ESRCH
not_a_directory, //ENOTDIR
not_a_socket, //ENOTSOCK
not_a_stream, //ENOSTR
not_connected, //ENOTCONN
not_enough_memory, //ENOMEM
not_supported, //ENOTSUP
operation_canceled, //ECANCELED
operation_in_progress, //EINPROGRESS
operation_not_permitted, //EPERM
operation_not_supported, //EOPNOTSUPP
operation_would_block, //EWOULDBLOCK
owner_dead, //EOWNERDEAD
permission_denied, //EACCES
protocol_error, //EPROTO
protocol_not_supported, //EPROTONOSUPPORT
read_only_file_system, //EROFS
resource_deadlock_would_occur, //EDEADLK
resource_unavailable_try_again, //EAGAIN
result_out_of_range, //ERANGE
state_not_recoverable, //ENOTRECOVERABLE
stream_timeout, //ETIME
text_file_busy, //ETXTBSY
timed_out, //ETIMEDOUT
too_many_files_open_in_system, //ENFILE
too_many_files_open, //EMFILE
too_many_links, //EMLINK
too_many_synbolic_link_levels, //ELOOP
value_too_large, //EOVERFLOW
wrong_protocol_type //EPROTOTYPE
};
} // namespace errc
template<> struct is_error_condition_enum<posix::posix_errno>&lt;errc::errc_t&gt;
{ static const bool value = true; };
// predefined error_code object used as &quot;throw on error&quot; tag
extern error_code <a href="#throws-object">throws</a>;
// <a href="#Non-member-functions">non-member functions</a>
bool operator==( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator==( const error_code &amp; code, const error_condition &amp; condition );
bool operator==( const error_condition &amp; condition, const error_code &amp; code );
bool operator==( const error_condition &amp; lhs, const error_condition &amp; rhs );
bool operator!=( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator!=( const error_code &amp; code, const error_condition &amp; condition );
bool operator!=( const error_condition &amp; condition, const error_code &amp; code );
bool operator!=( const error_condition &amp; lhs, const error_condition &amp; rhs );
bool operator&lt;( const error_code &amp; lhs, const error_code &amp; rhs );
bool operator&lt;( const error_condition &amp; lhs, const error_condition &amp; rhs );
error_code make_error_code( errc::errc_t e );
error_condition make_error_condition( errc::errc_t e );
template &lt;class charT, class traits&gt;
std::basic_ostream&lt;charT,traits&gt;&amp;
operator&lt;&lt;( basic_ostream&lt;charT,traits&gt;&amp; os, const error_code &amp; ec );
size_t hash_value( const error_code &amp; ec );
}
}</pre>
</blockquote>
<p>The value of each<code> errc_t</code> constant shall be the same as the
value of the <code>&lt;cerrno&gt;</code> macro shown in the above synopsis.</p>
<p>Users may specialize <code>is_error_code_enum</code> and <code>
is_error_condition_enum</code> templates to indicate that a type is eligible for
class <code>error_code</code> and <code>error_condition</code> automatic
conversions respectively.</p>
<h2><a name="Class-error_category">Class <code>error_category</code></a></h2>
<p>The class <code>error_category</code> defines the base class for types used
to identify the source and encoding of a particular category of error code.</p>
<p><i>[Note:</i> Classes may be derived from <code>error_category</code>
to support additional categories of errors. <i>--end note]</i></p>
<p>The class <code>error_category</code> serves as a base class for types used
to identify the source and encoding of a particular category of error code.
Classes may be derived from <code>error_category</code> to support categories of
errors in addition to those defined in the Boost System library. Such classes
shall behave as specified in this subclause. [<i> Note:</i> <code>error_category</code>
objects are passed by reference, and two such objects are equal if they have the
same address. This means that applications using custom <code>error_category</code>
types should create a single object of each such type. <i><EFBFBD>end note</i> ]</p>
<h3><a name="Class-error_category-synopsis">Class <code>error_category</code> synopsis</a></h3>
<blockquote>
<pre>namespace boost
{
namespace system
{
class error_category : public noncopyable
{
public:
virtual ~error_category();
virtual const char * name() const = 0;
virtual string message( int ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const;
virtual bool equivalent( int code, const error_condition &amp; condition ) const;
virtual bool equivalent( const error_code &amp; code, int condition ) const;
bool operator==( const error_category &amp; rhs ) const;
bool operator!=( const error_category &amp; rhs ) const;
bool operator&lt; ( const error_category &amp; rhs ) const;
};
const error_category &amp; get_system_category();
const error_category &amp; get_generic_category();
static const error_category &amp; system_category = get_system_category();
static const error_category &amp; generic_category = get_generic_category();
}
}</pre>
</blockquote>
<h3><a name="Class-error_category-virtual-members">Class <code>error_category</code> virtual members</a></h3>
<p>Classes derived from <code>error_category</code> shall behave as specified in
this subclause.</p>
<pre>virtual const char * name() const=0;</pre>
<blockquote>
<p><i>Returns: </i>a string naming the error category.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>virtual string message( int ev ) const=0;</pre>
<blockquote>
<p><i>Returns:</i> A string that describes the error denoted by
<code>ev</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>virtual error_condition default_error_condition( int ev ) const;</code></p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>error_condition( ev, *this )</code>.</p>
<blockquote>
<p>&nbsp;[<i>--Note:</i> Derived classes will typically convert <code>ev</code>
to some portable <code>error_category</code>, such as <code>generic_category</code>,
and return it as an <code>error_condition</code> for that category. <i>--end
note</i>]</p>
</blockquote>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>virtual bool equivalent( int code, const error_condition &amp;
condition )
const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>default_error_condition( code ) == condition</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>virtual bool equivalent( const error_code &amp; code, int condition ) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>*this == code.category() &amp;&amp; code.value() == condition</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_category-non-virtual-members">Class <code>error_category</code> non-virtual members</a></h3>
<p><code>bool operator==( const error_category &amp; rhs ) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>this == &amp;rhs</code>.</p>
</blockquote>
<p><code>bool operator!=( const error_category &amp; rhs ) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>this != &amp;rhs</code>.</p>
</blockquote>
<pre>bool operator&lt;( const error_category &amp; rhs ) const;</pre>
<blockquote>
<p><i>Returns:</i> <code>std::less&lt;const error_category*&gt;()( this, &amp;rhs )</code>.</p>
<blockquote>
<p><i>[Note:</i> <code>std::less</code> provides a total ordering for
pointers. <i>--end note]</i></p>
</blockquote>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_category-non-member-functions">Class <code>error_category</code>
non-member functions</a></h3>
<pre>const error_category &amp; get_system_category();</pre>
<blockquote>
<p><i>Returns:</i> A reference to a <code>error_category</code> object
identifying errors originating from the operating system.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>const error_category &amp; get_generic_category();</pre>
<blockquote>
<p><i>Returns:</i> A reference to a <code>error_category</code> object
identifying portable error conditions.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_category-predefined-objects">Class <code>error_category</code>
predefined objects</a></h3>
<p>Predefined objects <code>system_category</code>
and <code>generic_category</code> identify system specific error codes and portable error conditions, respectively.</p>
<h2><a name="Class-error_code">Class <code>
error_code</code></a></h2>
<p>The class <code>error_code</code> describes an object used to hold error code
values, such as those originating from the operating<br>
system or other low-level application program interfaces. <i>[ Note: </i>Class
<code>error_code</code> is an adjunct to error reporting by<br>
exception. <i><EFBFBD>end note ]</i></p>
<h3><a name="Class-error_code-synopsis">Class <code>
error_code</code> synopsis</a></h3>
<blockquote>
<pre>namespace boost
{
namespace system
{
class error_code {
public:
// constructors:
error_code();
error_code( val, const error_category &amp; cat );
template &lt;class <code>ErrorCodeEnum</code>&gt;
error_code(<code> ErrorCodeEnum</code> e,
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt; &gt;::type* = 0);
// modifiers:
void assign( int val, const error_category &amp; cat );
template&lt;typename <code>ErrorCodeEnum</code>&gt;
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt;, error_code&gt;::type &amp;
operator=( <code>ErrorCodeEnum</code> val );;
void clear();
// observers:
int value() const;
cont error_category &amp; category() const;
error_condition default_error_condition() const;
string message() const;
operator unspecified-bool-type() const;
private:
int val_; // <i>exposition only</i>
const error_category * cat_; // <i>exposition only</i>
};
}
}</pre>
</blockquote>
<h3><a name="Class-error_code-constructors">Class <code>
error_code</code> constructors</a></h3>
<pre>error_code();</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 &amp;&amp; cat_ == &amp;system_category</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_code( int val, const error_category &amp; cat );</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
<p><i>Postconditions:</i> <code>val_ == val &amp;&amp; cat_ == &amp;cat</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template &lt;class <code>ErrorCodeEnum</code>&gt;
error_code(<code> errorCodeEnum</code> val,
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt; &gt;::type* = 0);</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_code( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_code-modifiers">Class <code>
error_code</code> modifiers</a></h3>
<pre>void assign( int val, const error_category &amp; cat );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>val_ == val &amp;&amp; cat_ == &amp;cat</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template&lt;typename <code>ErrorCodeEnum</code>&gt;
typename enable_if&lt;is_error_code_enum&lt;<code>ErrorCodeEnum</code>&gt;, error_code&gt;::type &amp;
operator=( <code>ErrorCodeEnum</code> val );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>*this == make_error_code( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>void clear();</code></p>
<blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == generic_category</code></p>
</blockquote>
<h3><a name="Class-error_code-observers">Class <code>
error_code</code> observers</a></h3>
<p><code>int value() const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>val_</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>const error_category &amp; category() const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>*cat_</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_condition default_error_condition() const;</pre>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>category().default_error_condition( value())</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>string message() const;</code></p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>category().message( value())</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>operator <i>unspecified-bool-type</i>() const;</code></p>
<blockquote>
<p><i>Returns:</i> if <code>value() != 0</code>, returns a value that will evaluate
<code>true</code> in a boolean context; otherwise, returns a value that will
evaluate <code>false</code> in a boolean context. The value type returned shall
not be convertible to <code>int</code>.</p>
<p><i>Throws:</i> nothing.</p>
<p><i>[Note: </i>This conversion can be used in contexts where a <code>bool</code>
is expected ( e.g., an <code>if</code> condition ); however, implicit conversions
( e.g., to <code>int</code>) that can occur with <code>bool</code> are not
allowed, eliminating some sources of user error. One possible implementation
choice for this type is pointer-to-member. <i>--end note ]</i></p>
</blockquote>
<h2><a name="Class-error_condition">Class <code>error_condition</code></a></h2>
<p>The class <code>error_condition</code> describes an object used to hold
values identifying error conditions. <i>[ Note: </i><code>error_condition</code>
values are portable abstractions, while <code>error_code</code> values are
implementation specific. <i>--end note ]</i></p>
<h3><a name="Class-error_condition-synopsis">Class <code>error_condition</code> synopsis</a></h3>
<blockquote>
<pre>namespace boost
{
namespace system
{
class error_condition
{
public:
// constructors:
error_condition();
error_condition( int val, const error_category &amp; cat );
template &lt;class ErrorConditionEnum&gt;
error_condition( errorConditionEnum val,
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt; &gt;::type* = 0 );
// modifiers:
void assign( int val, const error_category &amp; cat );
template&lt;typename ErrorConditionEnum&gt;
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;, error_code&gt;::type &amp;
operator=( ErrorConditionEnum val );
void clear();
// observers:
int value() const;
const error_category &amp; category() const;
string message() const;
operator unspecified-bool-type () const;
private:
int val_; // <i>exposition only</i>
const error_category * cat_; // <i>exposition only</i>
};
}
}</pre>
</blockquote>
<h3><a name="Class-error_condition-constructors">Class <code>error_condition</code>
constructors</a></h3>
<pre>error_condition(); </pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p>
<p><i>Postconditions:</i> <code>val_ == 0 and cat_ == &amp;generic_category</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_condition( int val, const error_category &amp; cat );</pre>
<blockquote>
<p><i>Effects: </i>Constructs an object of type error_condition.</p>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == &amp;cat</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template &lt;class ErrorConditionEnum&gt;
error_condition( errorConditionEnum val,
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt; &gt;::type* = 0 );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of type <code>error_condition</code>.</p>
<p><i>Postconditions:</i> <code>*this == make_error_condition( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3><a name="Class-error_condition-modifiers">Class <code>error_condition</code>
modifiers</a></h3>
<pre>void assign( int val, const error_category &amp; cat ); </pre>
<blockquote>
<p><i>Postconditions:</i> <code>val_ == val and cat_ == &amp;cat</code>. </p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>template&lt;typename ErrorConditionEnum&gt;
typename enable_if&lt;is_error_condition_enum&lt;ErrorConditionEnum&gt;, error_code&gt;::type &amp;
operator=( ErrorConditionEnum val );</pre>
<blockquote>
<p><i>Postconditions:</i> <code>*this == make_error_condition( val )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>void clear();</code></p>
<blockquote>
<p><i>postcondition:</i> <code>value() == 0 &amp;&amp; category() == generic_category</code></p>
</blockquote>
<h3><a name="Class-error_condition-observers">Class <code>error_condition</code>
observers</a></h3>
<pre>int value() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>val_</code>.</p>
<p><i>Throws:</i> Nothing</p>
</blockquote>
<pre>const error_category &amp; category() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>*cat_</code>.</p>
<p>Throws: Nothing.</p>
</blockquote>
<pre>string message() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>category().message( value() )</code>.</p>
<p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>operator unspecified-bool-type () const;</pre>
<blockquote>
<p><i>Returns: </i>If <code>value() != 0</code>, returns a value that will
evaluate <code>true</code> in a boolean context; otherwise, returns a value
that will evaluate <code>false</code>. The return type shall not be
convertible to <code>int</code>. </p>
<p><i>Throws:</i> Nothing.</p>
<p><i>&nbsp;[ Note:</i> This conversion can be used in contexts where a <code>bool</code>
is expected ( e.g., an if condition ); however, implicit conversions ( e.g., to
<code>int</code>) that can occur with <code>bool</code> are not allowed,
eliminating some sources of user error. One possible implementation choice for
this type is pointer to member. <i>--end note</i> <i>]</i></p>
</blockquote>
<h2><a name="throws-object"><code>throws</code> object</a></h2>
<pre>extern error_code throws;</pre>
<p>The predefined <code>error_code</code> object <code>throws</code> is supplied
for use as a &quot;throw on error&quot; tag.</p>
<h2><a name="Semantics-of-throws">Semantics of <code>throws</code></a> object</h2>
<p>Functions that specify an argument in the form <code>error_code&amp; ec=throws</code>,
with appropriate namespace qualifiers, have the following error handling
semantics:</p>
<blockquote>
<p><i>Postconditions:</i></p>
<blockquote>
<p>If <code>&amp;ec != &amp;throws</code> and an error occurred:</p>
<ul>
<li> <code>ec.value()</code> returns the implementation specific error
number for the particular error that occurred.</li>
<li><code>ec.category()</code> returns the <code>
<a href="#Class-error_category">error_category</a></code> for <code>ec.value()</code>.</li>
</ul>
<p>if <code>&amp;ec != &amp;throws</code> and an error did not occur, <code>ec.clear()</code>.</p>
</blockquote>
<p><i>Throws:</i></p>
<blockquote>
<p>If an error occurs and <code>&amp;ec == &amp;throws</code>, throws an exception of type
<code><a href="#Class-system_error">system_error</a></code> or of a type
derived from <code><a href="#Class-system_error">system_error</a></code>. The
exception's <code>code()</code> member function returns a reference to an
<code>error_code</code> object with the behavior specified in <i>
Postconditions</i>.</p>
</blockquote>
</blockquote>
<h2><a name="Non-member-functions">Non-member functions</a></h2>
<pre>bool operator==( const error_code &amp; lhs, const error_code &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>lhs.category() == rhs.category() &amp;&amp; lhs.value() ==
rhs.value()</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator==( const error_code &amp; code, const error_condition &amp; condition );
bool operator==( const error_condition &amp; condition, const error_code &amp; code );</pre>
<blockquote>
<p><i>Returns:</i> <code>code.category().equivalent( code.value(), condition )<br>
|| condition.category().equivalent( code, condition.value() )</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator==( const error_condition &amp; lhs, const error_condition &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>lhs.category() == rhs.category() &amp;&amp; lhs.value() ==
rhs.value()</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator!=( const error_code &amp; lhs, const error_code &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>!(lhs == rhs )</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator!=( const error_code &amp; code, const error_condition &amp; condition );
bool operator!=( const error_condition &amp; condition, const error_code &amp; code );</pre>
<blockquote>
<p><i>Returns:</i><code> !( code ==&nbsp; condition )</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator!=( const error_condition &amp; lhs, const error_condition &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>!(lhs == rhs )</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator&lt;( const error_code &amp; lhs, const error_code &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>lhs.category() &lt; rhs.category()<br>
&nbsp; || (lhs.category() == rhs.category() &amp;&amp; lhs.value() &lt; rhs.value())</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>bool operator&lt;( const error_condition &amp; lhs, const error_condition &amp; rhs );</pre>
<blockquote>
<p><i>Returns:</i> <code>lhs.category() &lt; rhs.category()<br>
&nbsp; || (lhs.category() == rhs.category() &amp;&amp; lhs.value() &lt; rhs.value())</code>.</p>
<p><i>Throws: </i>Nothing.</p>
</blockquote>
<pre>error_code make_error_code( errc::errc_t e );</pre>
<blockquote>
<p><i>Returns:</i> <code>error_code( e, generic_category)</code>.</p>
</blockquote>
<pre>error_condition make_error_condition( errc::errc_t e );</pre>
<blockquote>
<p><i>Returns:</i> <code>error_condition( static_cast&lt;int&gt;( e ), generic_category)</code>.</p>
</blockquote>
<pre>template &lt;class charT, class traits&gt;
std::basic_ostream&lt;charT,traits&gt;&amp;
operator&lt;&lt;( basic_ostream&lt;charT,traits&gt;&amp; os, const error_code &amp; ec );</pre>
<blockquote>
<p><i>Effects:</i> <code>os &lt;&lt; ec.category().name() &lt;&lt; ':' &lt;&lt; ec.value()</code>.</p>
<p><i>Returns:</i> <code>os</code>.</p>
</blockquote>
<pre>size_t <a name="hash_value">hash_value</a>( const error_code &amp; ec );</pre>
<blockquote>
<p><i>Returns: </i>&nbsp;A hash value representing <code>ec</code>.</p>
</blockquote>
<h2><a name="Header-system_error">Header &lt;boost/system/system_error.hpp&gt;</a></h2>
<h3><a name="Class-system_error">Class <code>
system_error</code></a></h3>
<p>The class <code>system_error</code> describes an exception object used to
report errors that have an associated <code><a href="#Class-error_code">error_code</a></code>. Such errors typically originate from operating system or other low-level
application program interfaces.</p>
<blockquote>
<pre>namespace boost
{
namespace system
{
class system_error : public std::runtime_error
{
public:
system_error( error_code ec );
system_error( error_code ec, const char * what_arg );
system_error( error_code ec, const std::string &amp; what_arg );
system_error( int ev, const error_category &amp; ecat,
const char * what_arg );
system_error( int ev, const error_category &amp; ecat,
const std::string &amp; what_arg );
system_error( int ev, const error_category &amp; ecat);
const error_code &amp; code() const throw();
const char * what() const throw();
};
}
}</pre>
</blockquote>
<pre>system_error( error_code ec );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), &quot;&quot; ) == 0</code></p>
</blockquote>
<pre>system_error( error_code ec, const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( error_code ec, const std::string &amp; what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p>
</blockquote>
<pre>system_error( int ev, const error_category &amp; ecat,
const char * what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg ) == 0</code></p>
</blockquote>
<pre>system_error( int ev, const error_category &amp; ecat,
const std::string &amp; what_arg );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), what_arg.c_str() ) == 0</code></p>
</blockquote>
<pre>system_error( int ev, const error_category &amp; ecat );</pre>
<blockquote>
<p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
<p><i>Postcondition:</i> <code>code() == error_code( ev, ecat )<br>
&nbsp; &amp;&amp; std::strcmp( this-&gt;runtime_error::what(), &quot;&quot; ) == 0</code></p>
</blockquote>
<pre>const error_code &amp; code() const;</pre>
<blockquote>
<p><i>Returns:</i> <code>ec</code> or <code>error_code( ev, ecat )</code>, from
the constructor, as appropriate.</p>
</blockquote>
<pre>const char * what() const;</pre>
<blockquote>
<p><i>Returns: </i>A string incorporating <code>
this-&gt;runtime_error::what()</code> and <code>
code.message()</code>.</p>
</blockquote>
<hr>
<p>Revised
<!--webbot bot="Timestamp" S-Type="EDITED" S-Format="%B %d, %Y" startspan -->October 11, 2008<!--webbot bot="Timestamp" endspan i-checksum="30976" --> </font>
</p>
<p><EFBFBD> Copyright Beman Dawes, 2006, 2007, 2008</p>
<p>Distributed under the Boost Software License, Version 1.0. See
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a></p>
</body>
</html>

View File

@ -0,0 +1,6 @@
<style>
*:not(pre)>code { background: none; color: #600000; }
:not(pre):not([class^=L])>code { background: none; color: #600000; }
</style>

30
doc/system.adoc Normal file
View File

@ -0,0 +1,30 @@
////
Copyright 2018 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
See accompanying file LICENSE_1_0.txt or copy at
https://www.boost.org/LICENSE_1_0.txt
////
# Boost.System: Extensible Error Reporting
Beman Dawes, Christopher Kohlhoff, Peter Dimov
:toc: left
:toclevels: 4
:idprefix:
:docinfo: private-footer
:source-highlighter: rouge
:source-language: c++
:leveloffset: +1
include::system/introduction.adoc[]
include::system/usage.adoc[]
include::system/changes.adoc[]
include::system/rationale.adoc[]
include::system/reference.adoc[]
include::system/history.adoc[]
include::system/acknowledgements.adoc[]
include::system/copyright.adoc[]
:leveloffset: -1

View File

@ -0,0 +1,19 @@
////
Copyright 2003-2017 Beman Dawes
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
////
[#acknowledgments]
# Acknowledgments
:idprefix: ack_
Christopher Kohlhoff and Peter Dimov made important contributions to the
design. Comments and suggestions were also received from Pavel Vozenilek,
Gennaro Prota, Dave Abrahams, Jeff Garland, Iain Hanson, Oliver Kowalke, and
Oleg Abrosimov. Christopher Kohlhoff suggested several improvements to the
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2066.html[N2066]
paper. Johan Nilsson's comments led to several of the refinements in N2066.

133
doc/system/changes.adoc Normal file
View File

@ -0,0 +1,133 @@
////
Copyright 2018-2022 Peter Dimov
Distributed under the Boost Software License, Version 1.0.
https://www.boost.org/LICENSE_1_0.txt
////
[#changes]
# Revision History
:idprefix:
## Changes in Boost 1.80
* When an `error_code` is converted to `std::error_code` and then back
to `error_code`, the original is now restored, if possible.
* Reworked the conversion from `error_category` to `std::error_category`
to avoid the one-time allocation that shows up on leak checkers.
* 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 `boost::source_location` parameter to `throw_exception_from_error`.
* Added `throw_exception_from_error` overloads for `errc::errc_t`,
`std::error_code`, `std::errc`, `std::exception_ptr`.
* `result<T>::value` now automatically supplies `BOOST_CURRENT_LOCATION` to
`throw_exception_from_error` via a default argument.
* Added an `errc::make_error_code` overload taking a source location.
## Changes in Boost 1.78
* Added support for source locations to `error_code`.
* Added `error_code::to_string`, `error_condition::to_string`, `error_code::what`.
* `system_error::what()` now contains the source location, if present.
* Added `result<T, E = error_code>`, a class holding either a value or an
error, defined in `<boost/system/result.hpp>`.
## Changes in Boost 1.77
* The conversion operator from `error_category` to `std::error_category`
has been improved and no longer requires `<map>` or `<mutex>`.
* The comparison operators of `error_category` are now inline friends
instead of member functions (a side effect of the previous change.)
* `error_condition` now defers calling `generic_category()` to avoid
instantiating the object until it's actually needed.
* `error_condition::failed` and `error_condition::message` have been
undeprecated, and `operator bool()` now once again returns `failed()`.
* The system category now doesn't call `generic_category()`, to avoid
instantiating the object.
* The return value of `default_error_condition` changes in some cases into
an `error_condition` from the generic category, instead of from the system
category. This happens on POSIX when the input `error_code` is from
the system category and does not correspond to any `errc_t` value.
* The interoperability of `error_code` and `std::error_code` has been
improved substantially. It is now possible to construct
`boost::system::error_code` from `std::error_code`, and it's possible
to pass `boost::system::error_code` to functions taking `std::error_code&`.
* A stream insertion operator for `error_condition` has been added.
## Changes in Boost 1.76
* `windows_error.hpp` is no longer deprecated.
## Changes in Boost 1.75
* The platform-specific headers `windows_error.hpp`, `linux_error.hpp`,
and `cygwin_error.hpp` emit deprecation messages and are slated for
removal.
* The old names for `generic_category()` and `system_category()` emit
deprecation messages and are slated for removal.
* `error_condition::failed` is deprecated and is slated for removal.
`operator bool()` for `error_condition` has been reverted to its old
meaning of `value() != 0`. This is done for compatibility with
`std::error_condition` as the next release is expected to improve
interoperability with `<system_error>` even further. _Note that this
does not affect_ `error_code::failed`, which is still alive and well.
* The overload of `error_condition::message` that takes a buffer is
deprecated and is slated for removal, for the same reasons. _Note that
this does not affect_ `error_code::message`.
## Changes in Boost 1.74
* `operator bool()` now returns `failed()` instead of `value() != 0`.
## Changes in Boost 1.69
* Boost.System is now header-only. A stub library is still built for
compatibility, but linking to it is no longer necessary.
* Even more functions have been marked `constexpr`.
* The destructor of `error_category` is now protected and no longer
virtual. This is a _potentially breaking change_ but its impact
is expected to be limited.
* `error_category` now has a constructor that accepts a 64 bit identifier,
enabling distinct category objects to compare equal.
* The constructors of `error_category` are now protected.
* A non-allocating, nonthrowing overload of `message` has been added.
* A virtual function `failed` has been added, allowing categories for
which success is not synonymous with 0.
* The deprecated `boost::system::throws` object has been removed.
* `boost::throws()` is now deprecated and its use is discouraged.
* The constructor of `system_error` taking a single `error_code` argument
is now explicit.
* `system_error::code()` now returns by value.
## Changes in Boost 1.68
On a {cpp}14 compiler, many Boost.System functions and member functions
are now `constexpr`, and `error_code` and `error_condition` are literal
classes.
In addition to enabling use in constant expressions (and `constexpr`
functions), this significantly improves the quality of the generated code.
As a result of this change, however, now using Boost.System from {cpp}14
or {cpp}17 code requires that the library be also built with {cpp}14 or
above. This is the default on GCC 6 and newer, but not on GCC 5 or Clang.
One can build Boost for {cpp}14 by passing the `cxxstd=14` option to `b2`.
(Previous versions allowed code built against any {cpp} standard to link
with Boost.System built against any {cpp} standard. In 1.68, code using
any {cpp} standard can link with Boost.System built with {cpp}14 or above,
but if Boost.System is built with {cpp}11 or below, only code also built
with {cpp}11 and below can link to it successfully.)
## Changes in Boost 1.65
On a {cpp}11 compiler, Boost.System now provides implicit conversions
from `boost::system::error_category`, `error_code`, and `error_condition`
to their standard equivalents from `<system_error>`.
This allows libraries to expose a {cpp}11 interface and report errors
via `std::error_code` even when using Boost.System, directly or through a
dependency such as Boost.ASIO.

19
doc/system/copyright.adoc Normal file
View File

@ -0,0 +1,19 @@
////
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
////
[#copyright]
# Copyright and License
:idprefix:
This documentation is
* Copyright 2003-2017 Beman Dawes
* Copyright 2018-2022 Peter Dimov
and is distributed under the http://www.boost.org/LICENSE_1_0.txt[Boost Software License, Version 1.0].

30
doc/system/history.adoc Normal file
View File

@ -0,0 +1,30 @@
////
Copyright 2003-2017 Beman Dawes
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
////
[#history]
# History
:idprefix: history_
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html[N1975],
Filesystem Library Proposal for TR2, accepted for Library Technical
Report 2 (TR2) at the Berlin meeting, included additional components to
supplement the Standard Library's Diagnostics clause. Since then, these error
reporting components have received wider public scrutiny and enhancements have
been made to the design. The enhanced version has been used by
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2054.pdf[N2054],
Networking Library Proposal for TR2, demonstrating that these error reporting
components are useful beyond the original Filesystem Library.
The original proposal viewed error categories as a binary choice between
`errno` (i.e. POSIX-style) and the native operating system's error
codes. The proposed components now allow as many additional error categories as
are needed by either implementations or by users. The need to support additional
error categories, for example, occurs in some networking library implementations
because they are built on top of the POSIX `getaddrinfo` API that
uses error codes not based on `errno`.

View File

@ -0,0 +1,78 @@
////
Copyright 2003-2017 Beman Dawes
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
////
[#introduction]
# Introduction
:idprefix: intro_
Errors originating from the operating system or other low-level application
program interfaces (APIs) are typically reported via an integer representing
an error code, either by returning the code directly from the function (e.g.
`pthread_mutex_init`) or by using a side channel such as the `errno`
pseudo-variable under POSIX or `GetLastError()` under Windows.
However, these integer error values can only be interpreted when their source
is known. The value 5 under Windows means `ERROR_ACCESS_DENIED` when returned
by `GetLastError()`, but `EIO` when retrieved from `errno`. And conversely,
the same error condition "access denied" is represented by the value 5 when
returned by `GetLastError()` and 13 (`EACCES`) when retrieved from `errno`.
This means that in order for code to be able to handle errors from both
sources (to retrieve a text message describing the error, or to check whether
the error means "access denied"), it needs to know where the integer error
value originated. For this to be possible, the integer error value needs to
be accompanied by a piece of information identifying the source.
Boost.System provides a framework in which this is possible. Errors are
represented by a class `error_code` which contains both the error value and
a pointer to their source (called "category"), represented as a class derived
from `error_category`.
The category provides member functions such as `message`, which returns a text
message for a specific error value, and `equivalent`, which can be used to test
whether a specific error value correspond to an error condition such as "access
denied". `error_code` uses these category-provided functions in the
implementation of its `message` and `operator==` member functions.
Boost.System contains two predefined category classes, the generic category
(a reference to which is returned by `generic_category()`) and the system
category (`system_category()`). The generic category represents the error
values of the portable subset of `errno` values defined by the POSIX standard,
whereas the system category is OS dependent. Under POSIX, the system category
represents the `errno` values returned by the OS APIs (a superset of those in
the generic category), whereas under Windows, the system category represents
the error values returned by `GetLastError()`.
The framework is extensible. Users can define their own categories by
deriving a class from `error_category` and implementing a function that
returns a reference to an instance of it. This capability is useful both for
describing library-defined error values, and for adapting existing C API
libraries that return integer error values.
For those who prefer error reporting via exceptions, Boost.System provides
a standard exception class `system_error` that stores an `error_code`.
Boost.System was standardized in {cpp}11 as `<system_error>`. For a while,
the two were equivalent, but Boost.System has evolved since then and now
contains a number of extensions over its standard sibling:
* A non-allocating overload of `message`;
* Support for nonzero error codes meaning success, via the `failed` member
functions;
* Support for 64 bit category identifiers, as a solution to the problem
that sometimes it's not possible to ensure that only one instance of a
category exists in the program;
* Support for attaching source locations (file/line/function) to error codes;
* A class `result<T>` that can be used to return either a value or an error
code from a function;
* Various other minor improvements.
`boost::system::error_code` can be converted to, and constructed from,
`std::error_code`.

27
doc/system/rationale.adoc Normal file
View File

@ -0,0 +1,27 @@
////
Copyright 2003-2017 Beman Dawes
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
////
[#rationale]
# Design Rationale
:idprefix: rationale_
`error_code` and `error_condition` are designed as value types so
they can be copied without slicing and do not require heap allocation, but
still have polymorphic behavior based on the error category. This is achieved
by abstract base class `error_category` supplying the polymorphic behavior,
and `error_code` and `error_condition` containing a pointer to an object of a
type derived from `error_category`.
Many of the detailed design decisions were driven by the requirements that
users to be able to add additional error categories, and that it be no more
difficult to write portable code than system-specific code.
The `operator<<` overload for `error_code` eliminates a misleading conversion to
`bool` in code like `cout << ec`, where `ec` is of type `error_code`. It is also
useful in its own right.

2151
doc/system/reference.adoc Normal file

File diff suppressed because it is too large Load Diff

1414
doc/system/usage.adoc Normal file

File diff suppressed because it is too large Load Diff

View File

@ -7,325 +7,9 @@
// See library home page at http://www.boost.org/libs/system
#ifndef BOOST_CERRNO_HPP
#define BOOST_CERRNO_HPP
#ifndef BOOST_CERRNO_HPP_INCLUDED
#define BOOST_CERRNO_HPP_INCLUDED
#include <cerrno>
#include <boost/system/detail/cerrno.hpp>
// supply errno values likely to be missing, particularly on Windows
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT 9901
#endif
#ifndef EADDRINUSE
#define EADDRINUSE 9902
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL 9903
#endif
#ifndef EISCONN
#define EISCONN 9904
#endif
#ifndef EBADMSG
#define EBADMSG 9905
#endif
#ifndef ECONNABORTED
#define ECONNABORTED 9906
#endif
#ifndef EALREADY
#define EALREADY 9907
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED 9908
#endif
#ifndef ECONNRESET
#define ECONNRESET 9909
#endif
#ifndef EDESTADDRREQ
#define EDESTADDRREQ 9910
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH 9911
#endif
#ifndef EIDRM
#define EIDRM 9912
#endif
#ifndef EMSGSIZE
#define EMSGSIZE 9913
#endif
#ifndef ENETDOWN
#define ENETDOWN 9914
#endif
#ifndef ENETRESET
#define ENETRESET 9915
#endif
#ifndef ENETUNREACH
#define ENETUNREACH 9916
#endif
#ifndef ENOBUFS
#define ENOBUFS 9917
#endif
#ifndef ENOLINK
#define ENOLINK 9918
#endif
#ifndef ENODATA
#define ENODATA 9919
#endif
#ifndef ENOMSG
#define ENOMSG 9920
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT 9921
#endif
#ifndef ENOSR
#define ENOSR 9922
#endif
#ifndef ENOTSOCK
#define ENOTSOCK 9923
#endif
#ifndef ENOSTR
#define ENOSTR 9924
#endif
#ifndef ENOTCONN
#define ENOTCONN 9925
#endif
#ifndef ENOTSUP
#define ENOTSUP 9926
#endif
#ifndef ECANCELED
#define ECANCELED 9927
#endif
#ifndef EINPROGRESS
#define EINPROGRESS 9928
#endif
#ifndef EOPNOTSUPP
#define EOPNOTSUPP 9929
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK 9930
#endif
#ifndef EOWNERDEAD
#define EOWNERDEAD 9931
#endif
#ifndef EPROTO
#define EPROTO 9932
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT 9933
#endif
#ifndef ENOTRECOVERABLE
#define ENOTRECOVERABLE 9934
#endif
#ifndef ETIME
#define ETIME 9935
#endif
#ifndef ETXTBSY
#define ETXTBSY 9936
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 9938
#endif
#ifndef ELOOP
#define ELOOP 9939
#endif
#ifndef EOVERFLOW
#define EOVERFLOW 9940
#endif
#ifndef EPROTOTYPE
#define EPROTOTYPE 9941
#endif
#ifndef ENOSYS
#define ENOSYS 9942
#endif
#ifndef EINVAL
#define EINVAL 9943
#endif
#ifndef ERANGE
#define ERANGE 9944
#endif
#ifndef EILSEQ
#define EILSEQ 9945
#endif
// Windows Mobile doesn't appear to define these:
#ifndef E2BIG
#define E2BIG 9946
#endif
#ifndef EDOM
#define EDOM 9947
#endif
#ifndef EFAULT
#define EFAULT 9948
#endif
#ifndef EBADF
#define EBADF 9949
#endif
#ifndef EPIPE
#define EPIPE 9950
#endif
#ifndef EXDEV
#define EXDEV 9951
#endif
#ifndef EBUSY
#define EBUSY 9952
#endif
#ifndef ENOTEMPTY
#define ENOTEMPTY 9953
#endif
#ifndef ENOEXEC
#define ENOEXEC 9954
#endif
#ifndef EEXIST
#define EEXIST 9955
#endif
#ifndef EFBIG
#define EFBIG 9956
#endif
#ifndef ENAMETOOLONG
#define ENAMETOOLONG 9957
#endif
#ifndef ENOTTY
#define ENOTTY 9958
#endif
#ifndef EINTR
#define EINTR 9959
#endif
#ifndef ESPIPE
#define ESPIPE 9960
#endif
#ifndef EIO
#define EIO 9961
#endif
#ifndef EISDIR
#define EISDIR 9962
#endif
#ifndef ECHILD
#define ECHILD 9963
#endif
#ifndef ENOLCK
#define ENOLCK 9964
#endif
#ifndef ENOSPC
#define ENOSPC 9965
#endif
#ifndef ENXIO
#define ENXIO 9966
#endif
#ifndef ENODEV
#define ENODEV 9967
#endif
#ifndef ENOENT
#define ENOENT 9968
#endif
#ifndef ESRCH
#define ESRCH 9969
#endif
#ifndef ENOTDIR
#define ENOTDIR 9970
#endif
#ifndef ENOMEM
#define ENOMEM 9971
#endif
#ifndef EPERM
#define EPERM 9972
#endif
#ifndef EACCES
#define EACCES 9973
#endif
#ifndef EROFS
#define EROFS 9974
#endif
#ifndef EDEADLK
#define EDEADLK 9975
#endif
#ifndef EAGAIN
#define EAGAIN 9976
#endif
#ifndef ENFILE
#define ENFILE 9977
#endif
#ifndef EMFILE
#define EMFILE 9978
#endif
#ifndef EMLINK
#define EMLINK 9979
#endif
#endif // include guard
#endif // #ifndef BOOST_CERRNO_HPP_INCLUDED

18
include/boost/system.hpp Normal file
View File

@ -0,0 +1,18 @@
#ifndef BOOST_SYSTEM_HPP_INCLUDED
#define BOOST_SYSTEM_HPP_INCLUDED
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/error_code.hpp>
#include <boost/system/system_error.hpp>
#include <boost/config.hpp>
#if (__cplusplus >= 201103L) && !(defined(BOOST_GCC) && BOOST_GCC < 40800) || (defined(_MSC_VER) && _MSC_VER >= 1900)
# include <boost/system/result.hpp>
#endif
#endif // #ifndef BOOST_SYSTEM_HPP_INCLUDED

View File

@ -0,0 +1,42 @@
// boost/system/api_config.hpp -------------------------------------------------------//
// Copyright Beman Dawes 2003, 2006, 2010
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See http://www.boost.org/libs/system for documentation.
//--------------------------------------------------------------------------------------//
// Boost.System calls operating system API functions to implement system error category
// functions. Usually there is no question as to which API is to be used.
//
// In the case of MinGW or Cygwin/MinGW, however, both POSIX and Windows API's are
// available. Chaos ensues if other code thinks one is in use when Boost.System was
// actually built with the other. This header centralizes the API choice and prevents
// user definition of API macros, thus elminating the possibility of mismatches and the
// need to test configurations with little or no practical value.
//
//--------------------------------------------------------------------------------------//
#ifndef BOOST_SYSTEM_API_CONFIG_HPP
#define BOOST_SYSTEM_API_CONFIG_HPP
# if defined(BOOST_POSIX_API) || defined(BOOST_WINDOWS_API)
# error user defined BOOST_POSIX_API or BOOST_WINDOWS_API not supported
# endif
// BOOST_POSIX_API or BOOST_WINDOWS_API specify which API to use
// Cygwin/MinGW does not predefine _WIN32.
// Standalone MinGW and all other known Windows compilers do predefine _WIN32
// Compilers that predefine _WIN32 or __MINGW32__ do so for Windows 64-bit builds too.
# if defined(_WIN32) || defined(__CYGWIN__) // Windows default, including MinGW and Cygwin
# define BOOST_WINDOWS_API
# else
# define BOOST_POSIX_API
# endif
#endif // BOOST_SYSTEM_API_CONFIG_HPP

View File

@ -1,4 +1,4 @@
// boost/system/config.hpp -------------------------------------------------//
// boost/system/config.hpp -----------------------------------------------------------//
// Copyright Beman Dawes 2003, 2006
@ -7,69 +7,44 @@
// See http://www.boost.org/libs/system for documentation.
#ifndef BOOST_SYSTEM_CONFIG_HPP
#ifndef BOOST_SYSTEM_CONFIG_HPP
#define BOOST_SYSTEM_CONFIG_HPP
#include <boost/config.hpp>
#include <boost/system/api_config.hpp> // for BOOST_POSIX_API or BOOST_WINDOWS_API
// BOOST_POSIX_API or BOOST_WINDOWS_API specify which API to use.
// If not specified, a sensible default will be applied.
// This header implemented separate compilation features as described in
// http://www.boost.org/more/separate_compilation.html
//
// It's only retained for compatibility now that the library is header-only.
# if defined( BOOST_WINDOWS_API ) && defined( BOOST_POSIX_API )
# error both BOOST_WINDOWS_API and BOOST_POSIX_API are defined
# elif !defined( BOOST_WINDOWS_API ) && !defined( BOOST_POSIX_API )
# if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) || defined(__CYGWIN__)
# define BOOST_WINDOWS_API
# else
# define BOOST_POSIX_API
# endif
// normalize macros ------------------------------------------------------------------//
#if !defined(BOOST_SYSTEM_DYN_LINK) && !defined(BOOST_SYSTEM_STATIC_LINK) \
&& !defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_ALL_STATIC_LINK)
# define BOOST_SYSTEM_STATIC_LINK
#endif
#if defined(BOOST_ALL_DYN_LINK) && !defined(BOOST_SYSTEM_DYN_LINK)
# define BOOST_SYSTEM_DYN_LINK
#elif defined(BOOST_ALL_STATIC_LINK) && !defined(BOOST_SYSTEM_STATIC_LINK)
# define BOOST_SYSTEM_STATIC_LINK
#endif
#if defined(BOOST_SYSTEM_DYN_LINK) && defined(BOOST_SYSTEM_STATIC_LINK)
# error Must not define both BOOST_SYSTEM_DYN_LINK and BOOST_SYSTEM_STATIC_LINK
#endif
// enable dynamic or static linking as requested --------------------------------------//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
# if defined(BOOST_SYSTEM_SOURCE)
# define BOOST_SYSTEM_DECL BOOST_SYMBOL_EXPORT
# else
# define BOOST_SYSTEM_DECL BOOST_SYMBOL_IMPORT
# endif
// enable dynamic linking on Windows ---------------------------------------//
//# if (defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)) && defined(__BORLANDC__) && defined(__WIN32__)
//# error Dynamic linking Boost.System does not work for Borland; use static linking instead
//# endif
#ifdef BOOST_HAS_DECLSPEC // defined in config system
// we need to import/export our code only if the user has specifically
// asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
// libraries to be dynamically linked, or BOOST_SYSTEM_DYN_LINK
// if they want just this one to be dynamically liked:
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
// export if this is our own source, otherwise import:
#ifdef BOOST_SYSTEM_SOURCE
# define BOOST_SYSTEM_DECL __declspec(dllexport)
#else
# define BOOST_SYSTEM_DECL __declspec(dllimport)
#endif // BOOST_SYSTEM_SOURCE
#endif // DYN_LINK
#endif // BOOST_HAS_DECLSPEC
//
// if BOOST_SYSTEM_DECL isn't defined yet define it now:
#ifndef BOOST_SYSTEM_DECL
#define BOOST_SYSTEM_DECL
# define BOOST_SYSTEM_DECL
#endif
// enable automatic library variant selection ------------------------------//
#if !defined(BOOST_SYSTEM_SOURCE) && !defined(BOOST_ALL_NO_LIB) && !defined(BOOST_SYSTEM_NO_LIB)
//
// Set the name of our library, this will get undef'ed by auto_link.hpp
// once it's done with it:
//
#define BOOST_LIB_NAME boost_system
//
// If we're importing code from a dll, then tell auto_link.hpp about it:
//
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_SYSTEM_DYN_LINK)
# define BOOST_DYN_LINK
#endif
//
// And include the header that does the work:
//
#include <boost/config/auto_link.hpp>
#endif // auto-linking disabled
#endif // BOOST_SYSTEM_CONFIG_HPP

View File

@ -7,8 +7,15 @@
// See library home page at http://www.boost.org/libs/system
#ifndef BOOST_CYGWIN_ERROR_HPP
#define BOOST_CYGWIN_ERROR_HPP
#ifndef BOOST_SYSTEM_CYGWIN_ERROR_HPP
#define BOOST_SYSTEM_CYGWIN_ERROR_HPP
#include <boost/config/pragma_message.hpp>
#if !defined(BOOST_ALLOW_DEPRECATED_HEADERS)
BOOST_PRAGMA_MESSAGE("This header is deprecated and is slated for removal."
" If you want it retained, please open an issue in github.com/boostorg/system.")
#endif
// This header is effectively empty for compiles on operating systems where
// it is not applicable.
@ -23,7 +30,7 @@ namespace boost
{
// To construct an error_code after a API error:
//
// error_code( errno, system_category )
// error_code( errno, system_category() )
// User code should use the portable "posix" enums for POSIX errors; this
// allows such code to be portable to non-POSIX systems. For the non-POSIX
@ -46,11 +53,11 @@ namespace boost
namespace cygwin_error
{
inline error_code make_error_code( cygwin_errno e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
}
}
#endif // __CYGWIN__
#endif // BOOST_CYGWIN_ERROR_HPP
#endif // BOOST_SYSTEM_CYGWIN_ERROR_HPP

View File

@ -0,0 +1,32 @@
#ifndef BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt)
#include <boost/system/detail/snprintf.hpp>
#include <string>
//
namespace boost
{
namespace system
{
namespace detail
{
inline void append_int( std::string& s, int v )
{
char buffer[ 32 ];
detail::snprintf( buffer, sizeof( buffer ), ":%d", v );
s += buffer;
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_APPEND_INT_HPP_INCLUDED

View File

@ -0,0 +1,329 @@
// Copyright Beman Dawes 2005.
// Use, modification, and distribution is subject to 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
#ifndef BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED
#include <cerrno>
// supply errno values likely to be missing, particularly on Windows
#ifndef EAFNOSUPPORT
#define EAFNOSUPPORT 9901
#endif
#ifndef EADDRINUSE
#define EADDRINUSE 9902
#endif
#ifndef EADDRNOTAVAIL
#define EADDRNOTAVAIL 9903
#endif
#ifndef EISCONN
#define EISCONN 9904
#endif
#ifndef EBADMSG
#define EBADMSG 9905
#endif
#ifndef ECONNABORTED
#define ECONNABORTED 9906
#endif
#ifndef EALREADY
#define EALREADY 9907
#endif
#ifndef ECONNREFUSED
#define ECONNREFUSED 9908
#endif
#ifndef ECONNRESET
#define ECONNRESET 9909
#endif
#ifndef EDESTADDRREQ
#define EDESTADDRREQ 9910
#endif
#ifndef EHOSTUNREACH
#define EHOSTUNREACH 9911
#endif
#ifndef EIDRM
#define EIDRM 9912
#endif
#ifndef EMSGSIZE
#define EMSGSIZE 9913
#endif
#ifndef ENETDOWN
#define ENETDOWN 9914
#endif
#ifndef ENETRESET
#define ENETRESET 9915
#endif
#ifndef ENETUNREACH
#define ENETUNREACH 9916
#endif
#ifndef ENOBUFS
#define ENOBUFS 9917
#endif
#ifndef ENOLINK
#define ENOLINK 9918
#endif
#ifndef ENODATA
#define ENODATA 9919
#endif
#ifndef ENOMSG
#define ENOMSG 9920
#endif
#ifndef ENOPROTOOPT
#define ENOPROTOOPT 9921
#endif
#ifndef ENOSR
#define ENOSR 9922
#endif
#ifndef ENOTSOCK
#define ENOTSOCK 9923
#endif
#ifndef ENOSTR
#define ENOSTR 9924
#endif
#ifndef ENOTCONN
#define ENOTCONN 9925
#endif
#ifndef ENOTSUP
#define ENOTSUP 9926
#endif
#ifndef ECANCELED
#define ECANCELED 9927
#endif
#ifndef EINPROGRESS
#define EINPROGRESS 9928
#endif
#ifndef EOPNOTSUPP
#define EOPNOTSUPP 9929
#endif
#ifndef EWOULDBLOCK
#define EWOULDBLOCK 9930
#endif
#ifndef EOWNERDEAD
#define EOWNERDEAD 9931
#endif
#ifndef EPROTO
#define EPROTO 9932
#endif
#ifndef EPROTONOSUPPORT
#define EPROTONOSUPPORT 9933
#endif
#ifndef ENOTRECOVERABLE
#define ENOTRECOVERABLE 9934
#endif
#ifndef ETIME
#define ETIME 9935
#endif
#ifndef ETXTBSY
#define ETXTBSY 9936
#endif
#ifndef ETIMEDOUT
#define ETIMEDOUT 9938
#endif
#ifndef ELOOP
#define ELOOP 9939
#endif
#ifndef EOVERFLOW
#define EOVERFLOW 9940
#endif
#ifndef EPROTOTYPE
#define EPROTOTYPE 9941
#endif
#ifndef ENOSYS
#define ENOSYS 9942
#endif
#ifndef EINVAL
#define EINVAL 9943
#endif
#ifndef ERANGE
#define ERANGE 9944
#endif
#ifndef EILSEQ
#define EILSEQ 9945
#endif
// Windows Mobile doesn't appear to define these:
#ifndef E2BIG
#define E2BIG 9946
#endif
#ifndef EDOM
#define EDOM 9947
#endif
#ifndef EFAULT
#define EFAULT 9948
#endif
#ifndef EBADF
#define EBADF 9949
#endif
#ifndef EPIPE
#define EPIPE 9950
#endif
#ifndef EXDEV
#define EXDEV 9951
#endif
#ifndef EBUSY
#define EBUSY 9952
#endif
#ifndef ENOTEMPTY
#define ENOTEMPTY 9953
#endif
#ifndef ENOEXEC
#define ENOEXEC 9954
#endif
#ifndef EEXIST
#define EEXIST 9955
#endif
#ifndef EFBIG
#define EFBIG 9956
#endif
#ifndef ENAMETOOLONG
#define ENAMETOOLONG 9957
#endif
#ifndef ENOTTY
#define ENOTTY 9958
#endif
#ifndef EINTR
#define EINTR 9959
#endif
#ifndef ESPIPE
#define ESPIPE 9960
#endif
#ifndef EIO
#define EIO 9961
#endif
#ifndef EISDIR
#define EISDIR 9962
#endif
#ifndef ECHILD
#define ECHILD 9963
#endif
#ifndef ENOLCK
#define ENOLCK 9964
#endif
#ifndef ENOSPC
#define ENOSPC 9965
#endif
#ifndef ENXIO
#define ENXIO 9966
#endif
#ifndef ENODEV
#define ENODEV 9967
#endif
#ifndef ENOENT
#define ENOENT 9968
#endif
#ifndef ESRCH
#define ESRCH 9969
#endif
#ifndef ENOTDIR
#define ENOTDIR 9970
#endif
#ifndef ENOMEM
#define ENOMEM 9971
#endif
#ifndef EPERM
#define EPERM 9972
#endif
#ifndef EACCES
#define EACCES 9973
#endif
#ifndef EROFS
#define EROFS 9974
#endif
#ifndef EDEADLK
#define EDEADLK 9975
#endif
#ifndef EAGAIN
#define EAGAIN 9976
#endif
#ifndef ENFILE
#define ENFILE 9977
#endif
#ifndef EMFILE
#define EMFILE 9978
#endif
#ifndef EMLINK
#define EMLINK 9979
#endif
#endif // #ifndef BOOST_SYSTEM_DETAIL_CERRNO_HPP_INCLUDED

View File

@ -0,0 +1,81 @@
#ifndef BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED
// Copyright 2018-2022 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/system for documentation.
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
// BOOST_SYSTEM_HAS_SYSTEM_ERROR
#if !defined(BOOST_NO_CXX11_HDR_SYSTEM_ERROR) && !defined(BOOST_NO_CXX11_HDR_ATOMIC) && !defined(BOOST_NO_CXX11_HDR_MUTEX)
# define BOOST_SYSTEM_HAS_SYSTEM_ERROR
#endif
// BOOST_SYSTEM_NOEXCEPT
// Retained for backward compatibility
#define BOOST_SYSTEM_NOEXCEPT BOOST_NOEXCEPT
// BOOST_SYSTEM_HAS_CONSTEXPR
#if !defined(BOOST_NO_CXX14_CONSTEXPR)
# define BOOST_SYSTEM_HAS_CONSTEXPR
#endif
#if BOOST_WORKAROUND(BOOST_GCC, < 60000)
# undef BOOST_SYSTEM_HAS_CONSTEXPR
#endif
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
# define BOOST_SYSTEM_CONSTEXPR constexpr
#else
# define BOOST_SYSTEM_CONSTEXPR
#endif
// BOOST_SYSTEM_DEPRECATED
#if defined(__clang__)
# define BOOST_SYSTEM_DEPRECATED(msg) __attribute__((deprecated(msg)))
#elif defined(__GNUC__)
# if __GNUC__ * 100 + __GNUC_MINOR__ >= 405
# define BOOST_SYSTEM_DEPRECATED(msg) __attribute__((deprecated(msg)))
# else
# define BOOST_SYSTEM_DEPRECATED(msg) __attribute__((deprecated))
# endif
#elif defined(_MSC_VER)
# define BOOST_SYSTEM_DEPRECATED(msg) __declspec(deprecated(msg))
#elif defined(__sun)
# define BOOST_SYSTEM_DEPRECATED(msg) __attribute__((deprecated(msg)))
#else
# define BOOST_SYSTEM_DEPRECATED(msg)
#endif
// BOOST_SYSTEM_CLANG_6
#if defined(__clang__) && (__clang_major__ < 7 || (defined(__APPLE__) && __clang_major__ < 11))
# define BOOST_SYSTEM_CLANG_6
#endif
//
#if defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 50000
# define BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || (defined(_MSC_VER) && _MSC_VER == 1800) || (defined(BOOST_LIBSTDCXX_VERSION) && BOOST_LIBSTDCXX_VERSION < 90000)
// Under Cygwin (and MinGW!), std::system_category() is POSIX
// Under VS2013, std::system_category() isn't quite right
// Under libstdc++ before 7.4, before 8.3, before 9.1, default_error_condition
// for the system category returns a condition from the system category
# define BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY
#endif
#endif // BOOST_SYSTEM_DETAIL_CONFIG_HPP_INCLUDED

View File

@ -0,0 +1,32 @@
#ifndef BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
namespace boost
{
namespace system
{
namespace detail
{
template<bool C, class T = void> struct enable_if
{
typedef T type;
};
template<class T> struct enable_if<false, T>
{
};
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_ENABLE_IF_HPP_INCLUDED

View File

@ -0,0 +1,126 @@
#ifndef BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018, 2020
//
// 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/is_error_condition_enum.hpp>
#include <boost/system/detail/cerrno.hpp>
namespace boost
{
namespace system
{
namespace errc
{
enum errc_t
{
success = 0,
address_family_not_supported = EAFNOSUPPORT,
address_in_use = EADDRINUSE,
address_not_available = EADDRNOTAVAIL,
already_connected = EISCONN,
argument_list_too_long = E2BIG,
argument_out_of_domain = EDOM,
bad_address = EFAULT,
bad_file_descriptor = EBADF,
bad_message = EBADMSG,
broken_pipe = EPIPE,
connection_aborted = ECONNABORTED,
connection_already_in_progress = EALREADY,
connection_refused = ECONNREFUSED,
connection_reset = ECONNRESET,
cross_device_link = EXDEV,
destination_address_required = EDESTADDRREQ,
device_or_resource_busy = EBUSY,
directory_not_empty = ENOTEMPTY,
executable_format_error = ENOEXEC,
file_exists = EEXIST,
file_too_large = EFBIG,
filename_too_long = ENAMETOOLONG,
function_not_supported = ENOSYS,
host_unreachable = EHOSTUNREACH,
identifier_removed = EIDRM,
illegal_byte_sequence = EILSEQ,
inappropriate_io_control_operation = ENOTTY,
interrupted = EINTR,
invalid_argument = EINVAL,
invalid_seek = ESPIPE,
io_error = EIO,
is_a_directory = EISDIR,
message_size = EMSGSIZE,
network_down = ENETDOWN,
network_reset = ENETRESET,
network_unreachable = ENETUNREACH,
no_buffer_space = ENOBUFS,
no_child_process = ECHILD,
no_link = ENOLINK,
no_lock_available = ENOLCK,
no_message_available = ENODATA,
no_message = ENOMSG,
no_protocol_option = ENOPROTOOPT,
no_space_on_device = ENOSPC,
no_stream_resources = ENOSR,
no_such_device_or_address = ENXIO,
no_such_device = ENODEV,
no_such_file_or_directory = ENOENT,
no_such_process = ESRCH,
not_a_directory = ENOTDIR,
not_a_socket = ENOTSOCK,
not_a_stream = ENOSTR,
not_connected = ENOTCONN,
not_enough_memory = ENOMEM,
not_supported = ENOTSUP,
operation_canceled = ECANCELED,
operation_in_progress = EINPROGRESS,
operation_not_permitted = EPERM,
operation_not_supported = EOPNOTSUPP,
operation_would_block = EWOULDBLOCK,
owner_dead = EOWNERDEAD,
permission_denied = EACCES,
protocol_error = EPROTO,
protocol_not_supported = EPROTONOSUPPORT,
read_only_file_system = EROFS,
resource_deadlock_would_occur = EDEADLK,
resource_unavailable_try_again = EAGAIN,
result_out_of_range = ERANGE,
state_not_recoverable = ENOTRECOVERABLE,
stream_timeout = ETIME,
text_file_busy = ETXTBSY,
timed_out = ETIMEDOUT,
too_many_files_open_in_system = ENFILE,
too_many_files_open = EMFILE,
too_many_links = EMLINK,
too_many_symbolic_link_levels = ELOOP,
value_too_large = EOVERFLOW,
wrong_protocol_type = EPROTOTYPE
};
} // namespace errc
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
namespace posix = errc;
namespace posix_error = errc;
#endif
template<> struct is_error_condition_enum<errc::errc_t>
{
static const bool value = true;
};
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERRC_HPP_INCLUDED

View File

@ -0,0 +1,219 @@
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/config.hpp>
#include <string>
#include <functional>
#include <cstddef>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <system_error>
# include <atomic>
#endif
namespace boost
{
namespace system
{
class error_category;
class error_code;
class error_condition;
std::size_t hash_value( error_code const & ec );
namespace detail
{
BOOST_SYSTEM_CONSTEXPR bool failed_impl( int ev, error_category const & cat );
class std_category;
} // namespace detail
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
#if defined(BOOST_MSVC)
#pragma warning(push)
#pragma warning(disable: 4351) // new behavior: elements of array will be default initialized
#endif
class BOOST_SYMBOL_VISIBLE error_category
{
private:
friend std::size_t hash_value( error_code const & ec );
friend BOOST_SYSTEM_CONSTEXPR bool detail::failed_impl( int ev, error_category const & cat );
friend class error_code;
friend class error_condition;
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
public:
error_category( error_category const & ) = delete;
error_category& operator=( error_category const & ) = delete;
#else
private:
error_category( error_category const & );
error_category& operator=( error_category const & );
#endif
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< unsigned > sc_init_;
#else
unsigned sc_init_;
#endif
protected:
#if !defined(BOOST_NO_CXX11_DEFAULTED_FUNCTIONS) && !defined(BOOST_NO_CXX11_NON_PUBLIC_DEFAULTED_FUNCTIONS)
~error_category() = default;
#else
// We'd like to make the destructor protected, to make code that deletes
// an error_category* not compile; unfortunately, doing the below makes
// the destructor user-provided and hence breaks use after main, as the
// categories may get destroyed before code that uses them
// ~error_category() {}
#endif
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 ), stdcat_(), sc_init_()
{
}
public:
virtual const char * name() const BOOST_NOEXCEPT = 0;
virtual error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT;
virtual bool equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT;
virtual bool equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT;
virtual std::string message( int ev ) const = 0;
virtual char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT;
virtual bool failed( int ev ) const BOOST_NOEXCEPT
{
return ev != 0;
}
friend BOOST_SYSTEM_CONSTEXPR bool operator==( error_category const & lhs, error_category const & rhs ) BOOST_NOEXCEPT
{
return rhs.id_ == 0? &lhs == &rhs: lhs.id_ == rhs.id_;
}
friend BOOST_SYSTEM_CONSTEXPR bool operator!=( error_category const & lhs, error_category const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
friend BOOST_SYSTEM_CONSTEXPR bool operator<( error_category const & lhs, error_category const & rhs ) BOOST_NOEXCEPT
{
if( lhs.id_ < rhs.id_ )
{
return true;
}
if( lhs.id_ > rhs.id_ )
{
return false;
}
if( rhs.id_ != 0 )
{
return false; // equal
}
return std::less<error_category const *>()( &lhs, &rhs );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
void init_stdcat() const;
# if defined(__SUNPRO_CC) // trailing __global is not supported
operator std::error_category const & () const;
# else
operator std::error_category const & () const BOOST_SYMBOL_VISIBLE;
# endif
#endif
};
#if defined(BOOST_MSVC)
#pragma warning(pop)
#endif
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif
namespace detail
{
static const boost::ulong_long_type generic_category_id = ( boost::ulong_long_type( 0xB2AB117A ) << 32 ) + 0x257EDFD0;
static const boost::ulong_long_type system_category_id = generic_category_id + 1;
static const boost::ulong_long_type interop_category_id = generic_category_id + 2;
BOOST_SYSTEM_CONSTEXPR inline bool failed_impl( int ev, error_category const & cat )
{
if( cat.id_ == system_category_id || cat.id_ == generic_category_id )
{
return ev != 0;
}
else
{
return cat.failed( ev );
}
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_HPP_INCLUDED

View File

@ -0,0 +1,196 @@
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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/error_category.hpp>
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/snprintf.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
#include <string>
#include <cstring>
namespace boost
{
namespace system
{
// error_category default implementation
inline error_condition error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
{
return error_condition( ev, *this );
}
inline bool error_category::equivalent( int code, const error_condition & condition ) const BOOST_NOEXCEPT
{
return default_error_condition( code ) == condition;
}
inline bool error_category::equivalent( const error_code & code, int condition ) const BOOST_NOEXCEPT
{
return code.equals( condition, *this );
}
inline char const * error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
if( len == 0 )
{
return buffer;
}
if( len == 1 )
{
buffer[0] = 0;
return buffer;
}
#if !defined(BOOST_NO_EXCEPTIONS)
try
#endif
{
std::string m = this->message( ev );
# if defined( BOOST_MSVC )
# pragma warning( push )
# pragma warning( disable: 4996 )
# elif defined(__clang__) && defined(__has_warning)
# pragma clang diagnostic push
# if __has_warning("-Wdeprecated-declarations")
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif
# endif
std::strncpy( buffer, m.c_str(), len - 1 );
buffer[ len-1 ] = 0;
# if defined( BOOST_MSVC )
# pragma warning( pop )
# elif defined(__clang__) && defined(__has_warning)
# pragma clang diagnostic pop
# endif
return buffer;
}
#if !defined(BOOST_NO_EXCEPTIONS)
catch( ... )
{
detail::snprintf( buffer, len, "No message text available for error %d", ev );
return buffer;
}
#endif
}
} // namespace system
} // namespace boost
// interoperability with std::error_code, std::error_condition
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#include <boost/system/detail/std_category_impl.hpp>
#include <mutex>
#include <new>
namespace boost
{
namespace system
{
namespace detail
{
template<class = void> struct stdcat_mx_holder
{
static std::mutex mx_;
};
template<class T> std::mutex stdcat_mx_holder<T>::mx_;
} // namespace detail
inline void error_category::init_stdcat() const
{
static_assert( sizeof( stdcat_ ) >= sizeof( boost::system::detail::std_category ), "sizeof(stdcat_) is not enough for std_category" );
#if defined(BOOST_MSVC) && BOOST_MSVC < 1900
// no alignof
#else
static_assert( alignof( decltype(stdcat_align_) ) >= alignof( boost::system::detail::std_category ), "alignof(stdcat_) is not enough for std_category" );
#endif
std::lock_guard<std::mutex> lk( boost::system::detail::stdcat_mx_holder<>::mx_ );
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
::new( static_cast<void*>( stdcat_ ) ) boost::system::detail::std_category( this, 0 );
sc_init_.store( 1, std::memory_order_release );
}
}
#if defined( BOOST_GCC ) && BOOST_GCC >= 40800 && BOOST_GCC < 70000
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
inline BOOST_NOINLINE error_category::operator std::error_category const & () const
{
if( id_ == detail::generic_category_id )
{
// This condition must be the same as the one in error_condition.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
static const boost::system::detail::std_category generic_instance( this, 0x1F4D3 );
return generic_instance;
#else
return std::generic_category();
#endif
}
if( id_ == detail::system_category_id )
{
// 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;
#else
return std::system_category();
#endif
}
if( sc_init_.load( std::memory_order_acquire ) == 0 )
{
init_stdcat();
}
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
#endif // #if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CATEGORY_IMPL_HPP_INCLUDED

View File

@ -0,0 +1,726 @@
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017-2021
//
// 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/is_error_code_enum.hpp>
#include <boost/system/detail/error_category.hpp>
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/system_category.hpp>
#include <boost/system/detail/system_category_impl.hpp>
#include <boost/system/detail/interop_category.hpp>
#include <boost/system/detail/enable_if.hpp>
#include <boost/system/detail/is_same.hpp>
#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 <ostream>
#include <new>
#include <cstdio>
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
# include <system_error>
#endif
#if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
#endif
namespace boost
{
namespace system
{
// class error_code
// We want error_code to be a value type that can be copied without slicing
// and without requiring heap allocation, but we also want it to have
// polymorphic behavior based on the error category. This is achieved by
// abstract base class error_category supplying the polymorphic behavior,
// and error_code containing a pointer to an object of a type derived
// from error_category.
std::size_t hash_value( error_code const & ec );
class error_code
{
private:
friend std::size_t hash_value( error_code const & ec );
private:
struct data
{
int val_;
const error_category * cat_;
};
union
{
data d1_;
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
unsigned char d2_[ sizeof(std::error_code) ];
#endif
};
// 0: default constructed, d1_ value initialized
// 1: holds std::error_code in d2_
// 2: holds error code in d1_, failed == false
// 3: holds error code in d1_, failed == true
// >3: pointer to source_location, failed_ in lsb
boost::uintptr_t lc_flags_;
private:
char const* category_name() const BOOST_NOEXCEPT
{
// return category().name();
if( lc_flags_ == 0 )
{
// must match detail::system_error_category::name()
return "system";
}
else if( lc_flags_ == 1 )
{
// must match detail::interop_error_category::name()
return "std:unknown";
}
else
{
return d1_.cat_->name();
}
}
public:
// constructors:
BOOST_SYSTEM_CONSTEXPR error_code() BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
}
BOOST_SYSTEM_CONSTEXPR error_code( int val, const error_category & cat ) BOOST_NOEXCEPT:
d1_(), lc_flags_( 2 + detail::failed_impl( val, cat ) )
{
d1_.val_ = val;
d1_.cat_ = &cat;
}
error_code( int val, const error_category & cat, source_location const * loc ) BOOST_NOEXCEPT:
d1_(), lc_flags_( ( loc? reinterpret_cast<boost::uintptr_t>( loc ): 2 ) | +detail::failed_impl( val, cat ) )
{
d1_.val_ = val;
d1_.cat_ = &cat;
}
template<class ErrorCodeEnum> BOOST_SYSTEM_CONSTEXPR error_code( ErrorCodeEnum e,
typename detail::enable_if<
is_error_code_enum<ErrorCodeEnum>::value
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
|| std::is_error_code_enum<ErrorCodeEnum>::value
#endif
>::type* = 0 ) BOOST_NOEXCEPT: d1_(), lc_flags_( 0 )
{
*this = make_error_code( e );
}
error_code( error_code const& ec, source_location const * loc ) BOOST_NOEXCEPT:
d1_(), lc_flags_( 0 )
{
*this = ec;
if( ec.lc_flags_ != 0 && ec.lc_flags_ != 1 )
{
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:
d1_(), lc_flags_( 0 )
{
#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
// modifiers:
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
{
*this = error_code( val, cat );
}
void assign( int val, const error_category & cat, source_location const * loc ) BOOST_NOEXCEPT
{
*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
{
*this = make_error_code( val );
return *this;
}
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
{
*this = error_code();
}
// observers:
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
{
if( lc_flags_ != 1 )
{
return d1_.val_;
}
else
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
unsigned cv = static_cast<unsigned>( ec.value() );
unsigned ch = static_cast<unsigned>( reinterpret_cast<boost::uintptr_t>( &ec.category() ) % 2097143 ); // 2^21-9, prime
return static_cast<int>( cv + 1000 * ch );
#else
return -1;
#endif
}
}
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
{
if( lc_flags_ == 0 )
{
return system_category();
}
else if( lc_flags_ == 1 )
{
return detail::interop_category();
}
else
{
return *d1_.cat_;
}
}
// deprecated?
error_condition default_error_condition() const BOOST_NOEXCEPT
{
return category().default_error_condition( value() );
}
std::string message() const
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
return ec.message();
}
#endif
if( lc_flags_ == 0 )
{
return detail::system_error_category_message( value() );
}
else
{
return category().message( value() );
}
}
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
#if !defined(BOOST_NO_EXCEPTIONS)
try
#endif
{
detail::snprintf( buffer, len, "%s", ec.message().c_str() );
return buffer;
}
#if !defined(BOOST_NO_EXCEPTIONS)
catch( ... )
{
detail::snprintf( buffer, len, "No message text available for error std:%s:%d", ec.category().name(), ec.value() );
return buffer;
}
#endif
}
#endif
if( lc_flags_ == 0 )
{
return detail::system_error_category_message( value(), buffer, len );
}
else
{
return category().message( value(), buffer, len );
}
}
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
{
if( lc_flags_ & 1 )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& ec = *reinterpret_cast<std::error_code const*>( d2_ );
return ec.value() != 0;
}
#endif
return true;
}
else
{
return false;
}
}
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
{
return failed();
}
#else
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
{
return failed()? unspecified_bool_true: 0;
}
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
{
return !failed();
}
#endif
bool has_location() const BOOST_NOEXCEPT
{
return lc_flags_ >= 4;
}
source_location const & location() const BOOST_NOEXCEPT
{
BOOST_STATIC_CONSTEXPR source_location loc;
return lc_flags_ >= 4? *reinterpret_cast<source_location const*>( lc_flags_ &~ static_cast<boost::uintptr_t>( 1 ) ): loc;
}
// relationals:
private:
// private equality for use in error_category::equivalent
friend class error_category;
BOOST_SYSTEM_CONSTEXPR bool equals( int val, error_category const& cat ) const BOOST_NOEXCEPT
{
if( lc_flags_ == 0 )
{
return val == 0 && cat.id_ == detail::system_category_id;
}
else if( lc_flags_ == 1 )
{
return cat.id_ == detail::interop_category_id && val == value();
}
else
{
return val == d1_.val_ && cat == *d1_.cat_;
}
}
public:
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
{
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_ );
return e1 == e2;
}
else
#endif
{
return lhs.value() == rhs.value() && lhs.category() == rhs.category();
}
}
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lhs.lc_flags_ == 1 && rhs.lc_flags_ == 1 )
{
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_ );
return e1 < e2;
}
else
#endif
{
return lhs.category() < rhs.category() || (lhs.category() == rhs.category() && lhs.value() < rhs.value());
}
}
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( const error_code & lhs, const error_code & rhs ) BOOST_NOEXCEPT
{
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
{
return lhs == static_cast< std::error_code >( rhs );
}
inline friend bool operator==( error_code const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
{
return static_cast< std::error_code >( lhs ) == rhs;
}
inline friend bool operator!=( std::error_code const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( error_code const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
//
template<class E, class N = typename detail::enable_if<std::is_error_condition_enum<E>::value>::type>
inline friend bool operator==( error_code 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>
inline friend bool operator==( E lhs, error_code 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>
inline friend bool operator!=( error_code 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>
inline friend bool operator!=( E lhs, error_code 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>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( error_code 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>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( E lhs, error_code 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>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( error_code 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>
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( E lhs, error_code const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#if defined(BOOST_SYSTEM_CLANG_6)
inline friend bool operator==( error_code const & lhs, std::error_condition const & rhs ) BOOST_NOEXCEPT
{
return static_cast< std::error_code >( lhs ) == rhs;
}
inline friend bool operator==( std::error_condition const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
{
return lhs == static_cast< std::error_code >( rhs );
}
inline friend bool operator!=( error_code const & lhs, std::error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( std::error_condition const & lhs, error_code const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#endif
// conversions
operator std::error_code () const
{
if( lc_flags_ == 1 )
{
return *reinterpret_cast<std::error_code const*>( d2_ );
}
else if( lc_flags_ == 0 )
{
// This condition must be the same as the one in error_category_impl.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_SYSTEM_CATEGORY)
return std::error_code( 0, boost::system::system_category() );
#else
return std::error_code();
#endif
}
else
{
return std::error_code( d1_.val_, *d1_.cat_ );
}
}
operator std::error_code ()
{
return const_cast<error_code const&>( *this );
}
template<class T,
class E = typename detail::enable_if<detail::is_same<T, std::error_code>::value>::type>
operator T& ()
{
if( lc_flags_ != 1 )
{
std::error_code e2( *this );
::new( d2_ ) std::error_code( e2 );
lc_flags_ = 1;
}
return *reinterpret_cast<std::error_code*>( d2_ );
}
#if defined(BOOST_SYSTEM_CLANG_6)
template<class T,
class E = typename std::enable_if<std::is_same<T, std::error_code>::value>::type>
operator T const& () = delete;
#endif
#endif
std::string to_string() const
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( lc_flags_ == 1 )
{
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( d2_ );
std::string r( "std:" );
r += e2.category().name();
detail::append_int( r, e2.value() );
return r;
}
else
#endif
{
std::string r = category_name();
detail::append_int( r, value() );
return r;
}
}
template<class Ch, class Tr>
inline friend std::basic_ostream<Ch, Tr>&
operator<< (std::basic_ostream<Ch, Tr>& os, error_code const & ec)
{
return os << ec.to_string().c_str();
}
std::string what() const
{
std::string r = message();
r += " [";
r += to_string();
if( has_location() )
{
r += " at ";
r += location().to_string();
}
r += "]";
return r;
}
};
inline std::size_t hash_value( error_code const & ec )
{
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
if( ec.lc_flags_ == 1 )
{
std::error_code const& e2 = *reinterpret_cast<std::error_code const*>( ec.d2_ );
return std::hash<std::error_code>()( e2 );
}
#endif
error_category const & cat = ec.category();
boost::ulong_long_type id_ = cat.id_;
if( id_ == 0 )
{
id_ = reinterpret_cast<boost::uintptr_t>( &cat );
}
boost::ulong_long_type hv = ( boost::ulong_long_type( 0xCBF29CE4 ) << 32 ) + 0x84222325;
boost::ulong_long_type const prime = ( boost::ulong_long_type( 0x00000100 ) << 32 ) + 0x000001B3;
// id
hv ^= id_;
hv *= prime;
// value
hv ^= static_cast<unsigned>( ec.value() );
hv *= prime;
return static_cast<std::size_t>( hv );
}
} // namespace system
} // namespace boost
#if defined(BOOST_GCC) && BOOST_GCC >= 40600 && BOOST_GCC < 70000
# pragma GCC diagnostic pop
#endif
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CODE_HPP_INCLUDED

View File

@ -0,0 +1,297 @@
#ifndef BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017-2021
//
// 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/error_category.hpp>
#include <boost/system/detail/generic_category.hpp>
#include <boost/system/detail/enable_if.hpp>
#include <boost/system/detail/is_same.hpp>
#include <boost/system/detail/errc.hpp>
#include <boost/system/detail/append_int.hpp>
#include <boost/system/is_error_condition_enum.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace system
{
// class error_condition
// error_conditions are portable, error_codes are system or library specific
namespace detail
{
struct generic_value_tag
{
int value;
BOOST_SYSTEM_CONSTEXPR explicit generic_value_tag( int v ): value( v ) {}
};
} // namespace detail
class error_condition
{
private:
int val_;
error_category const * cat_;
private:
boost::ulong_long_type cat_id() const BOOST_NOEXCEPT
{
return cat_? cat_->id_: detail::generic_category_id;
}
public:
// constructors:
BOOST_SYSTEM_CONSTEXPR error_condition() BOOST_NOEXCEPT:
val_( 0 ), cat_( 0 )
{
}
BOOST_SYSTEM_CONSTEXPR error_condition( int val, const error_category & cat ) BOOST_NOEXCEPT:
val_( val ), cat_( &cat )
{
}
BOOST_SYSTEM_CONSTEXPR explicit error_condition( boost::system::detail::generic_value_tag vt ) BOOST_NOEXCEPT:
val_( vt.value ), cat_( 0 )
{
}
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
typename detail::enable_if<
is_error_condition_enum<ErrorConditionEnum>::value && !boost::system::detail::is_same<ErrorConditionEnum, errc::errc_t>::value
>::type* = 0) BOOST_NOEXCEPT
{
*this = make_error_condition( e );
}
template<class ErrorConditionEnum> BOOST_SYSTEM_CONSTEXPR error_condition( ErrorConditionEnum e,
typename detail::enable_if<boost::system::detail::is_same<ErrorConditionEnum, errc::errc_t>::value>::type* = 0) BOOST_NOEXCEPT:
val_( e ), cat_( 0 )
{
}
// modifiers:
BOOST_SYSTEM_CONSTEXPR void assign( int val, const error_category & cat ) BOOST_NOEXCEPT
{
val_ = val;
cat_ = &cat;
}
template<typename ErrorConditionEnum>
BOOST_SYSTEM_CONSTEXPR typename detail::enable_if<is_error_condition_enum<ErrorConditionEnum>::value, error_condition>::type &
operator=( ErrorConditionEnum val ) BOOST_NOEXCEPT
{
*this = error_condition( val );
return *this;
}
BOOST_SYSTEM_CONSTEXPR void clear() BOOST_NOEXCEPT
{
val_ = 0;
cat_ = 0;
}
// observers:
BOOST_SYSTEM_CONSTEXPR int value() const BOOST_NOEXCEPT
{
return val_;
}
BOOST_SYSTEM_CONSTEXPR const error_category & category() const BOOST_NOEXCEPT
{
return cat_? *cat_: generic_category();
}
std::string message() const
{
if( cat_ )
{
return cat_->message( value() );
}
else
{
return detail::generic_error_category_message( value() );
}
}
char const * message( char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
if( cat_ )
{
return cat_->message( value(), buffer, len );
}
else
{
return detail::generic_error_category_message( value(), buffer, len );
}
}
BOOST_SYSTEM_CONSTEXPR bool failed() const BOOST_NOEXCEPT
{
if( cat_ )
{
return detail::failed_impl( val_, *cat_ );
}
else
{
return val_ != 0;
}
}
#if !defined(BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS)
BOOST_SYSTEM_CONSTEXPR explicit operator bool() const BOOST_NOEXCEPT // true if error
{
return failed();
}
#else
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
BOOST_SYSTEM_CONSTEXPR operator unspecified_bool_type() const BOOST_NOEXCEPT // true if error
{
return failed()? unspecified_bool_true: 0;
}
BOOST_SYSTEM_CONSTEXPR bool operator!() const BOOST_NOEXCEPT // true if no error
{
return !failed();
}
#endif
// relationals:
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
BOOST_SYSTEM_CONSTEXPR inline friend bool operator==( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
if( lhs.val_ != rhs.val_ )
{
return false;
}
else if( lhs.cat_ == 0 )
{
return rhs.cat_id() == detail::generic_category_id;
}
else if( rhs.cat_ == 0 )
{
return lhs.cat_id() == detail::generic_category_id;
}
else
{
return *lhs.cat_ == *rhs.cat_;
}
}
BOOST_SYSTEM_CONSTEXPR inline friend bool operator<( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
error_category const& lcat = lhs.category();
error_category const& rcat = rhs.category();
return lcat < rcat || ( lcat == rcat && lhs.val_ < rhs.val_ );
}
BOOST_SYSTEM_CONSTEXPR inline friend bool operator!=( const error_condition & lhs, const error_condition & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
operator std::error_condition () const
{
// This condition must be the same as the one in error_category_impl.hpp
#if defined(BOOST_SYSTEM_AVOID_STD_GENERIC_CATEGORY)
return std::error_condition( value(), category() );
#else
if( cat_ )
{
return std::error_condition( val_, *cat_ );
}
else
{
return std::error_condition( val_, std::generic_category() );
}
#endif
}
inline friend bool operator==( std::error_code const & lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return lhs == static_cast< std::error_condition >( rhs );
}
inline friend bool operator==( error_condition const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
{
return static_cast< std::error_condition >( lhs ) == rhs;
}
inline friend bool operator!=( std::error_code const & lhs, error_condition const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
inline friend bool operator!=( error_condition const & lhs, std::error_code const & rhs ) BOOST_NOEXCEPT
{
return !( lhs == rhs );
}
#endif
std::string to_string() const
{
std::string r( "cond:" );
if( cat_ )
{
r += cat_->name();
}
else
{
r += "generic";
}
detail::append_int( r, value() );
return r;
}
template<class Ch, class Tr>
inline friend std::basic_ostream<Ch, Tr>&
operator<< (std::basic_ostream<Ch, Tr>& os, error_condition const & en)
{
os << en.to_string();
return os;
}
};
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_ERROR_CONDITION_HPP_INCLUDED

View File

@ -0,0 +1,123 @@
#ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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/error_category.hpp>
#include <boost/system/detail/generic_category_message.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace system
{
namespace detail
{
// generic_error_category
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
class BOOST_SYMBOL_VISIBLE generic_error_category: public error_category
{
public:
BOOST_SYSTEM_CONSTEXPR generic_error_category() BOOST_NOEXCEPT:
error_category( detail::generic_category_id )
{
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
{
return "generic";
}
std::string message( int ev ) const BOOST_OVERRIDE;
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
};
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif
// generic_error_category::message
inline char const * generic_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
return generic_error_category_message( ev, buffer, len );
}
inline std::string generic_error_category::message( int ev ) const
{
return generic_error_category_message( ev );
}
} // namespace detail
// generic_category()
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
namespace detail
{
template<class T> struct BOOST_SYMBOL_VISIBLE generic_cat_holder
{
static constexpr generic_error_category instance{};
};
// Before C++17 it was mandatory to redeclare all static constexpr
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template<class T> constexpr generic_error_category generic_cat_holder<T>::instance;
#endif
} // namespace detail
constexpr error_category const & generic_category() BOOST_NOEXCEPT
{
return detail::generic_cat_holder<void>::instance;
}
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
#if !defined(__SUNPRO_CC) // trailing __global is not supported
inline error_category const & generic_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
#endif
inline error_category const & generic_category() BOOST_NOEXCEPT
{
static const detail::generic_error_category instance;
return instance;
}
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
// deprecated synonyms
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
BOOST_SYSTEM_DEPRECATED("please use generic_category()") inline const error_category & get_generic_category() { return generic_category(); }
BOOST_SYSTEM_DEPRECATED("please use generic_category()") inline const error_category & get_posix_category() { return generic_category(); }
BOOST_SYSTEM_DEPRECATED("please use generic_category()") static const error_category & posix_category BOOST_ATTRIBUTE_UNUSED = generic_category();
BOOST_SYSTEM_DEPRECATED("please use generic_category()") static const error_category & errno_ecat BOOST_ATTRIBUTE_UNUSED = generic_category();
#endif
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_HPP_INCLUDED

View File

@ -0,0 +1,108 @@
#ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED
// Implementation of generic_error_category_message
//
// Copyright 2018 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/config.hpp>
#include <string>
#include <cstring>
namespace boost
{
namespace system
{
namespace detail
{
#if defined(__GLIBC__)
// glibc has two incompatible strerror_r definitions
inline char const * strerror_r_helper( char const * r, char const * ) BOOST_NOEXCEPT
{
return r;
}
inline char const * strerror_r_helper( int r, char const * buffer ) BOOST_NOEXCEPT
{
return r == 0? buffer: "Unknown error";
}
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
{
return strerror_r_helper( strerror_r( ev, buffer, len ), buffer );
}
inline std::string generic_error_category_message( int ev )
{
char buffer[ 128 ];
return generic_error_category_message( ev, buffer, sizeof( buffer ) );
}
#else // #if defined(__GLIBC__)
// std::strerror is thread-safe on everything else, incl. Windows
# if defined( BOOST_MSVC )
# pragma warning( push )
# pragma warning( disable: 4996 )
# elif defined(__clang__) && defined(__has_warning)
# pragma clang diagnostic push
# if __has_warning("-Wdeprecated-declarations")
# pragma clang diagnostic ignored "-Wdeprecated-declarations"
# endif
# endif
inline std::string generic_error_category_message( int ev )
{
char const * m = std::strerror( ev );
return m? m: "Unknown error";
}
inline char const * generic_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
{
if( len == 0 )
{
return buffer;
}
if( len == 1 )
{
buffer[0] = 0;
return buffer;
}
char const * m = std::strerror( ev );
if( m == 0 ) return "Unknown error";
std::strncpy( buffer, m, len - 1 );
buffer[ len-1 ] = 0;
return buffer;
}
# if defined( BOOST_MSVC )
# pragma warning( pop )
# elif defined(__clang__) && defined(__has_warning)
# pragma clang diagnostic pop
# endif
#endif // #if defined(__GLIBC__)
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_GENERIC_CATEGORY_MESSAGE_HPP_INCLUDED

View File

@ -0,0 +1,107 @@
#ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018, 2021
//
// 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/error_category.hpp>
#include <boost/system/detail/snprintf.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace system
{
namespace detail
{
// interop_error_category, used for std::error_code
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
class BOOST_SYMBOL_VISIBLE interop_error_category: public error_category
{
public:
BOOST_SYSTEM_CONSTEXPR interop_error_category() BOOST_NOEXCEPT:
error_category( detail::interop_category_id )
{
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
{
return "std:unknown";
}
std::string message( int ev ) const BOOST_OVERRIDE;
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
};
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif
inline char const * interop_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
detail::snprintf( buffer, len, "Unknown interop error %d", ev );
return buffer;
}
inline std::string interop_error_category::message( int ev ) const
{
char buffer[ 48 ];
return message( ev, buffer, sizeof( buffer ) );
}
// interop_category()
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
template<class T> struct BOOST_SYMBOL_VISIBLE interop_cat_holder
{
static constexpr interop_error_category instance{};
};
// Before C++17 it was mandatory to redeclare all static constexpr
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template<class T> constexpr interop_error_category interop_cat_holder<T>::instance;
#endif
constexpr error_category const & interop_category() BOOST_NOEXCEPT
{
return interop_cat_holder<void>::instance;
}
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
#if !defined(__SUNPRO_CC) // trailing __global is not supported
inline error_category const & interop_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
#endif
inline error_category const & interop_category() BOOST_NOEXCEPT
{
static const detail::interop_error_category instance;
return instance;
}
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_INTEROP_CATEGORY_HPP_INCLUDED

View File

@ -0,0 +1,33 @@
#ifndef BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED
// Copyright 2021 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
namespace boost
{
namespace system
{
namespace detail
{
template<class T1, class T2> struct is_same
{
enum _vt { value = 0 };
};
template<class T> struct is_same<T, T>
{
enum _vt { value = 1 };
};
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_IS_SAME_HPP_INCLUDED

View File

@ -0,0 +1,73 @@
#ifndef BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED
// Copyright 2018, 2020, 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/config.hpp>
#include <cstdio>
#include <cstdarg>
//
namespace boost
{
namespace system
{
namespace detail
{
#if ( defined(_MSC_VER) && _MSC_VER < 1900 ) || ( defined(__MINGW32__) && !defined(__MINGW64_VERSION_MAJOR) )
inline void snprintf( char * buffer, std::size_t len, char const * format, ... )
{
# if defined( BOOST_MSVC )
# pragma warning( push )
# pragma warning( disable: 4996 )
# endif
if( len == 0 ) return;
va_list args;
va_start( args, format );
_vsnprintf( buffer, len - 1, format, args );
buffer[ len - 1 ] = 0;
va_end( args );
# if defined( BOOST_MSVC )
# pragma warning( pop )
# endif
}
#else
#if defined(__GNUC__) && __GNUC__ >= 3
__attribute__((__format__ (__printf__, 3, 4)))
#endif
inline void snprintf( char * buffer, std::size_t len, char const * format, ... )
{
va_list args;
va_start( args, format );
std::vsnprintf( buffer, len, format, args );
va_end( args );
}
#endif
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_SNPRINTF_HPP_INCLUDED

View File

@ -0,0 +1,83 @@
#ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_STD_CATEGORY_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/error_category.hpp>
#include <system_error>
//
namespace boost
{
namespace system
{
namespace detail
{
class BOOST_SYMBOL_VISIBLE std_category: public std::error_category
{
private:
boost::system::error_category const * pc_;
public:
boost::system::error_category const & original_category() const BOOST_NOEXCEPT
{
return *pc_;
}
public:
explicit std_category( boost::system::error_category const * pc, unsigned id ): pc_( pc )
{
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
_Addr = id;
#endif
}
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
{
return pc_->name();
}
std::string message( int ev ) const BOOST_OVERRIDE
{
return pc_->message( ev );
}
std::error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE
{
return pc_->default_error_condition( ev );
}
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;
};
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_STD_CATEGORY_HPP_INCLUDED

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

@ -0,0 +1,110 @@
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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/error_category.hpp>
#include <boost/system/detail/config.hpp>
#include <boost/config.hpp>
namespace boost
{
namespace system
{
namespace detail
{
// system_error_category
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor"
#endif
class BOOST_SYMBOL_VISIBLE system_error_category: public error_category
{
public:
BOOST_SYSTEM_CONSTEXPR system_error_category() BOOST_NOEXCEPT:
error_category( detail::system_category_id )
{
}
const char * name() const BOOST_NOEXCEPT BOOST_OVERRIDE
{
return "system";
}
error_condition default_error_condition( int ev ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
std::string message( int ev ) const BOOST_OVERRIDE;
char const * message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT BOOST_OVERRIDE;
};
#if ( defined( BOOST_GCC ) && BOOST_GCC >= 40600 ) || defined( BOOST_CLANG )
#pragma GCC diagnostic pop
#endif
} // namespace detail
// system_category()
#if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
namespace detail
{
template<class T> struct BOOST_SYMBOL_VISIBLE system_cat_holder
{
static constexpr system_error_category instance{};
};
// Before C++17 it was mandatory to redeclare all static constexpr
#if defined(BOOST_NO_CXX17_INLINE_VARIABLES)
template<class T> constexpr system_error_category system_cat_holder<T>::instance;
#endif
} // namespace detail
constexpr error_category const & system_category() BOOST_NOEXCEPT
{
return detail::system_cat_holder<void>::instance;
}
#else // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
#if !defined(__SUNPRO_CC) // trailing __global is not supported
inline error_category const & system_category() BOOST_NOEXCEPT BOOST_SYMBOL_VISIBLE;
#endif
inline error_category const & system_category() BOOST_NOEXCEPT
{
static const detail::system_error_category instance;
return instance;
}
#endif // #if defined(BOOST_SYSTEM_HAS_CONSTEXPR)
// deprecated synonyms
#ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
BOOST_SYSTEM_DEPRECATED("please use system_category()") inline const error_category & get_system_category() { return system_category(); }
BOOST_SYSTEM_DEPRECATED("please use system_category()") static const error_category & native_ecat BOOST_ATTRIBUTE_UNUSED = system_category();
#endif
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_HPP_INCLUDED

View File

@ -0,0 +1,151 @@
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED
// Copyright Beman Dawes 2002, 2006
// Copyright (c) Microsoft Corporation 2014
// Copyright 2018 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/errc.hpp>
#include <boost/winapi/error_codes.hpp>
#include <boost/config.hpp>
//
namespace boost
{
namespace system
{
namespace detail
{
inline int system_category_condition_win32( int ev ) BOOST_NOEXCEPT
{
// When using the Windows Runtime, most system errors are reported as HRESULTs.
// We want to map the common Win32 errors to their equivalent error condition,
// whether or not they are reported via an HRESULT.
#define BOOST_SYSTEM_FAILED(hr) ((hr) < 0)
#define BOOST_SYSTEM_HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
#define BOOST_SYSTEM_HRESULT_CODE(hr) ((hr) & 0xFFFF)
#define BOOST_SYSTEM_FACILITY_WIN32 7
if( BOOST_SYSTEM_FAILED( ev ) && BOOST_SYSTEM_HRESULT_FACILITY( ev ) == BOOST_SYSTEM_FACILITY_WIN32 )
{
ev = BOOST_SYSTEM_HRESULT_CODE( ev );
}
#undef BOOST_SYSTEM_FAILED
#undef BOOST_SYSTEM_HRESULT_FACILITY
#undef BOOST_SYSTEM_HRESULT_CODE
#undef BOOST_SYSTEM_FACILITY_WIN32
using namespace boost::winapi;
using namespace errc;
// Windows system -> posix_errno decode table
// see WinError.h comments for descriptions of errors
switch ( ev )
{
case 0: return success;
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_UNIT_: return no_such_device;
case ERROR_BROKEN_PIPE_: return broken_pipe;
case ERROR_BUFFER_OVERFLOW_: return filename_too_long;
case ERROR_BUSY_: return device_or_resource_busy;
case ERROR_BUSY_DRIVE_: return device_or_resource_busy;
case ERROR_CANNOT_MAKE_: return permission_denied;
case ERROR_CANTOPEN_: return io_error;
case ERROR_CANTREAD_: return io_error;
case ERROR_CANTWRITE_: return io_error;
case ERROR_CONNECTION_ABORTED_: return connection_aborted;
case ERROR_CURRENT_DIRECTORY_: return permission_denied;
case ERROR_DEV_NOT_EXIST_: return no_such_device;
case ERROR_DEVICE_IN_USE_: return device_or_resource_busy;
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_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;
case ERROR_INVALID_ACCESS_: return permission_denied;
case ERROR_INVALID_DRIVE_: return no_such_device;
case ERROR_INVALID_FUNCTION_: return function_not_supported;
case ERROR_INVALID_HANDLE_: return invalid_argument;
case ERROR_INVALID_NAME_: return no_such_file_or_directory;
case ERROR_INVALID_PARAMETER_: return invalid_argument;
case ERROR_LOCK_VIOLATION_: return no_lock_available;
case ERROR_LOCKED_: return no_lock_available;
case ERROR_NEGATIVE_SEEK_: return invalid_argument;
case ERROR_NOACCESS_: return permission_denied;
case ERROR_NOT_ENOUGH_MEMORY_: return not_enough_memory;
case ERROR_NOT_READY_: return resource_unavailable_try_again;
case ERROR_NOT_SAME_DEVICE_: return cross_device_link;
case ERROR_OPEN_FAILED_: return io_error;
case ERROR_OPEN_FILES_: return device_or_resource_busy;
case ERROR_OPERATION_ABORTED_: return operation_canceled;
case ERROR_OUTOFMEMORY_: return not_enough_memory;
case ERROR_PATH_NOT_FOUND_: return no_such_file_or_directory;
case ERROR_READ_FAULT_: return io_error;
case ERROR_REPARSE_TAG_INVALID_: return invalid_argument;
case ERROR_RETRY_: return resource_unavailable_try_again;
case ERROR_SEEK_: return io_error;
case ERROR_SHARING_VIOLATION_: return permission_denied;
case ERROR_NOT_SUPPORTED_: return not_supported; // WinError.h: "The request is not supported."
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 WSAEACCES_: return permission_denied;
case WSAEADDRINUSE_: return address_in_use;
case WSAEADDRNOTAVAIL_: return address_not_available;
case WSAEAFNOSUPPORT_: return address_family_not_supported;
case WSAEALREADY_: return connection_already_in_progress;
case WSAEBADF_: return bad_file_descriptor;
case WSAECONNABORTED_: return connection_aborted;
case WSAECONNREFUSED_: return connection_refused;
case WSAECONNRESET_: return connection_reset;
case WSAEDESTADDRREQ_: return destination_address_required;
case WSAEFAULT_: return bad_address;
case WSAEHOSTUNREACH_: return host_unreachable;
case WSAEINPROGRESS_: return operation_in_progress;
case WSAEINTR_: return interrupted;
case WSAEINVAL_: return invalid_argument;
case WSAEISCONN_: return already_connected;
case WSAEMFILE_: return too_many_files_open;
case WSAEMSGSIZE_: return message_size;
case WSAENAMETOOLONG_: return filename_too_long;
case WSAENETDOWN_: return network_down;
case WSAENETRESET_: return network_reset;
case WSAENETUNREACH_: return network_unreachable;
case WSAENOBUFS_: return no_buffer_space;
case WSAENOPROTOOPT_: return no_protocol_option;
case WSAENOTCONN_: return not_connected;
case WSAENOTSOCK_: return not_a_socket;
case WSAEOPNOTSUPP_: return operation_not_supported;
case WSAEPROTONOSUPPORT_: return protocol_not_supported;
case WSAEPROTOTYPE_: return wrong_protocol_type;
case WSAETIMEDOUT_: return timed_out;
case WSAEWOULDBLOCK_: return operation_would_block;
default: return -1;
}
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_CONDITION_WIN32_HPP_INCLUDED

View File

@ -0,0 +1,61 @@
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018, 2020
//
// 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/system_category.hpp>
#include <boost/system/detail/system_category_message.hpp>
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/api_config.hpp>
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
#endif
// system_error_category implementation
#if defined(BOOST_WINDOWS_API)
#include <boost/system/detail/system_category_condition_win32.hpp>
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
{
int e2 = system_category_condition_win32( ev );
if( e2 == -1 )
{
return error_condition( ev, *this );
}
else
{
return error_condition( boost::system::detail::generic_value_tag( e2 ) );
}
}
#else // #if defined(BOOST_WINDOWS_API)
inline boost::system::error_condition boost::system::detail::system_error_category::default_error_condition( int ev ) const BOOST_NOEXCEPT
{
return error_condition( boost::system::detail::generic_value_tag( ev ) );
}
#endif // #if defined(BOOST_WINDOWS_API)
inline std::string boost::system::detail::system_error_category::message( int ev ) const
{
return system_error_category_message( ev );
}
inline char const * boost::system::detail::system_error_category::message( int ev, char * buffer, std::size_t len ) const BOOST_NOEXCEPT
{
return system_error_category_message( ev, buffer, len );
}
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_IMPL_HPP_INCLUDED

View File

@ -0,0 +1,71 @@
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_HPP_INCLUDED
// Implementation of system_error_category_message
//
// Copyright 2018, 2022 Peter Dimov
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/api_config.hpp>
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
#endif
#if defined(BOOST_WINDOWS_API)
#include <boost/system/detail/system_category_message_win32.hpp>
namespace boost
{
namespace system
{
namespace detail
{
inline std::string system_error_category_message( int ev )
{
return system_category_message_win32( ev );
}
inline char const * system_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
{
return system_category_message_win32( ev, buffer, len );
}
} // namespace detail
} // namespace system
} // namespace boost
#else // #if defined(BOOST_WINDOWS_API)
#include <boost/system/detail/generic_category_message.hpp>
namespace boost
{
namespace system
{
namespace detail
{
inline std::string system_error_category_message( int ev )
{
return generic_error_category_message( ev );
}
inline char const * system_error_category_message( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
{
return generic_error_category_message( ev, buffer, len );
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #if defined(BOOST_WINDOWS_API)
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_HPP_INCLUDED

View File

@ -0,0 +1,211 @@
#ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED
// Copyright Beman Dawes 2002, 2006
// Copyright (c) Microsoft Corporation 2014
// Copyright 2018, 2020 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/snprintf.hpp>
#include <boost/winapi/error_handling.hpp>
#include <boost/winapi/character_code_conversion.hpp>
#include <boost/winapi/local_memory.hpp>
#include <boost/config.hpp>
#include <cstdio>
//
namespace boost
{
namespace system
{
namespace detail
{
inline char const * unknown_message_win32( int ev, char * buffer, std::size_t len )
{
detail::snprintf( buffer, len, "Unknown error (%d)", ev );
return buffer;
}
inline boost::winapi::UINT_ message_cp_win32()
{
#if defined(BOOST_SYSTEM_USE_UTF8)
return boost::winapi::CP_UTF8_;
#else
return boost::winapi::CP_ACP_;
#endif
}
inline char const * system_category_message_win32( int ev, char * buffer, std::size_t len ) BOOST_NOEXCEPT
{
if( len == 0 )
{
return buffer;
}
if( len == 1 )
{
buffer[0] = 0;
return buffer;
}
boost::winapi::UINT_ const code_page = message_cp_win32();
int r = 0;
#if !defined(BOOST_NO_ANSI_APIS)
if( code_page == boost::winapi::CP_ACP_ )
{
using namespace boost::winapi;
DWORD_ retval = boost::winapi::FormatMessageA(
FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
NULL,
ev,
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
buffer,
static_cast<DWORD_>( len ),
NULL
);
r = static_cast<int>( retval );
}
else
#endif
{
using namespace boost::winapi;
wchar_t * lpMsgBuf = 0;
DWORD_ retval = boost::winapi::FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
NULL,
ev,
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
(LPWSTR_) &lpMsgBuf,
0,
NULL
);
if( retval != 0 )
{
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, buffer, static_cast<int>( len ), NULL, NULL );
boost::winapi::LocalFree( lpMsgBuf );
if ( r != 0 ) --r; // exclude null terminator
}
}
if( r == 0 )
{
return unknown_message_win32( ev, buffer, len );
}
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
{
buffer[ --r ] = 0;
}
if( r > 0 && buffer[ r-1 ] == '.' )
{
buffer[ --r ] = 0;
}
return buffer;
}
struct local_free
{
void * p_;
~local_free()
{
boost::winapi::LocalFree( p_ );
}
};
inline std::string unknown_message_win32( int ev )
{
char buffer[ 38 ];
return unknown_message_win32( ev, buffer, sizeof( buffer ) );
}
inline std::string system_category_message_win32( int ev )
{
using namespace boost::winapi;
wchar_t * lpMsgBuf = 0;
DWORD_ retval = boost::winapi::FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER_ | FORMAT_MESSAGE_FROM_SYSTEM_ | FORMAT_MESSAGE_IGNORE_INSERTS_,
NULL,
ev,
MAKELANGID_( LANG_NEUTRAL_, SUBLANG_DEFAULT_ ), // Default language
(LPWSTR_) &lpMsgBuf,
0,
NULL
);
if( retval == 0 )
{
return unknown_message_win32( ev );
}
local_free lf_ = { lpMsgBuf };
(void)lf_;
UINT_ const code_page = message_cp_win32();
int r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, 0, 0, NULL, NULL );
if( r == 0 )
{
return unknown_message_win32( ev );
}
std::string buffer( r, char() );
r = boost::winapi::WideCharToMultiByte( code_page, 0, lpMsgBuf, -1, &buffer[0], r, NULL, NULL );
if( r == 0 )
{
return unknown_message_win32( ev );
}
--r; // exclude null terminator
while( r > 0 && ( buffer[ r-1 ] == '\n' || buffer[ r-1 ] == '\r' ) )
{
--r;
}
if( r > 0 && buffer[ r-1 ] == '.' )
{
--r;
}
buffer.resize( r );
return buffer;
}
} // namespace detail
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_SYSTEM_CATEGORY_MESSAGE_WIN32_HPP_INCLUDED

View File

@ -0,0 +1,59 @@
#ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
#define BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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
namespace boost
{
namespace system
{
class error_code;
} // namespace system
// boost::throws()
namespace detail
{
// Misuse of the error_code object is turned into a noisy failure by
// poisoning the reference. This particular implementation doesn't
// produce warnings or errors from popular compilers, is very efficient
// (as determined by inspecting generated code), and does not suffer
// from order of initialization problems. In practice, it also seems
// cause user function error handling implementation errors to be detected
// very early in the development cycle.
inline system::error_code* throws()
{
// See github.com/boostorg/system/pull/12 by visigoth for why the return
// is poisoned with nonzero rather than (0). A test, test_throws_usage(),
// has been added to error_code_test.cpp, and as visigoth mentioned it
// fails on clang for release builds with a return of 0 but works fine
// with (1).
// Since the undefined behavior sanitizer (-fsanitize=undefined) does not
// allow a reference to be formed to the unaligned address of (1), we use
// (8) instead.
return reinterpret_cast<system::error_code*>(8);
}
} // namespace detail
inline system::error_code& throws()
{
return *detail::throws();
}
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_DETAIL_THROWS_HPP_INCLUDED

View File

@ -0,0 +1,57 @@
#ifndef BOOST_SYSTEM_ERRC_HPP_INCLUDED
#define BOOST_SYSTEM_ERRC_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018, 2020
//
// 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/errc.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/error_condition.hpp>
#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
{
namespace system
{
// make_* functions for errc::errc_t
namespace errc
{
// explicit conversion:
BOOST_SYSTEM_CONSTEXPR inline error_code make_error_code( errc_t e ) BOOST_NOEXCEPT
{
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
{
return error_condition( e, generic_category() );
}
} // namespace errc
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_ERRC_HPP_INCLUDED

View File

@ -0,0 +1,13 @@
#ifndef BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/error_category.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#endif // #ifndef BOOST_SYSTEM_ERROR_CATEGORY_HPP_INCLUDED

View File

@ -1,513 +1,21 @@
// boost/system/error_code.hpp ---------------------------------------------//
#ifndef BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
#define BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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
#ifndef BOOST_ERROR_CODE_HPP
#define BOOST_ERROR_CODE_HPP
#include <boost/system/config.hpp>
#include <boost/cstdint.hpp>
#include <boost/assert.hpp>
#include <boost/operators.hpp>
#include <boost/noncopyable.hpp>
#include <boost/utility/enable_if.hpp>
#include <ostream>
#include <string>
#include <stdexcept>
#include <functional>
// TODO: undef these macros if not already defined
#include <boost/cerrno.hpp>
#if !defined(BOOST_POSIX_API) && !defined(BOOST_WINDOWS_API)
# error BOOST_POSIX_API or BOOST_WINDOWS_API must be defined
#endif
#include <boost/config/abi_prefix.hpp> // must be the last #include
namespace boost
{
namespace system
{
class error_code;
class error_condition;
// "Concept" helpers ---------------------------------------------------//
template< class T >
struct is_error_code_enum { static const bool value = false; };
template< class T >
struct is_error_condition_enum { static const bool value = false; };
// generic error_conditions --------------------------------------------//
namespace errc
{
enum errc_t
{
success = 0,
address_family_not_supported = EAFNOSUPPORT,
address_in_use = EADDRINUSE,
address_not_available = EADDRNOTAVAIL,
already_connected = EISCONN,
argument_list_too_long = E2BIG,
argument_out_of_domain = EDOM,
bad_address = EFAULT,
bad_file_descriptor = EBADF,
bad_message = EBADMSG,
broken_pipe = EPIPE,
connection_aborted = ECONNABORTED,
connection_already_in_progress = EALREADY,
connection_refused = ECONNREFUSED,
connection_reset = ECONNRESET,
cross_device_link = EXDEV,
destination_address_required = EDESTADDRREQ,
device_or_resource_busy = EBUSY,
directory_not_empty = ENOTEMPTY,
executable_format_error = ENOEXEC,
file_exists = EEXIST,
file_too_large = EFBIG,
filename_too_long = ENAMETOOLONG,
function_not_supported = ENOSYS,
host_unreachable = EHOSTUNREACH,
identifier_removed = EIDRM,
illegal_byte_sequence = EILSEQ,
inappropriate_io_control_operation = ENOTTY,
interrupted = EINTR,
invalid_argument = EINVAL,
invalid_seek = ESPIPE,
io_error = EIO,
is_a_directory = EISDIR,
message_size = EMSGSIZE,
network_down = ENETDOWN,
network_reset = ENETRESET,
network_unreachable = ENETUNREACH,
no_buffer_space = ENOBUFS,
no_child_process = ECHILD,
no_link = ENOLINK,
no_lock_available = ENOLCK,
no_message_available = ENODATA,
no_message = ENOMSG,
no_protocol_option = ENOPROTOOPT,
no_space_on_device = ENOSPC,
no_stream_resources = ENOSR,
no_such_device_or_address = ENXIO,
no_such_device = ENODEV,
no_such_file_or_directory = ENOENT,
no_such_process = ESRCH,
not_a_directory = ENOTDIR,
not_a_socket = ENOTSOCK,
not_a_stream = ENOSTR,
not_connected = ENOTCONN,
not_enough_memory = ENOMEM,
not_supported = ENOTSUP,
operation_canceled = ECANCELED,
operation_in_progress = EINPROGRESS,
operation_not_permitted = EPERM,
operation_not_supported = EOPNOTSUPP,
operation_would_block = EWOULDBLOCK,
owner_dead = EOWNERDEAD,
permission_denied = EACCES,
protocol_error = EPROTO,
protocol_not_supported = EPROTONOSUPPORT,
read_only_file_system = EROFS,
resource_deadlock_would_occur = EDEADLK,
resource_unavailable_try_again = EAGAIN,
result_out_of_range = ERANGE,
state_not_recoverable = ENOTRECOVERABLE,
stream_timeout = ETIME,
text_file_busy = ETXTBSY,
timed_out = ETIMEDOUT,
too_many_files_open_in_system = ENFILE,
too_many_files_open = EMFILE,
too_many_links = EMLINK,
too_many_synbolic_link_levels = ELOOP,
value_too_large = EOVERFLOW,
wrong_protocol_type = EPROTOTYPE
};
} // namespace errc
# ifndef BOOST_SYSTEM_NO_DEPRECATED
namespace posix = errc;
namespace posix_error = errc;
# endif
template<> struct is_error_condition_enum<errc::errc_t>
{ static const bool value = true; };
// ----------------------------------------------------------------------//
// Operating system specific interfaces --------------------------------//
// The interface is divided into general and system-specific portions to
// meet these requirements:
//
// * Code calling an operating system API can create an error_code with
// a single category (system_category), even for POSIX-like operating
// systems that return some POSIX errno values and some native errno
// values. This code should not have to pay the cost of distinguishing
// between categories, since it is not yet known if that is needed.
//
// * Users wishing to write system-specific code should be given enums for
// at least the common error cases.
//
// * System specific code should fail at compile time if moved to another
// operating system.
// The system specific portions of the interface are located in headers
// with names reflecting the operating system. For example,
//
// <boost/system/cygwin_error.hpp>
// <boost/system/linux_error.hpp>
// <boost/system/windows_error.hpp>
//
// These headers are effectively empty for compiles on operating systems
// where they are not applicable.
// ----------------------------------------------------------------------//
// class error_category ------------------------------------------------//
class error_category : public noncopyable
{
public:
virtual ~error_category(){}
virtual const char * name() const = 0;
virtual std::string message( int ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const;
virtual bool equivalent( int code,
const error_condition & condition ) const;
virtual bool equivalent( const error_code & code,
int condition ) const;
bool operator==(const error_category & rhs) const { return this == &rhs; }
bool operator!=(const error_category & rhs) const { return this != &rhs; }
bool operator<( const error_category & rhs ) const
{
return std::less<const error_category*>()( this, &rhs );
}
};
// predefined error categories -----------------------------------------//
BOOST_SYSTEM_DECL const error_category & get_system_category();
BOOST_SYSTEM_DECL const error_category & get_generic_category();
static const error_category & system_category = get_system_category();
static const error_category & generic_category = get_generic_category();
# ifndef BOOST_SYSTEM_NO_DEPRECATED
// deprecated synonyms
inline const error_category & get_posix_category() { return get_generic_category(); }
static const error_category & posix_category = get_generic_category();
static const error_category & errno_ecat = get_generic_category();
static const error_category & native_ecat = get_system_category();
# endif
// class error_condition -----------------------------------------------//
// error_conditions are portable, error_codes are system or library specific
class error_condition
{
public:
// constructors:
error_condition() : m_val(0), m_cat(&get_generic_category()) {}
error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template <class ErrorConditionEnum>
error_condition(ErrorConditionEnum e,
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0)
{
*this = make_error_condition(e);
}
// modifiers:
void assign( int val, const error_category & cat )
{
m_val = val;
m_cat = &cat;
}
template<typename ErrorConditionEnum>
typename boost::enable_if<is_error_condition_enum<ErrorConditionEnum>, error_condition>::type &
operator=( ErrorConditionEnum val )
{
*this = make_error_condition(val);
return *this;
}
void clear()
{
m_val = 0;
m_cat = &get_generic_category();
}
// observers:
int value() const { return m_val; }
const error_category & category() const { return *m_cat; }
std::string message() const { return m_cat->message(value()); }
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error
{
return m_val == 0 ? 0 : unspecified_bool_true;
}
bool operator!() const // true if no error
{
return m_val == 0;
}
// relationals:
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
inline friend bool operator==( const error_condition & lhs,
const error_condition & rhs )
{
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
}
inline friend bool operator<( const error_condition & lhs,
const error_condition & rhs )
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
{
return lhs.m_cat < rhs.m_cat
|| (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
}
private:
int m_val;
const error_category * m_cat;
};
// class error_code ----------------------------------------------------//
// We want error_code to be a value type that can be copied without slicing
// and without requiring heap allocation, but we also want it to have
// polymorphic behavior based on the error category. This is achieved by
// abstract base class error_category supplying the polymorphic behavior,
// and error_code containing a pointer to an object of a type derived
// from error_category.
class error_code
{
public:
// constructors:
error_code() : m_val(0), m_cat(&get_system_category()) {}
error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {}
template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e,
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0)
{
*this = make_error_code(e);
}
// modifiers:
void assign( int val, const error_category & cat )
{
m_val = val;
m_cat = &cat;
}
template<typename ErrorCodeEnum>
typename boost::enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
operator=( ErrorCodeEnum val )
{
*this = make_error_code(val);
return *this;
}
void clear()
{
m_val = 0;
m_cat = &get_system_category();
}
// observers:
int value() const { return m_val; }
const error_category & category() const { return *m_cat; }
error_condition default_error_condition() const { return m_cat->default_error_condition(value()); }
std::string message() const { return m_cat->message(value()); }
typedef void (*unspecified_bool_type)();
static void unspecified_bool_true() {}
operator unspecified_bool_type() const // true if error
{
return m_val == 0 ? 0 : unspecified_bool_true;
}
bool operator!() const // true if no error
{
return m_val == 0;
}
// relationals:
inline friend bool operator==( const error_code & lhs,
const error_code & rhs )
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
{
return lhs.m_cat == rhs.m_cat && lhs.m_val == rhs.m_val;
}
inline friend bool operator<( const error_code & lhs,
const error_code & rhs )
// the more symmetrical non-member syntax allows enum
// conversions work for both rhs and lhs.
{
return lhs.m_cat < rhs.m_cat
|| (lhs.m_cat == rhs.m_cat && lhs.m_val < rhs.m_val);
}
private:
int m_val;
const error_category * m_cat;
};
// predefined error_code object used as "throw on error" tag
# ifndef BOOST_SYSTEM_NO_DEPRECATED
BOOST_SYSTEM_DECL extern error_code throws;
# endif
// Moving from a "throws" object to a "throws" function without breaking
// existing code is a bit of a problem. The workaround is to place the
// "throws" function in namespace boost rather than namespace boost::system.
} // namespace system
namespace detail { inline system::error_code * throws() { return 0; } }
// Misuse of the error_code object is turned into a noisy failure by
// poisoning the reference. This particular implementation doesn't
// produce warnings or errors from popular compilers, is very efficient
// (as determined by inspecting generated code), and does not suffer
// from order of initialization problems. In practice, it also seems
// cause user function error handling implementation errors to be detected
// very early in the development cycle.
inline system::error_code & throws()
{ return *detail::throws(); }
namespace system
{
// non-member functions ------------------------------------------------//
inline bool operator!=( const error_code & lhs,
const error_code & rhs )
{
return !(lhs == rhs);
}
inline bool operator!=( const error_condition & lhs,
const error_condition & rhs )
{
return !(lhs == rhs);
}
inline bool operator==( const error_code & code,
const error_condition & condition )
{
return code.category().equivalent( code.value(), condition )
|| condition.category().equivalent( code, condition.value() );
}
inline bool operator!=( const error_code & lhs,
const error_condition & rhs )
{
return !(lhs == rhs);
}
inline bool operator==( const error_condition & condition,
const error_code & code )
{
return condition.category().equivalent( code, condition.value() )
|| code.category().equivalent( code.value(), condition );
}
inline bool operator!=( const error_condition & lhs,
const error_code & rhs )
{
return !(lhs == rhs);
}
// TODO: both of these may move elsewhere, but the LWG hasn't spoken yet.
template <class charT, class traits>
inline std::basic_ostream<charT,traits>&
operator<< (std::basic_ostream<charT,traits>& os, error_code ec)
{
os << ec.category().name() << ':' << ec.value();
return os;
}
inline std::size_t hash_value( const error_code & ec )
{
return static_cast<std::size_t>(ec.value())
+ reinterpret_cast<std::size_t>(&ec.category());
}
// make_* functions for errc::errc_t -----------------------------//
namespace errc
{
// explicit conversion:
inline error_code make_error_code( errc_t e )
{ return error_code( e, get_generic_category() ); }
// implicit conversion:
inline error_condition make_error_condition( errc_t e )
{ return error_condition( e, get_generic_category() ); }
}
// error_category default implementation -------------------------------//
inline error_condition error_category::default_error_condition( int ev ) const
{
return error_condition( ev, *this );
}
inline bool error_category::equivalent( int code,
const error_condition & condition ) const
{
return default_error_condition( code ) == condition;
}
inline bool error_category::equivalent( const error_code & code,
int condition ) const
{
return *this == code.category() && code.value() == condition;
}
} // namespace system
} // namespace boost
#include <boost/config/abi_suffix.hpp> // pops abi_prefix.hpp pragmas
# ifdef BOOST_ERROR_CODE_HEADER_ONLY
# include <boost/../libs/system/src/error_code.cpp>
# endif
#endif // BOOST_ERROR_CODE_HPP
#include <boost/system/detail/error_code.hpp>
#include <boost/system/error_category.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/system/errc.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/system/detail/throws.hpp>
#endif // BOOST_SYSTEM_ERROR_CODE_HPP_INCLUDED

View File

@ -0,0 +1,13 @@
#ifndef BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED
#define BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/error_condition.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#endif // #ifndef BOOST_SYSTEM_ERROR_CONDITION_HPP_INCLUDED

View File

@ -0,0 +1,13 @@
#ifndef BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/generic_category.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#endif // #ifndef BOOST_SYSTEM_GENERIC_CATEGORY_HPP_INCLUDED

View File

@ -0,0 +1,30 @@
#ifndef BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED
#define BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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
namespace boost
{
namespace system
{
class error_code;
template<class T> struct is_error_code_enum
{
static const bool value = false;
};
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_IS_ERROR_CODE_ENUM_HPP_INCLUDED

View File

@ -0,0 +1,30 @@
#ifndef BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED
#define BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED
// Copyright Beman Dawes 2006, 2007
// Copyright Christoper Kohlhoff 2007
// Copyright Peter Dimov 2017, 2018
//
// 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
namespace boost
{
namespace system
{
class error_condition;
template<class T> struct is_error_condition_enum
{
static const bool value = false;
};
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_IS_ERROR_CONDITION_ENUM_HPP_INCLUDED

View File

@ -7,8 +7,8 @@
// See library home page at http://www.boost.org/libs/system
#ifndef BOOST_LINUX_ERROR_HPP
#define BOOST_LINUX_ERROR_HPP
#ifndef BOOST_SYSTEM_LINUX_ERROR_HPP
#define BOOST_SYSTEM_LINUX_ERROR_HPP
// This header is effectively empty for compiles on operating systems where
// it is not applicable.
@ -23,7 +23,7 @@ namespace boost
{
// To construct an error_code after a API error:
//
// error_code( errno, system_category )
// error_code( errno, system_category() )
// User code should use the portable "posix" enums for POSIX errors; this
// allows such code to be portable to non-POSIX systems. For the non-POSIX
@ -89,7 +89,7 @@ namespace boost
};
} // namespace linux_error
# ifndef BOOST_SYSTEM_NO_DEPRECATED
# ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
namespace Linux = linux_error;
# endif
@ -99,7 +99,7 @@ namespace boost
namespace linux_error
{
inline error_code make_error_code( linux_errno e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
} // namespace system
@ -107,4 +107,4 @@ namespace boost
#endif // Linux
#endif // BOOST_LINUX_ERROR_HPP
#endif // BOOST_SYSTEM_LINUX_ERROR_HPP

View File

@ -0,0 +1,604 @@
#ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED
#define BOOST_SYSTEM_RESULT_HPP_INCLUDED
// 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/errc.hpp>
#include <boost/system/system_error.hpp>
#include <boost/system/detail/error_code.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#include <boost/variant2/variant.hpp>
#include <boost/throw_exception.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/assert.hpp>
#include <boost/config.hpp>
#include <type_traits>
#include <utility>
#include <iosfwd>
#include <system_error>
#include <exception>
//
namespace boost
{
namespace system
{
// throw_exception_from_error
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wattributes"
#endif
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( error_code const & e, boost::source_location const& loc )
{
boost::throw_with_location( system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( errc::errc_t const & e, boost::source_location const& loc )
{
boost::throw_with_location( system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::error_code const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( e ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::errc const & e, boost::source_location const& loc )
{
boost::throw_with_location( std::system_error( make_error_code( e ) ), loc );
}
BOOST_NORETURN BOOST_NOINLINE inline void throw_exception_from_error( std::exception_ptr const & p, boost::source_location const& loc )
{
if( p )
{
std::rethrow_exception( p );
}
else
{
boost::throw_with_location( std::bad_exception(), loc );
}
}
#if defined(__GNUC__) && __GNUC__ >= 7 && __GNUC__ <= 8
# pragma GCC diagnostic pop
#endif
// in_place_*
using in_place_value_t = variant2::in_place_index_t<0>;
constexpr in_place_value_t in_place_value{};
using in_place_error_t = variant2::in_place_index_t<1>;
constexpr in_place_error_t in_place_error{};
namespace detail
{
template<class T> using remove_cvref = typename std::remove_cv< typename std::remove_reference<T>::type >::type;
template<class... T> using is_errc_t = std::is_same<mp11::mp_list<remove_cvref<T>...>, mp11::mp_list<errc::errc_t>>;
} // namespace detail
// result
template<class T, class E = error_code> class result
{
private:
variant2::variant<T, E> v_;
public:
// constructors
// default
template<class En2 = void, class En = typename std::enable_if<
std::is_void<En2>::value &&
std::is_default_constructible<T>::value
>::type>
constexpr result()
noexcept( std::is_nothrow_default_constructible<T>::value )
: v_( in_place_value )
{
}
// implicit, value
template<class A = T, typename std::enable_if<
std::is_convertible<A, T>::value &&
!(detail::is_errc_t<A>::value && std::is_arithmetic<T>::value) &&
!std::is_constructible<E, A>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<T, A>::value )
: v_( in_place_value, std::forward<A>(a) )
{
}
// implicit, error
template<class A = E, class = void, typename std::enable_if<
std::is_convertible<A, E>::value &&
!std::is_constructible<T, A>::value, int>::type = 0>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<E, A>::value )
: v_( in_place_error, std::forward<A>(a) )
{
}
// explicit, value
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
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<T, A...>::value )
: v_( in_place_value, std::forward<A>(a)... )
{
}
// 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
>::type>
explicit constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// tagged, value
template<class... A, class En = typename std::enable_if<
std::is_constructible<T, A...>::value
>::type>
constexpr result( in_place_value_t, A&&... a )
noexcept( std::is_nothrow_constructible<T, A...>::value )
: v_( in_place_value, std::forward<A>(a)... )
{
}
// tagged, error
template<class... A, class En = typename std::enable_if<
std::is_constructible<E, A...>::value
>::type>
constexpr result( in_place_error_t, A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// 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
{
return v_.index() == 0;
}
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
}
constexpr explicit operator bool() const noexcept
{
return v_.index() == 0;
}
// checked value access
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
BOOST_CXX14_CONSTEXPR T value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
return variant2::unsafe_get<0>( v_ );
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
#else
BOOST_CXX14_CONSTEXPR T& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &
{
if( has_value() )
{
return variant2::unsafe_get<0>( v_ );
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
BOOST_CXX14_CONSTEXPR T const& value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const&
{
if( has_value() )
{
return variant2::unsafe_get<0>( v_ );
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value( loc ) );
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) &&
{
return std::move( value( loc ) );
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
value() const && = delete;
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const &&
{
return std::move( value( loc ) );
}
#endif
// unchecked value access
BOOST_CXX14_CONSTEXPR T* operator->() noexcept
{
return variant2::get_if<0>( &v_ );
}
BOOST_CXX14_CONSTEXPR T const* operator->() const noexcept
{
return variant2::get_if<0>( &v_ );
}
#if defined( BOOST_NO_CXX11_REF_QUALIFIERS )
BOOST_CXX14_CONSTEXPR T& operator*() noexcept
{
T* p = operator->();
BOOST_ASSERT( p != 0 );
return *p;
}
BOOST_CXX14_CONSTEXPR T const& operator*() const noexcept
{
T const* p = operator->();
BOOST_ASSERT( p != 0 );
return *p;
}
#else
BOOST_CXX14_CONSTEXPR T& operator*() & noexcept
{
T* p = operator->();
BOOST_ASSERT( p != 0 );
return *p;
}
BOOST_CXX14_CONSTEXPR T const& operator*() const & noexcept
{
T const* p = operator->();
BOOST_ASSERT( p != 0 );
return *p;
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
operator*() && noexcept(std::is_nothrow_move_constructible<T>::value)
{
return std::move(**this);
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T&&>::type
operator*() && noexcept
{
return std::move(**this);
}
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<std::is_move_constructible<U>::value, T>::type
operator*() const && noexcept = delete;
template<class U = T>
BOOST_CXX14_CONSTEXPR
typename std::enable_if<!std::is_move_constructible<U>::value, T const&&>::type
operator*() const && noexcept
{
return std::move(**this);
}
#endif
// error access
constexpr E error() const
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
{
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
noexcept( noexcept( v_.swap( r.v_ ) ) )
{
v_.swap( r.v_ );
}
friend BOOST_CXX14_CONSTEXPR void swap( result & r1, result & r2 )
noexcept( noexcept( r1.swap( r2 ) ) )
{
r1.swap( r2 );
}
// equality
friend constexpr bool operator==( result const & r1, result const & r2 )
noexcept( noexcept( r1.v_ == r2.v_ ) )
{
return r1.v_ == r2.v_;
}
friend constexpr bool operator!=( result const & r1, result const & r2 )
noexcept( noexcept( !( r1 == r2 ) ) )
{
return !( r1 == r2 );
}
};
template<class Ch, class Tr, class T, class E> std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, result<T, E> const & r )
{
if( r.has_value() )
{
os << "value:" << *r;
}
else
{
os << "error:" << r.error();
}
return os;
}
// result<void>
template<class E> class result<void, E>
{
private:
variant2::variant<variant2::monostate, E> v_;
public:
// constructors
// default
constexpr result() noexcept
: v_( in_place_value )
{
}
// explicit, error
template<class A, class En = typename std::enable_if<
std::is_constructible<E, A>::value &&
!std::is_convertible<A, E>::value
>::type>
explicit constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<E, A>::value )
: v_( in_place_error, std::forward<A>(a) )
{
}
// implicit, error
template<class A, class En2 = void, class En = typename std::enable_if<
std::is_convertible<A, E>::value
>::type>
constexpr result( A&& a )
noexcept( std::is_nothrow_constructible<E, A>::value )
: v_( in_place_error, std::forward<A>(a) )
{
}
// more than one arg, error
template<class... A, class En2 = void, class En3 = void, class En = typename std::enable_if<
std::is_constructible<E, A...>::value &&
sizeof...(A) >= 2
>::type>
constexpr result( A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// tagged, value
constexpr result( in_place_value_t ) noexcept
: v_( in_place_value )
{
}
// tagged, error
template<class... A, class En = typename std::enable_if<
std::is_constructible<E, A...>::value
>::type>
constexpr result( in_place_error_t, A&&... a )
noexcept( std::is_nothrow_constructible<E, A...>::value )
: v_( in_place_error, std::forward<A>(a)... )
{
}
// queries
constexpr bool has_value() const noexcept
{
return v_.index() == 0;
}
constexpr bool has_error() const noexcept
{
return v_.index() != 0;
}
constexpr explicit operator bool() const noexcept
{
return v_.index() == 0;
}
// checked value access
BOOST_CXX14_CONSTEXPR void value( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) const
{
if( has_value() )
{
}
else
{
throw_exception_from_error( variant2::unsafe_get<1>( v_ ), loc );
}
}
// unchecked value access
BOOST_CXX14_CONSTEXPR void* operator->() noexcept
{
return variant2::get_if<0>( &v_ );
}
BOOST_CXX14_CONSTEXPR void const* operator->() const noexcept
{
return variant2::get_if<0>( &v_ );
}
BOOST_CXX14_CONSTEXPR void operator*() const noexcept
{
BOOST_ASSERT( has_value() );
}
// error access
constexpr E error() const
noexcept( std::is_nothrow_default_constructible<E>::value && std::is_nothrow_copy_constructible<E>::value )
{
return has_error()? variant2::unsafe_get<1>( v_ ): E();
}
// swap
BOOST_CXX14_CONSTEXPR void swap( result& r )
noexcept( noexcept( v_.swap( r.v_ ) ) )
{
v_.swap( r.v_ );
}
friend BOOST_CXX14_CONSTEXPR void swap( result & r1, result & r2 )
noexcept( noexcept( r1.swap( r2 ) ) )
{
r1.swap( r2 );
}
// equality
friend constexpr bool operator==( result const & r1, result const & r2 )
noexcept( noexcept( r1.v_ == r2.v_ ) )
{
return r1.v_ == r2.v_;
}
friend constexpr bool operator!=( result const & r1, result const & r2 )
noexcept( noexcept( !( r1 == r2 ) ) )
{
return !( r1 == r2 );
}
};
template<class Ch, class Tr, class E> std::basic_ostream<Ch, Tr>& operator<<( std::basic_ostream<Ch, Tr>& os, result<void, E> const & r )
{
if( r.has_value() )
{
os << "value:void";
}
else
{
os << "error:" << r.error();
}
return os;
}
} // namespace system
} // namespace boost
#endif // #ifndef BOOST_SYSTEM_RESULT_HPP_INCLUDED

View File

@ -0,0 +1,14 @@
#ifndef BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED
#define BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
//
// See library home page at http://www.boost.org/libs/system
#include <boost/system/detail/system_category.hpp>
#include <boost/system/detail/system_category_impl.hpp>
#include <boost/system/detail/error_category_impl.hpp>
#endif // #ifndef BOOST_SYSTEM_SYSTEM_CATEGORY_HPP_INCLUDED

View File

@ -1,81 +1,55 @@
// Boost system_error.hpp --------------------------------------------------//
#ifndef BOOST_SYSTEM_SYSTEM_ERROR_HPP
#define BOOST_SYSTEM_SYSTEM_ERROR_HPP
// Copyright Beman Dawes 2006
// 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)
#ifndef BOOST_SYSTEM_ERROR_HPP
#define BOOST_SYSTEM_ERROR_HPP
// Copyright Beman Dawes 2006
// Copyright Peter Dimov 2021
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
#include <boost/system/detail/error_code.hpp>
#include <string>
#include <stdexcept>
#include <cassert>
#include <boost/system/error_code.hpp>
namespace boost
{
namespace system
{
// class system_error --------------------------------------------------//
namespace system
{
class system_error : public std::runtime_error
class BOOST_SYMBOL_VISIBLE system_error: public std::runtime_error
{
private:
error_code code_;
public:
explicit system_error( error_code const & ec ):
std::runtime_error( ec.what() ), code_( ec ) {}
system_error( error_code const & ec, std::string const & prefix ):
std::runtime_error( prefix + ": " + ec.what() ), code_( ec ) {}
system_error( error_code const & ec, char const * prefix ):
std::runtime_error( std::string( prefix ) + ": " + ec.what() ), code_( ec ) {}
system_error( int ev, error_category const & ecat ):
std::runtime_error( error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, std::string const & prefix ):
std::runtime_error( prefix + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
system_error( int ev, error_category const & ecat, char const * prefix ):
std::runtime_error( std::string( prefix ) + ": " + error_code( ev, ecat ).what() ), code_( ev, ecat ) {}
error_code code() const BOOST_NOEXCEPT
{
public:
system_error( error_code ec )
: std::runtime_error(""), m_error_code(ec) {}
system_error( error_code ec, const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {}
system_error( error_code ec, const char* what_arg )
: std::runtime_error(what_arg), m_error_code(ec) {}
system_error( int ev, const error_category & ecat )
: std::runtime_error(""), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat,
const std::string & what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
system_error( int ev, const error_category & ecat,
const char * what_arg )
: std::runtime_error(what_arg), m_error_code(ev,ecat) {}
virtual ~system_error() throw() {}
const error_code & code() const throw() { return m_error_code; }
const char * what() const throw();
private:
error_code m_error_code;
mutable std::string m_what;
};
// implementation ------------------------------------------------------//
inline const char * system_error::what() const throw()
// see http://www.boost.org/more/error_handling.html for lazy build rationale
{
if ( m_what.empty() )
{
try
{
m_what = this->std::runtime_error::what();
if ( m_error_code )
{
if ( !m_what.empty() ) m_what += ": ";
m_what += m_error_code.message();
}
}
catch (...) { return std::runtime_error::what(); }
}
return m_what.c_str();
return code_;
}
};
} // namespace system
} // namespace system
} // namespace boost
#endif // BOOST_SYSTEM_ERROR_HPP
#endif // BOOST_SYSTEM_SYSTEM_ERROR_HPP

View File

@ -7,8 +7,8 @@
// See library home page at http://www.boost.org/libs/system
#ifndef BOOST_WINDOWS_ERROR_HPP
#define BOOST_WINDOWS_ERROR_HPP
#ifndef BOOST_SYSTEM_WINDOWS_ERROR_HPP
#define BOOST_SYSTEM_WINDOWS_ERROR_HPP
// This header is effectively empty for compiles on operating systems where
// it is not applicable.
@ -18,7 +18,7 @@
#ifdef BOOST_WINDOWS_API
#include <boost/system/error_code.hpp>
#include <winerror.h>
#include <boost/winapi/error_codes.hpp>
namespace boost
{
@ -29,7 +29,7 @@ namespace boost
// To construct an error_code after a API error:
//
// error_code( ::GetLastError(), system_category )
// error_code( ::GetLastError(), system_category() )
namespace windows_error
{
@ -37,59 +37,60 @@ namespace boost
{
success = 0,
// These names and values are based on Windows winerror.h
invalid_function = ERROR_INVALID_FUNCTION,
file_not_found = ERROR_FILE_NOT_FOUND,
path_not_found = ERROR_PATH_NOT_FOUND,
too_many_open_files = ERROR_TOO_MANY_OPEN_FILES,
access_denied = ERROR_ACCESS_DENIED,
invalid_handle = ERROR_INVALID_HANDLE,
arena_trashed = ERROR_ARENA_TRASHED,
not_enough_memory = ERROR_NOT_ENOUGH_MEMORY,
invalid_block = ERROR_INVALID_BLOCK,
bad_environment = ERROR_BAD_ENVIRONMENT,
bad_format = ERROR_BAD_FORMAT,
invalid_access = ERROR_INVALID_ACCESS,
outofmemory = ERROR_OUTOFMEMORY,
invalid_drive = ERROR_INVALID_DRIVE,
current_directory = ERROR_CURRENT_DIRECTORY,
not_same_device = ERROR_NOT_SAME_DEVICE,
no_more_files = ERROR_NO_MORE_FILES,
write_protect = ERROR_WRITE_PROTECT,
bad_unit = ERROR_BAD_UNIT,
not_ready = ERROR_NOT_READY,
bad_command = ERROR_BAD_COMMAND,
crc = ERROR_CRC,
bad_length = ERROR_BAD_LENGTH,
seek = ERROR_SEEK,
not_dos_disk = ERROR_NOT_DOS_DISK,
sector_not_found = ERROR_SECTOR_NOT_FOUND,
out_of_paper = ERROR_OUT_OF_PAPER,
write_fault = ERROR_WRITE_FAULT,
read_fault = ERROR_READ_FAULT,
gen_failure = ERROR_GEN_FAILURE,
sharing_violation = ERROR_SHARING_VIOLATION,
lock_violation = ERROR_LOCK_VIOLATION,
wrong_disk = ERROR_WRONG_DISK,
sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED,
handle_eof = ERROR_HANDLE_EOF,
handle_disk_full= ERROR_HANDLE_DISK_FULL,
rem_not_list = ERROR_REM_NOT_LIST,
dup_name = ERROR_DUP_NAME,
bad_net_path = ERROR_BAD_NETPATH,
network_busy = ERROR_NETWORK_BUSY,
invalid_function = boost::winapi::ERROR_INVALID_FUNCTION_,
file_not_found = boost::winapi::ERROR_FILE_NOT_FOUND_,
path_not_found = boost::winapi::ERROR_PATH_NOT_FOUND_,
too_many_open_files = boost::winapi::ERROR_TOO_MANY_OPEN_FILES_,
access_denied = boost::winapi::ERROR_ACCESS_DENIED_,
invalid_handle = boost::winapi::ERROR_INVALID_HANDLE_,
arena_trashed = boost::winapi::ERROR_ARENA_TRASHED_,
not_enough_memory = boost::winapi::ERROR_NOT_ENOUGH_MEMORY_,
invalid_block = boost::winapi::ERROR_INVALID_BLOCK_,
bad_environment = boost::winapi::ERROR_BAD_ENVIRONMENT_,
bad_format = boost::winapi::ERROR_BAD_FORMAT_,
invalid_access = boost::winapi::ERROR_INVALID_ACCESS_,
outofmemory = boost::winapi::ERROR_OUTOFMEMORY_,
invalid_drive = boost::winapi::ERROR_INVALID_DRIVE_,
current_directory = boost::winapi::ERROR_CURRENT_DIRECTORY_,
not_same_device = boost::winapi::ERROR_NOT_SAME_DEVICE_,
no_more_files = boost::winapi::ERROR_NO_MORE_FILES_,
write_protect = boost::winapi::ERROR_WRITE_PROTECT_,
bad_unit = boost::winapi::ERROR_BAD_UNIT_,
not_ready = boost::winapi::ERROR_NOT_READY_,
bad_command = boost::winapi::ERROR_BAD_COMMAND_,
crc = boost::winapi::ERROR_CRC_,
bad_length = boost::winapi::ERROR_BAD_LENGTH_,
seek = boost::winapi::ERROR_SEEK_,
not_dos_disk = boost::winapi::ERROR_NOT_DOS_DISK_,
sector_not_found = boost::winapi::ERROR_SECTOR_NOT_FOUND_,
out_of_paper = boost::winapi::ERROR_OUT_OF_PAPER_,
write_fault = boost::winapi::ERROR_WRITE_FAULT_,
read_fault = boost::winapi::ERROR_READ_FAULT_,
gen_failure = boost::winapi::ERROR_GEN_FAILURE_,
sharing_violation = boost::winapi::ERROR_SHARING_VIOLATION_,
lock_violation = boost::winapi::ERROR_LOCK_VIOLATION_,
wrong_disk = boost::winapi::ERROR_WRONG_DISK_,
sharing_buffer_exceeded = boost::winapi::ERROR_SHARING_BUFFER_EXCEEDED_,
handle_eof = boost::winapi::ERROR_HANDLE_EOF_,
handle_disk_full = boost::winapi::ERROR_HANDLE_DISK_FULL_,
not_supported = boost::winapi::ERROR_NOT_SUPPORTED_,
rem_not_list = boost::winapi::ERROR_REM_NOT_LIST_,
dup_name = boost::winapi::ERROR_DUP_NAME_,
bad_net_path = boost::winapi::ERROR_BAD_NETPATH_,
network_busy = boost::winapi::ERROR_NETWORK_BUSY_,
// ...
file_exists = ERROR_FILE_EXISTS,
cannot_make = ERROR_CANNOT_MAKE,
file_exists = boost::winapi::ERROR_FILE_EXISTS_,
cannot_make = boost::winapi::ERROR_CANNOT_MAKE_,
// ...
broken_pipe = ERROR_BROKEN_PIPE,
open_failed = ERROR_OPEN_FAILED,
buffer_overflow = ERROR_BUFFER_OVERFLOW,
disk_full= ERROR_DISK_FULL,
broken_pipe = boost::winapi::ERROR_BROKEN_PIPE_,
open_failed = boost::winapi::ERROR_OPEN_FAILED_,
buffer_overflow = boost::winapi::ERROR_BUFFER_OVERFLOW_,
disk_full = boost::winapi::ERROR_DISK_FULL_,
// ...
lock_failed = ERROR_LOCK_FAILED,
busy = ERROR_BUSY,
cancel_violation = ERROR_CANCEL_VIOLATION,
already_exists = ERROR_ALREADY_EXISTS
lock_failed = boost::winapi::ERROR_LOCK_FAILED_,
busy = boost::winapi::ERROR_BUSY_,
cancel_violation = boost::winapi::ERROR_CANCEL_VIOLATION_,
already_exists = boost::winapi::ERROR_ALREADY_EXISTS_
// ...
// TODO: add more Windows errors
@ -97,7 +98,7 @@ namespace boost
} // namespace windows
# ifndef BOOST_SYSTEM_NO_DEPRECATED
# ifdef BOOST_SYSTEM_ENABLE_DEPRECATED
namespace windows = windows_error;
# endif
@ -107,7 +108,7 @@ namespace boost
namespace windows_error
{
inline error_code make_error_code( windows_error_code e )
{ return error_code( e, get_system_category() ); }
{ return error_code( e, system_category() ); }
}
} // namespace system
@ -115,4 +116,4 @@ namespace boost
#endif // BOOST_WINDOWS_API
#endif // BOOST_WINDOWS_ERROR_HPP
#endif // BOOST_SYSTEM_WINDOWS_ERROR_HPP

View File

@ -1,14 +1,15 @@
<html>
<head>
<meta http-equiv="refresh" content="0; URL=doc/index.html">
<meta http-equiv="refresh" content="0; URL=doc/html/system.html">
</head>
<body>
Automatic redirection failed, please go to
<a href="doc/index.html">doc/index.html</a>.
<hr>
<p><EFBFBD> Copyright Beman Dawes, 2003</p>
<p> Distribution under the Boost Software License, Version 1.0.
(See accompanying file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy at <a href="http://www.boost.org/LICENSE_1_0.txt">
www.boost.org/LICENSE_1_0.txt</a>)</p>
<a href="doc/html/system.html">doc/html/system.html</a>.
</body>
</html>
</html>
<!--
© Copyright Beman Dawes, 2001
Distributed under the Boost Software License, Version 1.0.
See accompanying file LICENSE_1_0.txt or copy at
https://www.boost.org/LICENSE_1_0.txt
-->

17
meta/libraries.json Normal file
View File

@ -0,0 +1,17 @@
{
"key": "system",
"name": "System",
"authors": [
"Beman Dawes"
],
"maintainers": [
"Peter Dimov <pdimov -at- gmail.com>"
],
"description": "Extensible error reporting.",
"category": [
"System",
"Error-handling",
"Programming"
],
"cxxstd": "03"
}

View File

@ -1,6 +1,7 @@
// error_code support implementation file ----------------------------------//
// error_code stub implementation, for compatibility only
// Copyright Beman Dawes 2002, 2006
// Copyright Peter Dimov 2018
// 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)
@ -9,427 +10,22 @@
//----------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
// define BOOST_SYSTEM_SOURCE so that <boost/system/config.hpp> knows
// the library is being built (possibly exporting rather than importing code)
#define BOOST_SYSTEM_SOURCE
#define BOOST_SYSTEM_SOURCE
#include <boost/system/config.hpp>
#include <boost/system/error_code.hpp>
#include <boost/cerrno.hpp>
#include <vector>
#include <cstdlib>
#include <cassert>
using namespace boost::system;
using namespace boost::system::errc;
#include <cstring> // for strerror/strerror_r
# if defined( BOOST_WINDOWS_API )
# include <windows.h>
# ifndef ERROR_INCORRECT_SIZE
# define ERROR_INCORRECT_SIZE ERROR_BAD_ARGUMENTS
# endif
# endif
//----------------------------------------------------------------------------//
namespace
{
// standard error categories ---------------------------------------------//
class generic_error_category : public error_category
{
public:
generic_error_category(){}
const char * name() const;
std::string message( int ev ) const;
};
class system_error_category : public error_category
{
public:
system_error_category(){}
const char * name() const;
std::string message( int ev ) const;
error_condition default_error_condition( int ev ) const;
};
// generic_error_category implementation ---------------------------------//
const char * generic_error_category::name() const
{
return "generic";
}
std::string generic_error_category::message( int ev ) const
{
static std::string unknown_err( "Unknown error" );
// strerror_r is preferred because it is always thread safe,
// however, we fallback to strerror in certain cases because:
// -- Windows doesn't provide strerror_r.
// -- HP and Sundo provide strerror_r on newer systems, but there is
// no way to tell if is available at runtime and in any case their
// versions of strerror are thread safe anyhow.
// -- Linux only sometimes provides strerror_r.
// -- Tru64 provides strerror_r only when compiled -pthread.
// -- VMS doesn't provide strerror_r, but on this platform, strerror is
// thread safe.
# if defined(BOOST_WINDOWS_API) || defined(__hpux) || defined(__sun)\
|| (defined(__linux) && (!defined(__USE_XOPEN2K) || defined(BOOST_SYSTEM_USE_STRERROR)))\
|| (defined(__osf__) && !defined(_REENTRANT))\
|| (defined(__vms))\
|| (defined(__QNXNTO__))
const char * c_str = std::strerror( ev );
return c_str
? std::string( c_str )
: unknown_err;
# else // use strerror_r
char buf[64];
char * bp = buf;
std::size_t sz = sizeof(buf);
# if defined(__CYGWIN__) || defined(__USE_GNU)
// Oddball version of strerror_r
const char * c_str = strerror_r( ev, bp, sz );
return c_str
? std::string( c_str )
: unknown_err;
# else
// POSIX version of strerror_r
int result;
for (;;)
{
// strerror_r returns 0 on success, otherwise ERANGE if buffer too small,
// invalid_argument if ev not a valid error number
# if defined (__sgi)
const char * c_str = strerror( ev );
result = 0;
return c_str
? std::string( c_str )
: unknown_err;
# else
result = strerror_r( ev, bp, sz );
# endif
if (result == 0 )
break;
else
{
# if defined(__linux)
// Linux strerror_r returns -1 on error, with error number in errno
result = errno;
# endif
if ( result != ERANGE ) break;
if ( sz > sizeof(buf) ) std::free( bp );
sz *= 2;
if ( (bp = static_cast<char*>(std::malloc( sz ))) == 0 )
return std::string( "ENOMEM" );
}
}
std::string msg;
try
{
msg = ( ( result == invalid_argument ) ? "Unknown error" : bp );
}
# ifndef BOOST_NO_EXCEPTIONS
// See ticket #2098
catch(...)
{
// just eat the exception
}
# endif
if ( sz > sizeof(buf) ) std::free( bp );
sz = 0;
return msg;
# endif // else POSIX version of strerror_r
# endif // else use strerror_r
}
// system_error_category implementation --------------------------------//
const char * system_error_category::name() const
{
return "system";
}
error_condition system_error_category::default_error_condition( int ev ) const
{
switch ( ev )
{
case 0: return make_error_condition( success );
# if defined(BOOST_POSIX_API)
// POSIX-like O/S -> posix_errno decode table ---------------------------//
case E2BIG: return make_error_condition( argument_list_too_long );
case EACCES: return make_error_condition( permission_denied );
case EADDRINUSE: return make_error_condition( address_in_use );
case EADDRNOTAVAIL: return make_error_condition( address_not_available );
case EAFNOSUPPORT: return make_error_condition( address_family_not_supported );
case EAGAIN: return make_error_condition( resource_unavailable_try_again );
# if EALREADY != EBUSY // EALREADY and EBUSY are the same on QNX Neutrino
case EALREADY: return make_error_condition( connection_already_in_progress );
# endif
case EBADF: return make_error_condition( bad_file_descriptor );
case EBADMSG: return make_error_condition( bad_message );
case EBUSY: return make_error_condition( device_or_resource_busy );
case ECANCELED: return make_error_condition( operation_canceled );
case ECHILD: return make_error_condition( no_child_process );
case ECONNABORTED: return make_error_condition( connection_aborted );
case ECONNREFUSED: return make_error_condition( connection_refused );
case ECONNRESET: return make_error_condition( connection_reset );
case EDEADLK: return make_error_condition( resource_deadlock_would_occur );
case EDESTADDRREQ: return make_error_condition( destination_address_required );
case EDOM: return make_error_condition( argument_out_of_domain );
case EEXIST: return make_error_condition( file_exists );
case EFAULT: return make_error_condition( bad_address );
case EFBIG: return make_error_condition( file_too_large );
case EHOSTUNREACH: return make_error_condition( host_unreachable );
case EIDRM: return make_error_condition( identifier_removed );
case EILSEQ: return make_error_condition( illegal_byte_sequence );
case EINPROGRESS: return make_error_condition( operation_in_progress );
case EINTR: return make_error_condition( interrupted );
case EINVAL: return make_error_condition( invalid_argument );
case EIO: return make_error_condition( io_error );
case EISCONN: return make_error_condition( already_connected );
case EISDIR: return make_error_condition( is_a_directory );
case ELOOP: return make_error_condition( too_many_synbolic_link_levels );
case EMFILE: return make_error_condition( too_many_files_open );
case EMLINK: return make_error_condition( too_many_links );
case EMSGSIZE: return make_error_condition( message_size );
case ENAMETOOLONG: return make_error_condition( filename_too_long );
case ENETDOWN: return make_error_condition( network_down );
case ENETRESET: return make_error_condition( network_reset );
case ENETUNREACH: return make_error_condition( network_unreachable );
case ENFILE: return make_error_condition( too_many_files_open_in_system );
case ENOBUFS: return make_error_condition( no_buffer_space );
case ENODATA: return make_error_condition( no_message_available );
case ENODEV: return make_error_condition( no_such_device );
case ENOENT: return make_error_condition( no_such_file_or_directory );
case ENOEXEC: return make_error_condition( executable_format_error );
case ENOLCK: return make_error_condition( no_lock_available );
case ENOLINK: return make_error_condition( no_link );
case ENOMEM: return make_error_condition( not_enough_memory );
case ENOMSG: return make_error_condition( no_message );
case ENOPROTOOPT: return make_error_condition( no_protocol_option );
case ENOSPC: return make_error_condition( no_space_on_device );
case ENOSR: return make_error_condition( no_stream_resources );
case ENOSTR: return make_error_condition( not_a_stream );
case ENOSYS: return make_error_condition( function_not_supported );
case ENOTCONN: return make_error_condition( not_connected );
case ENOTDIR: return make_error_condition( not_a_directory );
# if ENOTEMPTY != EEXIST // AIX treats ENOTEMPTY and EEXIST as the same value
case ENOTEMPTY: return make_error_condition( directory_not_empty );
# endif // ENOTEMPTY != EEXIST
case ENOTRECOVERABLE: return make_error_condition( state_not_recoverable );
case ENOTSOCK: return make_error_condition( not_a_socket );
case ENOTSUP: return make_error_condition( not_supported );
case ENOTTY: return make_error_condition( inappropriate_io_control_operation );
case ENXIO: return make_error_condition( no_such_device_or_address );
# if EOPNOTSUPP != ENOTSUP
case EOPNOTSUPP: return make_error_condition( operation_not_supported );
# endif // EOPNOTSUPP != ENOTSUP
case EOVERFLOW: return make_error_condition( value_too_large );
case EOWNERDEAD: return make_error_condition( owner_dead );
case EPERM: return make_error_condition( operation_not_permitted );
case EPIPE: return make_error_condition( broken_pipe );
case EPROTO: return make_error_condition( protocol_error );
case EPROTONOSUPPORT: return make_error_condition( protocol_not_supported );
case EPROTOTYPE: return make_error_condition( wrong_protocol_type );
case ERANGE: return make_error_condition( result_out_of_range );
case EROFS: return make_error_condition( read_only_file_system );
case ESPIPE: return make_error_condition( invalid_seek );
case ESRCH: return make_error_condition( no_such_process );
case ETIME: return make_error_condition( stream_timeout );
case ETIMEDOUT: return make_error_condition( timed_out );
case ETXTBSY: return make_error_condition( text_file_busy );
# if EAGAIN != EWOULDBLOCK
case EWOULDBLOCK: return make_error_condition( operation_would_block );
# endif // EAGAIN != EWOULDBLOCK
case EXDEV: return make_error_condition( cross_device_link );
#else
// Windows system -> posix_errno decode table ---------------------------//
// see WinError.h comments for descriptions of errors
case ERROR_ACCESS_DENIED: return make_error_condition( permission_denied );
case ERROR_ALREADY_EXISTS: return make_error_condition( file_exists );
case ERROR_BAD_UNIT: return make_error_condition( no_such_device );
case ERROR_BUFFER_OVERFLOW: return make_error_condition( filename_too_long );
case ERROR_BUSY: return make_error_condition( device_or_resource_busy );
case ERROR_BUSY_DRIVE: return make_error_condition( device_or_resource_busy );
case ERROR_CANNOT_MAKE: return make_error_condition( permission_denied );
case ERROR_CANTOPEN: return make_error_condition( io_error );
case ERROR_CANTREAD: return make_error_condition( io_error );
case ERROR_CANTWRITE: return make_error_condition( io_error );
case ERROR_CURRENT_DIRECTORY: return make_error_condition( permission_denied );
case ERROR_DEV_NOT_EXIST: return make_error_condition( no_such_device );
case ERROR_DEVICE_IN_USE: return make_error_condition( device_or_resource_busy );
case ERROR_DIR_NOT_EMPTY: return make_error_condition( directory_not_empty );
case ERROR_DIRECTORY: return make_error_condition( invalid_argument ); // WinError.h: "The directory name is invalid"
case ERROR_DISK_FULL: return make_error_condition( no_space_on_device );
case ERROR_FILE_EXISTS: return make_error_condition( file_exists );
case ERROR_FILE_NOT_FOUND: return make_error_condition( no_such_file_or_directory );
case ERROR_HANDLE_DISK_FULL: return make_error_condition( no_space_on_device );
case ERROR_INVALID_ACCESS: return make_error_condition( permission_denied );
case ERROR_INVALID_DRIVE: return make_error_condition( no_such_device );
case ERROR_INVALID_FUNCTION: return make_error_condition( function_not_supported );
case ERROR_INVALID_HANDLE: return make_error_condition( invalid_argument );
case ERROR_INVALID_NAME: return make_error_condition( invalid_argument );
case ERROR_LOCK_VIOLATION: return make_error_condition( no_lock_available );
case ERROR_LOCKED: return make_error_condition( no_lock_available );
case ERROR_NEGATIVE_SEEK: return make_error_condition( invalid_argument );
case ERROR_NOACCESS: return make_error_condition( permission_denied );
case ERROR_NOT_ENOUGH_MEMORY: return make_error_condition( not_enough_memory );
case ERROR_NOT_READY: return make_error_condition( resource_unavailable_try_again );
case ERROR_NOT_SAME_DEVICE: return make_error_condition( cross_device_link );
case ERROR_OPEN_FAILED: return make_error_condition( io_error );
case ERROR_OPEN_FILES: return make_error_condition( device_or_resource_busy );
case ERROR_OPERATION_ABORTED: return make_error_condition( operation_canceled );
case ERROR_OUTOFMEMORY: return make_error_condition( not_enough_memory );
case ERROR_PATH_NOT_FOUND: return make_error_condition( no_such_file_or_directory );
case ERROR_READ_FAULT: return make_error_condition( io_error );
case ERROR_RETRY: return make_error_condition( resource_unavailable_try_again );
case ERROR_SEEK: return make_error_condition( io_error );
case ERROR_SHARING_VIOLATION: return make_error_condition( permission_denied );
case ERROR_TOO_MANY_OPEN_FILES: return make_error_condition( too_many_files_open );
case ERROR_WRITE_FAULT: return make_error_condition( io_error );
case ERROR_WRITE_PROTECT: return make_error_condition( permission_denied );
case WSAEACCES: return make_error_condition( permission_denied );
case WSAEADDRINUSE: return make_error_condition( address_in_use );
case WSAEADDRNOTAVAIL: return make_error_condition( address_not_available );
case WSAEAFNOSUPPORT: return make_error_condition( address_family_not_supported );
case WSAEALREADY: return make_error_condition( connection_already_in_progress );
case WSAEBADF: return make_error_condition( bad_file_descriptor );
case WSAECONNABORTED: return make_error_condition( connection_aborted );
case WSAECONNREFUSED: return make_error_condition( connection_refused );
case WSAECONNRESET: return make_error_condition( connection_reset );
case WSAEDESTADDRREQ: return make_error_condition( destination_address_required );
case WSAEFAULT: return make_error_condition( bad_address );
case WSAEHOSTUNREACH: return make_error_condition( host_unreachable );
case WSAEINPROGRESS: return make_error_condition( operation_in_progress );
case WSAEINTR: return make_error_condition( interrupted );
case WSAEINVAL: return make_error_condition( invalid_argument );
case WSAEISCONN: return make_error_condition( already_connected );
case WSAEMFILE: return make_error_condition( too_many_files_open );
case WSAEMSGSIZE: return make_error_condition( message_size );
case WSAENAMETOOLONG: return make_error_condition( filename_too_long );
case WSAENETDOWN: return make_error_condition( network_down );
case WSAENETRESET: return make_error_condition( network_reset );
case WSAENETUNREACH: return make_error_condition( network_unreachable );
case WSAENOBUFS: return make_error_condition( no_buffer_space );
case WSAENOPROTOOPT: return make_error_condition( no_protocol_option );
case WSAENOTCONN: return make_error_condition( not_connected );
case WSAENOTSOCK: return make_error_condition( not_a_socket );
case WSAEOPNOTSUPP: return make_error_condition( operation_not_supported );
case WSAEPROTONOSUPPORT: return make_error_condition( protocol_not_supported );
case WSAEPROTOTYPE: return make_error_condition( wrong_protocol_type );
case WSAETIMEDOUT: return make_error_condition( timed_out );
case WSAEWOULDBLOCK: return make_error_condition( operation_would_block );
#endif
default: return error_condition( ev, system_category );
}
}
# if !defined( BOOST_WINDOWS_API )
std::string system_error_category::message( int ev ) const
{
return generic_category.message( ev );
}
# else
// TODO:
//Some quick notes on the implementation (sorry for the noise if
//someone has already mentioned them):
//
//- The ::LocalFree() usage isn't exception safe.
//
//See:
//
//<http://boost.cvs.sourceforge.net/boost/boost/boost/asio/system_exception.hpp?revision=1.1&view=markup>
//
//in the implementation of what() for an example.
//
//Cheers,
//Chris
std::string system_error_category::message( int ev ) const
{
# ifndef BOOST_NO_ANSI_APIS
LPVOID lpMsgBuf;
DWORD retval = ::FormatMessageA(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ev,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPSTR) &lpMsgBuf,
0,
NULL
);
if (retval == 0)
return std::string("Unknown error");
std::string str( static_cast<LPCSTR>(lpMsgBuf) );
::LocalFree( lpMsgBuf ); // free the buffer
# else // WinCE workaround
LPVOID lpMsgBuf;
DWORD retval = ::FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
ev,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPWSTR) &lpMsgBuf,
0,
NULL
);
if (retval == 0)
return std::string("Unknown error");
int num_chars = (wcslen( static_cast<LPCWSTR>(lpMsgBuf) ) + 1) * 2;
LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
if (::WideCharToMultiByte(CP_ACP, 0, static_cast<LPCWSTR>(lpMsgBuf), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
return std::string("Unknown error");
std::string str( narrow_buffer );
::LocalFree( lpMsgBuf ); // free the buffer
# endif
while ( str.size()
&& (str[str.size()-1] == '\n' || str[str.size()-1] == '\r') )
str.erase( str.size()-1 );
if ( str.size() && str[str.size()-1] == '.' )
{ str.erase( str.size()-1 ); }
return str;
}
# endif
} // unnamed namespace
namespace boost
{
namespace system
{
# ifndef BOOST_SYSTEM_NO_DEPRECATED
BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code;
// note that it doesn't matter if this
// isn't initialized before use since
// the only use is to take its
// address for comparison purposes
# endif
namespace system
{
BOOST_SYSTEM_DECL const error_category & get_system_category()
{
static const system_error_category system_category_const;
return system_category_const;
}
BOOST_SYSTEM_DECL void dummy_exported_function()
{
}
BOOST_SYSTEM_DECL const error_category & get_generic_category()
{
static const generic_error_category generic_category_const;
return generic_category_const;
}
} // namespace system
} // namespace system
} // namespace boost

145
test/CMakeLists.txt Normal file
View File

@ -0,0 +1,145 @@
# Copyright 2018-2020 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
include(BoostTest OPTIONAL RESULT_VARIABLE HAVE_BOOST_TEST)
if(NOT HAVE_BOOST_TEST)
return()
endif()
macro(system_run s1)
string(MAKE_C_IDENTIFIER ${s1} n1)
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)
endmacro()
macro(lib name macro)
add_library(${name} EXCLUDE_FROM_ALL ${ARGN})
target_compile_definitions(${name} PRIVATE $<$<BOOL:BUILD_SHARED_LIBS>:${macro}=1>)
target_link_libraries(${name} PRIVATE Boost::system Boost::config)
endmacro()
set(BOOST_TEST_LINK_LIBRARIES Boost::system Boost::core Boost::static_assert)
boost_test(SOURCES quick.cpp)
system_run(error_code_test.cpp)
system_run(error_code_user_test.cpp)
system_run(system_error_test.cpp)
lib(boost_system_throw_test THROW_DYN_LINK throw_test.cpp)
boost_test(SOURCES dynamic_link_test.cpp LINK_LIBRARIES boost_system_throw_test)
system_run(initialization_test.cpp)
system_run(header_only_test.cpp)
boost_test(SOURCES config_test.cpp)
system_run(std_interop_test.cpp)
system_run(std_mismatch_test.cpp)
lib(boost_system_single_instance_lib1 SINGLE_INSTANCE_DYN_LINK single_instance_1.cpp)
lib(boost_system_single_instance_lib2 SINGLE_INSTANCE_DYN_LINK single_instance_2.cpp)
system_run(single_instance_test.cpp single_instance_1.cpp single_instance_2.cpp)
boost_test(SOURCES single_instance_test.cpp NAME single_instance_test_lib LINK_LIBRARIES boost_system_single_instance_lib1 boost_system_single_instance_lib2)
system_run(before_main_test.cpp)
system_run(constexpr_test.cpp)
system_run(win32_hresult_test.cpp)
system_run(error_category_test.cpp)
system_run(generic_category_test.cpp)
system_run(system_category_test.cpp)
system_run(after_main_test.cpp)
system_run(failed_test.cpp)
system_run(failed_constexpr_test.cpp)
boost_test(SOURCES warnings_test.cpp COMPILE_OPTIONS -Wall -Werror)
lib(boost_system_std_single_instance_lib1 STD_SINGLE_INSTANCE_DYN_LINK std_single_instance_1.cpp)
lib(boost_system_std_single_instance_lib2 STD_SINGLE_INSTANCE_DYN_LINK std_single_instance_2.cpp)
system_run(std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp)
boost_test(SOURCES std_single_instance_test.cpp NAME std_single_instance_test_lib LINK_LIBRARIES boost_system_std_single_instance_lib1 boost_system_std_single_instance_lib2)
boost_test(TYPE run SOURCES is_error_code_enum_test.cpp)
boost_test(TYPE run SOURCES is_error_condition_enum_test.cpp)
boost_test(TYPE run SOURCES errc_test.cpp)
boost_test(TYPE run SOURCES errc_test2.cpp)
boost_test(TYPE run SOURCES error_category_test2.cpp)
boost_test(TYPE run SOURCES error_condition_test.cpp)
boost_test(TYPE run SOURCES error_condition_test2.cpp)
boost_test(TYPE run SOURCES generic_category_test2.cpp)
boost_test(TYPE run SOURCES generic_category_test3.cpp)
boost_test(TYPE run SOURCES system_category_test2.cpp)
boost_test(TYPE run SOURCES system_category_test3.cpp)
boost_test(TYPE run SOURCES windows_error_test.cpp)
boost_test(TYPE run SOURCES cygwin_error_test.cpp)
boost_test(TYPE run SOURCES linux_error_test.cpp)
boost_test(TYPE link SOURCES errc_test3.cpp)
boost_test(TYPE run SOURCES snprintf_test.cpp)
boost_test(TYPE run SOURCES std_interop_test2.cpp)
boost_test(TYPE run SOURCES std_interop_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test4.cpp)
boost_test(TYPE run SOURCES std_interop_test5.cpp)
boost_test(TYPE run SOURCES std_interop_test6.cpp)
boost_test(TYPE run SOURCES std_interop_test7.cpp)
boost_test(TYPE run SOURCES std_interop_test8.cpp)
boost_test(TYPE run SOURCES std_interop_test9.cpp)
boost_test(TYPE run SOURCES ec_location_test.cpp)
boost_test(TYPE run SOURCES error_condition_test3.cpp)
boost_test(TYPE run SOURCES error_code_test2.cpp)
boost_test(TYPE run SOURCES system_error_test2.cpp)
boost_test(TYPE run SOURCES std_interop_test10.cpp)
boost_test(TYPE run SOURCES ec_location_test2.cpp)
boost_test(TYPE run SOURCES ec_what_test.cpp)
boost_test(TYPE run SOURCES system_error_test3.cpp)
boost_test(TYPE run SOURCES std_interop_test11.cpp)
boost_test(TYPE run SOURCES ec_wstream_test.cpp)
boost_test(TYPE run SOURCES std_interop_test12.cpp)
boost_test(TYPE run SOURCES errc_test4.cpp)
boost_test(TYPE run SOURCES std_interop_test13.cpp)
boost_test(TYPE run SOURCES std_interop_test14.cpp)
boost_test(TYPE run SOURCES ec_location_test3.cpp)
boost_test(TYPE run SOURCES ec_location_test4.cpp)
# result
set(BOOST_TEST_COMPILE_FEATURES cxx_std_11)
boost_test(TYPE run SOURCES result_default_construct.cpp)
boost_test(TYPE run SOURCES result_value_construct.cpp)
boost_test(TYPE run SOURCES result_error_construct.cpp)
boost_test(TYPE run SOURCES result_copy_construct.cpp)
boost_test(TYPE run SOURCES result_move_construct.cpp)
boost_test(TYPE run SOURCES result_copy_assign.cpp)
boost_test(TYPE run SOURCES result_move_assign.cpp)
boost_test(TYPE run SOURCES result_value_access.cpp)
boost_test(TYPE run SOURCES result_error_access.cpp)
boost_test(TYPE run SOURCES result_swap.cpp)
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)

View File

@ -1,43 +1,176 @@
# Boost System Library test Jamfile
# Copyright Beman Dawes 2003, 2006
# Copyright 2017-2021 Peter Dimov
# Distributed under the Boost Software License, Version 1.0.
# See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt
# See library home page at http://www.boost.org/libs/system
project
: requirements
<library>/boost/system//boost_system
<toolset>msvc:<asynch-exceptions>on
;
import testing ;
test-suite "system"
: [ run error_code_test.cpp
: # command line
: # input files
: # requirements
<link>static
]
[ run error_code_test.cpp
: : : : error_code_test_dll
]
[ run error_code_user_test.cpp
: : : <link>static
]
[ run error_code_user_test.cpp
: : : : error_code_user_test_dll
]
[ run system_error_test.cpp
: : : <link>static
]
[ run system_error_test.cpp
: : : : system_error_test_dll
]
[ run initialization_test.cpp
]
[ run header_only_test.cpp
: : : <link>static
]
;
project
: default-build
<warnings>extra
: requirements
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on
<toolset>gcc-4.4:<cxxflags>-Wno-sign-compare
;
rule system-run ( sources + )
{
local result ;
result += [ run $(sources) ] ;
result += [ run $(sources) : : : <library>/boost/system//boost_system <link>static : $(sources[1]:B)_static ] ;
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 ] ;
return $(result) ;
}
system-run error_code_test.cpp ;
system-run error_code_user_test.cpp ;
system-run system_error_test.cpp ;
lib throw_test : throw_test.cpp : <link>shared:<define>THROW_DYN_LINK=1 ;
run dynamic_link_test.cpp throw_test : : : <link>shared : throw_test_shared ;
system-run initialization_test.cpp ;
system-run header_only_test.cpp ;
run config_test.cpp : : : <test-info>always_show_run_output ;
system-run std_interop_test.cpp ;
system-run std_mismatch_test.cpp ;
lib single_instance_lib1 : single_instance_1.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
lib single_instance_lib2 : single_instance_2.cpp : <link>shared:<define>SINGLE_INSTANCE_DYN_LINK ;
system-run single_instance_test.cpp single_instance_1.cpp single_instance_2.cpp ;
run single_instance_test.cpp single_instance_lib1 single_instance_lib2 : : : <link>static : single_instance_lib_static ;
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 : : :
# 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 ;
system-run error_category_test.cpp ;
system-run generic_category_test.cpp ;
system-run system_category_test.cpp ;
system-run after_main_test.cpp ;
system-run failed_test.cpp ;
system-run failed_constexpr_test.cpp ;
# Quick (CI) test
run quick.cpp ;
run warnings_test.cpp
: : : <warnings>pedantic
<toolset>msvc:<warnings-as-errors>on
<toolset>gcc:<warnings-as-errors>on
<toolset>clang:<warnings-as-errors>on ;
lib std_single_instance_lib1 : std_single_instance_1.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
lib std_single_instance_lib2 : std_single_instance_2.cpp : <link>shared:<define>STD_SINGLE_INSTANCE_DYN_LINK ;
system-run std_single_instance_test.cpp std_single_instance_1.cpp std_single_instance_2.cpp ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>static : std_single_instance_lib_static ;
run std_single_instance_test.cpp std_single_instance_lib1 std_single_instance_lib2 : : : <link>shared <define>STD_SINGLE_INSTANCE_SHARED : std_single_instance_lib_shared ;
run is_error_code_enum_test.cpp ;
run is_error_condition_enum_test.cpp ;
run errc_test.cpp ;
run errc_test2.cpp ;
run error_category_test2.cpp ;
run error_condition_test.cpp ;
run error_condition_test2.cpp ;
run generic_category_test2.cpp ;
run generic_category_test3.cpp ;
run system_category_test2.cpp ;
run system_category_test3.cpp ;
run windows_error_test.cpp ;
run cygwin_error_test.cpp ;
run linux_error_test.cpp ;
link errc_test3.cpp ;
run snprintf_test.cpp ;
run std_interop_test2.cpp ;
run std_interop_test3.cpp ;
run std_interop_test4.cpp ;
run std_interop_test5.cpp
: : :
# crash on xenial, but the real g++ 4.8 on both centos 7 and trusty works
<toolset>gcc-4.8:<build>no
<toolset>gcc-4.9:<build>no
;
run std_interop_test6.cpp ;
run std_interop_test7.cpp ;
run std_interop_test8.cpp ;
run std_interop_test9.cpp ;
run ec_location_test.cpp ;
run error_condition_test3.cpp ;
run error_code_test2.cpp ;
run system_error_test2.cpp ;
run std_interop_test10.cpp ;
run ec_location_test2.cpp ;
run ec_what_test.cpp ;
run system_error_test3.cpp ;
run std_interop_test11.cpp ;
run ec_wstream_test.cpp ;
run std_interop_test12.cpp ;
run errc_test4.cpp ;
run std_interop_test13.cpp ;
run std_interop_test14.cpp ;
run ec_location_test3.cpp ;
run ec_location_test4.cpp ;
# result
import ../../config/checks/config : requires ;
CPP11 = [ requires cxx11_variadic_templates cxx11_template_aliases cxx11_decltype cxx11_constexpr cxx11_noexcept ] <toolset>gcc-4.7:<build>no ;
run result_default_construct.cpp : : : $(CPP11) ;
run result_value_construct.cpp : : : $(CPP11) ;
run result_error_construct.cpp : : : $(CPP11) ;
run result_copy_construct.cpp : : : $(CPP11) ;
run result_move_construct.cpp : : : $(CPP11) ;
run result_copy_assign.cpp : : : $(CPP11) ;
run result_move_assign.cpp : : : $(CPP11) ;
run result_value_access.cpp : : : $(CPP11) ;
run result_error_access.cpp : : : $(CPP11) ;
run result_swap.cpp : : : $(CPP11) <toolset>gcc-10:<cxxflags>"-Wno-maybe-uninitialized" ;
run result_eq.cpp : : : $(CPP11) ;
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) ;

37
test/after_main_test.cpp Normal file
View File

@ -0,0 +1,37 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/core/quick_exit.hpp>
#include <boost/config.hpp>
#include <cerrno>
#if defined(BOOST_MSVC)
# pragma warning(disable: 4722) // Z::~Z never returns
#endif
using namespace boost::system;
struct Z
{
~Z()
{
BOOST_TEST_CSTR_EQ( generic_category().name(), "generic" );
BOOST_TEST_CSTR_EQ( system_category().name(), "system" );
boost::quick_exit( boost::report_errors() );
}
};
static Z z;
static error_code e1( 1, system_category() );
static error_code e2( ENOENT, generic_category() );
int main()
{
(void)e1;
(void)e2;
}

30
test/before_main_test.cpp Normal file
View File

@ -0,0 +1,30 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
using namespace boost::system;
static error_code e1( 1, system_category() );
static std::string m1 = e1.message();
static error_code e2( ENOENT, generic_category() );
static std::string m2 = e2.message();
int main()
{
error_code e1_( 1, system_category() );
BOOST_TEST_EQ( e1, e1_ );
BOOST_TEST_EQ( m1, e1_.message() );
error_code e2_( ENOENT, generic_category() );
BOOST_TEST_EQ( e2, e2_ );
BOOST_TEST_EQ( m2, e2_.message() );
return boost::report_errors();
}

View File

@ -0,0 +1,17 @@
# Copyright 2018, 2019 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
cmake_minimum_required(VERSION 3.5...3.16)
project(cmake_install_test LANGUAGES CXX)
find_package(boost_system REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main Boost::system)
enable_testing()
add_test(main main)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure -C $<CONFIG>)

View File

@ -0,0 +1,44 @@
// Copyright 2017, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/system.hpp>
#include <cassert>
#include <cerrno>
#define BOOST_TEST(expr) assert(expr)
#define BOOST_TEST_EQ(x1, x2) assert((x1)==(x2))
int main()
{
boost::system::error_category const & bt = boost::system::generic_category();
int ev = ENOENT;
boost::system::error_code bc( ev, bt );
BOOST_TEST_EQ( bc.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::error_condition bn = bt.default_error_condition( ev );
BOOST_TEST_EQ( bn.value(), ev );
BOOST_TEST_EQ( &bn.category(), &bt );
BOOST_TEST( bt.equivalent( ev, bn ) );
BOOST_TEST( bc == bn );
boost::system::error_code bc2 = make_error_code( boost::system::errc::no_such_file_or_directory );
BOOST_TEST_EQ( bc2, bc );
BOOST_TEST_EQ( bc2.value(), ev );
BOOST_TEST_EQ( &bc.category(), &bt );
boost::system::system_error x( bc, "prefix" );
BOOST_TEST_EQ( x.code(), bc );
BOOST_TEST_EQ( std::string( x.what() ), "prefix: " + bc.what() );
}

View File

@ -0,0 +1,26 @@
# 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
cmake_minimum_required(VERSION 3.5...3.20)
project(cmake_subdir_test LANGUAGES CXX)
add_subdirectory(../.. boostorg/system)
add_subdirectory(../../../assert boostorg/assert)
add_subdirectory(../../../config boostorg/config)
add_subdirectory(../../../core boostorg/core)
add_subdirectory(../../../mp11 boostorg/mp11)
add_subdirectory(../../../predef boostorg/predef)
add_subdirectory(../../../static_assert boostorg/static_assert)
add_subdirectory(../../../throw_exception boostorg/throw_exception)
add_subdirectory(../../../variant2 boostorg/variant2)
add_subdirectory(../../../winapi boostorg/winapi)
add_executable(quick ../quick.cpp)
target_link_libraries(quick Boost::system Boost::core)
enable_testing()
add_test(quick quick)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure --no-tests=error -C $<CONFIG>)

65
test/config_test.cpp Normal file
View File

@ -0,0 +1,65 @@
// error_code_test.cpp ---------------------------------------------------------------//
// Copyright Beman Dawes 2014
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
// See library home page at http://www.boost.org/libs/system
#include <boost/system/config.hpp>
#include <iostream>
using std::cout;
using std::endl;
int main()
{
#ifdef BOOST_WINDOWS_API
std::cout << "BOOST_WINDOWS_API is defined" << std::endl;
#else
std::cout << "BOOST_WINDOWS_API is not defined" << std::endl;
#endif
#ifdef _MSC_VER
std::cout << "_MSC_VER is defined as " << _MSC_VER << std::endl;
#else
std::cout << "_MSC_VER is not defined" << std::endl;
#endif
#ifdef __CYGWIN__
std::cout << "__CYGWIN__ is defined" << std::endl;
#else
std::cout << "__CYGWIN__ is not defined" << std::endl;
#endif
#ifdef __MINGW32__
std::cout << "__MINGW32__ is defined" << std::endl;
#else
std::cout << "__MINGW32__ is not defined" << std::endl;
#endif
#ifdef BOOST_POSIX_API
std::cout << "BOOST_POSIX_API is defined" << std::endl;
#else
std::cout << "BOOST_POSIX_API is not defined" << std::endl;
#endif
#ifdef BOOST_PLAT_WINDOWS_DESKTOP
std::cout << "BOOST_PLAT_WINDOWS_DESKTOP is defined as "
<< BOOST_PLAT_WINDOWS_DESKTOP << std::endl;
#else
std::cout << "BOOST_PLAT_WINDOWS_DESKTOP is not defined" << std::endl;
#endif
#ifdef BOOST_NO_ANSI_APIS
std::cout << "BOOST_NO_ANSI_APIS is defined" << std::endl;
#else
std::cout << "BOOST_NO_ANSI_APIS is not defined" << std::endl;
#endif
#ifdef BOOST_NO_CXX11_NOEXCEPT
std::cout << "BOOST_NO_CXX11_NOEXCEPT is defined" << std::endl;
#else
std::cout << "BOOST_NO_CXX11_NOEXCEPT is not defined" << std::endl;
#endif
#ifdef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is defined" << std::endl;
#else
std::cout << "BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS is not defined" << std::endl;
#endif
return 0;
}

68
test/constexpr_test.cpp Normal file
View File

@ -0,0 +1,68 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/static_assert.hpp>
#include <boost/config.hpp>
#include <boost/config/workaround.hpp>
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Skipping constexpr test, BOOST_SYSTEM_HAS_CONSTEXPR isn't defined")
int main() {}
#else
using namespace boost::system;
constexpr error_code e1( 1, system_category() );
BOOST_STATIC_ASSERT( e1.value() == 1 );
BOOST_STATIC_ASSERT( e1.category() == system_category() );
BOOST_STATIC_ASSERT( e1 );
BOOST_STATIC_ASSERT( e1 == e1 );
constexpr error_code e2( 2, generic_category() );
BOOST_STATIC_ASSERT( e2.value() == 2 );
BOOST_STATIC_ASSERT( e2.category() == generic_category() );
BOOST_STATIC_ASSERT( e2 );
BOOST_STATIC_ASSERT( e2 == e2 );
#if !BOOST_WORKAROUND(BOOST_GCC, < 80200)
BOOST_STATIC_ASSERT( e1 != e2 );
#endif
constexpr error_code e3;
BOOST_STATIC_ASSERT( e3.value() == 0 );
BOOST_STATIC_ASSERT( e3.category() == system_category() );
BOOST_STATIC_ASSERT( !e3 );
BOOST_STATIC_ASSERT( e3 == e3 );
#if !BOOST_WORKAROUND(BOOST_GCC, < 80200)
BOOST_STATIC_ASSERT( e1 != e3 );
#endif
int main()
{
error_code e1_( 1, system_category() );
BOOST_TEST_EQ( e1, e1_ );
error_code e2_( 2, generic_category() );
BOOST_TEST_EQ( e2, e2_ );
error_code e3_;
BOOST_TEST_EQ( e3, e3_ );
return boost::report_errors();
}
#endif

View File

@ -0,0 +1,29 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/system/cygwin_error.hpp>
#include <boost/config/pragma_message.hpp>
#if !defined(__CYGWIN__)
BOOST_PRAGMA_MESSAGE( "Skipping test, __CYGWIN__ is not defined" )
int main() {}
#else
#include <boost/core/lightweight_test.hpp>
int main()
{
namespace sys = boost::system;
sys::error_code ec = sys::cygwin_error::no_package;
BOOST_TEST_EQ( ec, sys::cygwin_error::no_package );
BOOST_TEST_EQ( ec, sys::error_code( ENOPKG, sys::system_category() ) );
return boost::report_errors();
}
#endif

View File

@ -0,0 +1,47 @@
// dynamic_link_test.cpp -------------------------------------------------------------//
// Copyright Beman Dawes 2010
// Distributed under the Boost Software License, Version 1.0.
// See www.boost.org/LICENSE_1_0.txt
// Library home page is www.boost.org/libs/system
//--------------------------------------------------------------------------------------//
// Dynamic link libraries (DLL's), also know as dynamic shared objects (DSO's),
// can cause symbol visability problems unless carefully configured. One of the
// manifestations, particularly with GCC, is that a system_error exception thrown from
// a DLL or DSO is not caught.
//
// The purpose of this program is to test for that error.
//--------------------------------------------------------------------------------------//
#include <boost/system/system_error.hpp>
#include <iostream>
void throw_test();
int main()
{
try
{
throw_test();
}
catch (const boost::system::system_error& ex)
{
std::cout << " caught boost::system::system_error as expected\n";
std::cout << " what() reports " << ex.what() << '\n';
return 0;
}
catch (const std::runtime_error& ex)
{
std::cout << " error: caught std::runtime_error instead of boost::system::system_error\n";
std::cout << " what() reports " << ex.what() << '\n';
return 1;
}
std::cout << " error: failed to catch boost::system::system_error\n";
return 1;
}

116
test/ec_location_test.cpp Normal file
View File

@ -0,0 +1,116 @@
// Copyright 2021 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( val, cat );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
boost::system::error_code ec( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 27 );
}
{
boost::system::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &boost::system::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = boost::system::error_code( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 51 );
}
{
boost::system::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &boost::system::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 75 );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code e2( val, std::generic_category() );
boost::system::error_code ec( e2 );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( val, cat, &loc );
BOOST_TEST_EQ( ec.value(), val );
BOOST_TEST_EQ( &ec.category(), &cat );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 100 );
}
#endif
return boost::report_errors();
}

287
test/ec_location_test2.cpp Normal file
View File

@ -0,0 +1,287 @@
// Copyright 2021 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>
namespace sys = boost::system;
enum E
{
none = 0,
einval = EINVAL
};
namespace boost
{
namespace system
{
template<> struct is_error_code_enum< ::E >
{
static const bool value = true;
};
} // namespace system
} // namespace boost
sys::error_code make_error_code( E e )
{
return e == 0? sys::error_code(): sys::error_code( e, sys::generic_category() );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
enum E2
{
e2inval = EINVAL
};
namespace boost
{
namespace system
{
template<> struct is_error_code_enum< ::E2 >
{
static const bool value = true;
};
} // namespace system
} // namespace boost
std::error_code make_error_code( E2 e )
{
return std::error_code( e, std::generic_category() );
}
#endif
int main()
{
{
sys::error_code ec( einval );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 77 );
}
{
sys::error_code ec( none );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 127 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( einval, &loc );
BOOST_TEST_EQ( ec.value(), EINVAL );
BOOST_TEST_EQ( &ec.category(), &sys::generic_category() );
BOOST_TEST( ec.failed() );
BOOST_TEST( ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 175 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( none, &loc );
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
sys::error_code ec( e2inval );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec = sys::error_code( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST_EQ( &ec.category(), &sys::system_category() );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
ec.assign( e2inval, &loc );
BOOST_TEST_EQ( ec, std::error_code( EINVAL, std::generic_category() ) );
BOOST_TEST( ec.failed() );
BOOST_TEST( !ec.has_location() );
BOOST_TEST_EQ( ec.location().line(), 0 );
}
#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();
}

91
test/ec_what_test.cpp Normal file
View File

@ -0,0 +1,91 @@
// Copyright 2020, 2021 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>
namespace sys = boost::system;
int main()
{
{
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:0]" );
}
{
sys::error_code ec( 5, sys::generic_category() );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::generic_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5]" );
}
{
sys::error_code ec( 5, sys::system_category() );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5]" );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::generic_category(), &loc );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::generic_category() );
BOOST_TEST_EQ( &ec.location(), &loc );
BOOST_TEST_EQ( ec.what(), ec.message() + " [generic:5 at " + loc.to_string() + "]" );
}
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
sys::error_code ec( 5, sys::system_category(), &loc );
BOOST_TEST_EQ( ec.value(), 5 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( &ec.location(), &loc );
BOOST_TEST_EQ( ec.what(), ec.message() + " [system:5 at " + loc.to_string() + "]" );
}
#if defined(BOOST_SYSTEM_HAS_SYSTEM_ERROR)
{
std::error_code ec;
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:0]" );
}
{
std::error_code ec( 5, std::generic_category() );
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:generic:5]" );
}
{
std::error_code ec( 5, std::system_category() );
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.what(), ec2.message() + " [std:system:5]" );
}
#endif
return boost::report_errors();
}

21
test/ec_wstream_test.cpp Normal file
View File

@ -0,0 +1,21 @@
// 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/core/lightweight_test.hpp>
#include <sstream>
namespace sys = boost::system;
int main()
{
{
std::wostringstream os;
os << sys::error_code();
BOOST_TEST( os.str() == L"system:0" );
}
return boost::report_errors();
}

18
test/errc_test.cpp Normal file
View File

@ -0,0 +1,18 @@
// Copyright 2020 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/system/is_error_condition_enum.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::success ), 0 );
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::no_such_file_or_directory ), ENOENT );
BOOST_TEST_EQ( static_cast<int>( boost::system::errc::address_family_not_supported ), EAFNOSUPPORT );
BOOST_TEST( boost::system::is_error_condition_enum< boost::system::errc::errc_t >::value );
return boost::report_errors();
}

20
test/errc_test2.cpp Normal file
View File

@ -0,0 +1,20 @@
// Copyright 2020 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/core/lightweight_test.hpp>
int main()
{
BOOST_TEST_EQ( make_error_code( boost::system::errc::success ).value(), 0 );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::success ).value(), 0 );
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::no_such_file_or_directory ).value(), ENOENT );
BOOST_TEST_EQ( make_error_code( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
BOOST_TEST_EQ( make_error_condition( boost::system::errc::address_family_not_supported ).value(), EAFNOSUPPORT );
return boost::report_errors();
}

34
test/errc_test3.cpp Normal file
View File

@ -0,0 +1,34 @@
// Copyright 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
int main()
{
make_error_code( boost::system::errc::success ).value();
make_error_code( boost::system::errc::success ).category();
make_error_code( boost::system::errc::success ).default_error_condition();
make_error_code( boost::system::errc::success ).message();
make_error_code( boost::system::errc::success ).failed();
make_error_code( boost::system::errc::success ).clear();
make_error_condition( boost::system::errc::success ).value();
make_error_condition( boost::system::errc::success ).category();
make_error_condition( boost::system::errc::success ).message();
make_error_condition( boost::system::errc::success ).failed();
make_error_condition( boost::system::errc::success ).clear();
make_error_code( boost::system::errc::no_such_file_or_directory ).value();
make_error_code( boost::system::errc::no_such_file_or_directory ).category();
make_error_code( boost::system::errc::no_such_file_or_directory ).default_error_condition();
make_error_code( boost::system::errc::no_such_file_or_directory ).message();
make_error_code( boost::system::errc::no_such_file_or_directory ).failed();
make_error_code( boost::system::errc::no_such_file_or_directory ).clear();
make_error_condition( boost::system::errc::no_such_file_or_directory ).value();
make_error_condition( boost::system::errc::no_such_file_or_directory ).category();
make_error_condition( boost::system::errc::no_such_file_or_directory ).message();
make_error_condition( boost::system::errc::no_such_file_or_directory ).failed();
make_error_condition( boost::system::errc::no_such_file_or_directory ).clear();
}

17
test/errc_test4.cpp Normal file
View File

@ -0,0 +1,17 @@
// Copyright 2022 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/errc.hpp>
#include <boost/assert/source_location.hpp>
#include <boost/core/lightweight_test.hpp>
int main()
{
BOOST_STATIC_CONSTEXPR boost::source_location loc = BOOST_CURRENT_LOCATION;
BOOST_TEST( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).has_location() );
BOOST_TEST_EQ( make_error_code( boost::system::errc::no_such_file_or_directory, &loc ).location().to_string(), loc.to_string() );
return boost::report_errors();
}

View File

@ -0,0 +1,82 @@
// Copyright 2018 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
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
//
namespace sys = boost::system;
class user_category: public sys::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
return buffer;
}
using sys::error_category::message;
};
static user_category s_cat_1;
static user_category s_cat_2;
int main()
{
// default_error_condition
BOOST_TEST( s_cat_1.default_error_condition( 1 ) == sys::error_condition( 1, s_cat_1 ) );
BOOST_TEST( s_cat_2.default_error_condition( 2 ) == sys::error_condition( 2, s_cat_2 ) );
// equivalent
BOOST_TEST( s_cat_1.equivalent( 1, sys::error_condition( 1, s_cat_1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, sys::error_condition( 2, s_cat_1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, sys::error_condition( 2, s_cat_2 ) ) );
// the other equivalent
BOOST_TEST( s_cat_1.equivalent( sys::error_code( 1, s_cat_1 ), 1 ) );
BOOST_TEST( !s_cat_1.equivalent( sys::error_code( 1, s_cat_1 ), 2 ) );
BOOST_TEST( !s_cat_1.equivalent( sys::error_code( 1, s_cat_2 ), 1 ) );
// message
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), s_cat_1.message( 1 ).c_str() );
}
{
char buffer[ 4 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), "use" );
}
// ==
BOOST_TEST_NOT( s_cat_1 == s_cat_2 );
BOOST_TEST( s_cat_1 != s_cat_2 );
return boost::report_errors();
}

View File

@ -0,0 +1,79 @@
// Copyright 2018, 2020 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
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_category.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
//
namespace sys = boost::system;
class user_category: public sys::error_category
{
public:
virtual const char * name() const BOOST_NOEXCEPT
{
return "user";
}
virtual std::string message( int ev ) const
{
char buffer[ 256 ];
std::sprintf( buffer, "user message %d", ev );
return buffer;
}
using sys::error_category::message;
};
static user_category s_cat_1;
static user_category s_cat_2;
int main()
{
// default_error_condition
BOOST_TEST( s_cat_1.default_error_condition( 1 ).value() == 1 );
BOOST_TEST( s_cat_1.default_error_condition( 1 ).category() == s_cat_1 );
BOOST_TEST( s_cat_2.default_error_condition( 2 ).value() == 2 );
BOOST_TEST( s_cat_2.default_error_condition( 2 ).category() == s_cat_2 );
// equivalent
BOOST_TEST( s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 1 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_1.default_error_condition( 2 ) ) );
BOOST_TEST( !s_cat_1.equivalent( 1, s_cat_2.default_error_condition( 2 ) ) );
// message
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), s_cat_1.message( 1 ).c_str() );
}
{
char buffer[ 4 ];
BOOST_TEST_CSTR_EQ( s_cat_1.message( 1, buffer, sizeof( buffer ) ), "use" );
}
// ==
BOOST_TEST_NOT( s_cat_1 == s_cat_2 );
BOOST_TEST( s_cat_1 != s_cat_2 );
return boost::report_errors();
}

View File

@ -7,15 +7,12 @@
// See library home page at http://www.boost.org/libs/system
//----------------------------------------------------------------------------//
//----------------------------------------------------------------------------//
#include <boost/config/warning_disable.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
#include <boost/system/cygwin_error.hpp>
#include <boost/system/linux_error.hpp>
#include <boost/system/windows_error.hpp>
#include <boost/core/lightweight_test.hpp>
#include <iostream>
#include <sstream>
#include <string>
@ -27,14 +24,20 @@
// with a boost::system using directive increases use scenario coverage.
using namespace boost::system;
# if defined( BOOST_WINDOWS_API )
# include "winerror.h"
# define BOOST_ACCESS_ERROR_MACRO ERROR_ACCESS_DENIED
# elif defined( BOOST_POSIX_API )
# define BOOST_ACCESS_ERROR_MACRO EACCES
# else
# error "Only supported for POSIX and Windows"
# endif
#if defined( BOOST_WINDOWS_API )
// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on
// either of those platforms include the full windows.h
# if defined(__MINGW32__) || defined(__CYGWIN__)
# include <windows.h>
# else
# include <winerror.h>
# endif
# define BOOST_ACCESS_ERROR_MACRO ERROR_ACCESS_DENIED
#elif defined( BOOST_POSIX_API )
# define BOOST_ACCESS_ERROR_MACRO EACCES
#else
# error "Only supported for POSIX and Windows"
#endif
namespace
{
@ -47,6 +50,53 @@ namespace
ss >> s;
BOOST_TEST( s == expected );
}
// throws_function_test ------------------------------------------------------------//
// usage example
int divide(int dividend, int divisor, boost::system::error_code& ec = boost::throws())
{
if (divisor == 0) // is there an error?
{
if (&ec == &boost::throws()) // throw on error
throw "oops!"; // whatever exception you prefer
ec = error_code(EDOM, generic_category()); // report error via error_code
return 0;
}
if (&ec != &boost::throws()) // error reporting via error_code
ec.clear();
return dividend / divisor;
}
// test usage example
void test_throws_usage()
{
std::cout << "Test throws() example and usage...\n";
error_code ec;
// no error tests
BOOST_TEST_EQ((divide(10, 2)), 5); // no error, report via exception
ec = make_error_code(errc::argument_out_of_domain);
BOOST_TEST_EQ((divide(10, 5, ec)), 2); // no error, report via error_code
BOOST_TEST(!ec);
ec = make_error_code(errc::argument_out_of_domain);
BOOST_TEST_EQ((divide(10, 0, ec)), 0); // error, report via error_code
BOOST_TEST(ec);
bool exception_thrown = false;
try
{ divide(10, 0); } // error, report via exception
catch (...)
{ exception_thrown = true; }
BOOST_TEST(exception_thrown);
//error_code should_fail(boost::throws()); // should fail at runtime
//boost::throws() = ec; // should fail at runtime
}
}
// main ------------------------------------------------------------------------------//
@ -56,55 +106,52 @@ namespace
int main( int, char ** )
{
std::cout << "Conversion use cases...\n";
error_condition x1( errc::file_exists );
(void)x1;
//error_code x2( errc::file_exists ); // should fail to compile
make_error_code(errc::file_exists);
make_error_condition(errc::file_exists);
std::cout << "General tests...\n";
// unit tests:
BOOST_TEST( posix_category == posix_category );
BOOST_TEST( system_category == system_category );
BOOST_TEST( posix_category != system_category );
BOOST_TEST( system_category != posix_category );
if ( std::less<const error_category*>()( &posix_category, &system_category ) )
{
BOOST_TEST( posix_category < system_category );
BOOST_TEST( !(system_category < posix_category) );
}
else
{
BOOST_TEST( system_category < posix_category );
BOOST_TEST( !(posix_category < system_category) );
}
BOOST_TEST( generic_category() == generic_category() );
BOOST_TEST( system_category() == system_category() );
BOOST_TEST( generic_category() != system_category() );
BOOST_TEST( system_category() != generic_category() );
BOOST_TEST_NE( generic_category() < system_category(), system_category() < generic_category() );
error_code ec;
error_condition dec;
error_condition econd;
BOOST_TEST( !ec );
BOOST_TEST( ec.value() == 0 );
dec = ec.default_error_condition();
BOOST_TEST( dec.value() == 0 );
BOOST_TEST( dec.category() == posix_category );
BOOST_TEST( ec == posix::success );
BOOST_TEST( ec.category() == system_category );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec == errc::success );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
BOOST_TEST( !(ec < error_code( 0, system_category )) );
BOOST_TEST( !(error_code( 0, system_category ) < ec) );
BOOST_TEST( ec < error_code( 1, system_category ) );
BOOST_TEST( !(error_code( 1, system_category ) < ec) );
BOOST_TEST( !(ec < error_code( 0, system_category() )) );
BOOST_TEST( !(error_code( 0, system_category() ) < ec) );
BOOST_TEST( ec < error_code( 1, system_category() ) );
BOOST_TEST( !(error_code( 1, system_category() ) < ec) );
error_code ec_0_system( 0, system_category );
error_code ec_0_system( 0, system_category() );
BOOST_TEST( !ec_0_system );
BOOST_TEST( ec_0_system.value() == 0 );
dec = ec_0_system.default_error_condition();
BOOST_TEST( dec.value() == 0 );
BOOST_TEST( dec.category() == posix_category );
BOOST_TEST( ec_0_system == posix::success );
BOOST_TEST( ec_0_system.category() == system_category );
econd = ec_0_system.default_error_condition();
BOOST_TEST( econd.value() == 0 );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( ec_0_system == errc::success );
BOOST_TEST( ec_0_system.category() == system_category() );
BOOST_TEST( std::strcmp( ec_0_system.category().name(), "system") == 0 );
check_ostream( ec_0_system, "system:0" );
BOOST_TEST( ec_0_system == ec );
error_code ec_1_system( 1, system_category );
error_code ec_1_system( 1, system_category() );
BOOST_TEST( ec_1_system );
BOOST_TEST( ec_1_system.value() == 1 );
BOOST_TEST( ec_1_system.value() != 0 );
@ -112,41 +159,44 @@ int main( int, char ** )
BOOST_TEST( ec_0_system != ec_1_system );
check_ostream( ec_1_system, "system:1" );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec );
BOOST_TEST( ec.value() == BOOST_ACCESS_ERROR_MACRO );
dec = ec.default_error_condition();
BOOST_TEST( dec.value() == static_cast<int>(posix::permission_denied) );
BOOST_TEST( dec.category() == posix_category );
BOOST_TEST( dec == error_condition( posix::permission_denied, posix_category ) );
BOOST_TEST( dec == posix::permission_denied );
BOOST_TEST( posix::permission_denied == dec );
BOOST_TEST( ec == posix::permission_denied );
BOOST_TEST( ec.category() == system_category );
econd = ec.default_error_condition();
BOOST_TEST( econd.value() == static_cast<int>(errc::permission_denied) );
BOOST_TEST( econd.category() == generic_category() );
BOOST_TEST( econd == error_condition( errc::permission_denied, generic_category() ) );
BOOST_TEST( econd == errc::permission_denied );
BOOST_TEST( errc::permission_denied == econd );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.category() == system_category() );
BOOST_TEST( std::strcmp( ec.category().name(), "system") == 0 );
// test the explicit make_error_code conversion for posix
ec = make_error_code( posix::bad_message );
// test the explicit make_error_code conversion for errc
ec = make_error_code( errc::bad_message );
BOOST_TEST( ec );
BOOST_TEST( ec == posix::bad_message );
BOOST_TEST( posix::bad_message == ec );
BOOST_TEST( ec != posix::permission_denied );
BOOST_TEST( posix::permission_denied != ec );
BOOST_TEST( ec.category() == posix_category );
BOOST_TEST( ec == errc::bad_message );
BOOST_TEST( errc::bad_message == ec );
BOOST_TEST( ec != errc::permission_denied );
BOOST_TEST( errc::permission_denied != ec );
BOOST_TEST( ec.category() == generic_category() );
// test the deprecated predefined error_category synonyms
BOOST_TEST( &system_category == &native_ecat );
BOOST_TEST( &posix_category == &errno_ecat );
BOOST_TEST( system_category == native_ecat );
BOOST_TEST( posix_category == errno_ecat );
//// test the deprecated predefined error_category synonyms
//BOOST_TEST( &system_category() == &native_ecat );
//BOOST_TEST( &generic_category() == &errno_ecat );
//BOOST_TEST( system_category() == native_ecat );
//BOOST_TEST( generic_category() == errno_ecat );
// test error_code and error_condition message();
// see Boost.Filesystem operations_test for code specific message() tests
ec = error_code( -1, system_category );
ec = error_code( -1, system_category() );
std::cout << "error_code message for -1 is \"" << ec.message() << "\"\n";
std::cout << "error_code message for 0 is \"" << ec_0_system.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
// Fails when the language isn't US English
// BOOST_TEST( ec_0_system.message().substr(0,36) == "The operation completed successfully" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( ec.message().substr(0,13) == "Unknown error" );
@ -158,108 +208,91 @@ int main( int, char ** )
BOOST_TEST( ec.message() == "error -1" );
#endif
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category );
ec = error_code( BOOST_ACCESS_ERROR_MACRO, system_category() );
BOOST_TEST( ec.message() != "" );
BOOST_TEST( ec.message().substr( 0, 13) != "Unknown error" );
dec = error_condition( -1, posix_category );
std::cout << "error_condition message for -1 is \"" << dec.message() << "\"\n";
econd = error_condition( -1, generic_category() );
error_condition econd_ok;
std::cout << "error_condition message for -1 is \"" << econd.message() << "\"\n";
std::cout << "error_condition message for 0 is \"" << econd_ok.message() << "\"\n";
#if defined(BOOST_WINDOWS_API)
// Borland appends newline, so just check text
BOOST_TEST( dec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd_ok.message().substr(0,8) == "No error" );
#elif defined(linux) || defined(__linux) || defined(__linux__)
// Linux appends value to message as unsigned, so it varies with # of bits
BOOST_TEST( dec.message().substr(0,13) == "Unknown error" );
BOOST_TEST( econd.message().substr(0,13) == "Unknown error" );
#elif defined(__hpux)
BOOST_TEST( dec.message() == "" );
BOOST_TEST( econd.message() == "" );
#elif defined(__osf__)
BOOST_TEST( dec.message() == "Error -1 occurred." );
BOOST_TEST( econd.message() == "Error -1 occurred." );
#elif defined(__vms)
BOOST_TEST( dec.message() == "error -1" );
BOOST_TEST( econd.message() == "error -1" );
#endif
dec = error_condition( BOOST_ACCESS_ERROR_MACRO, posix_category );
BOOST_TEST( dec.message() != "" );
BOOST_TEST( dec.message().substr( 0, 13) != "Unknown error" );
econd = error_condition( BOOST_ACCESS_ERROR_MACRO, generic_category() );
BOOST_TEST( econd.message() != "" );
BOOST_TEST( econd.message().substr( 0, 13) != "Unknown error" );
test_throws_usage();
#ifdef BOOST_WINDOWS_API
std::cout << "Windows tests...\n";
// these tests probe the Windows posix decoder
// these tests probe the Windows errc decoder
// test the first entry in the decoder table:
ec = error_code( ERROR_ACCESS_DENIED, system_category );
ec = error_code( ERROR_ACCESS_DENIED, system_category() );
BOOST_TEST( ec.value() == ERROR_ACCESS_DENIED );
BOOST_TEST( ec == posix::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the second entry in the decoder table:
ec = error_code( ERROR_ALREADY_EXISTS, system_category );
ec = error_code( ERROR_ALREADY_EXISTS, system_category() );
BOOST_TEST( ec.value() == ERROR_ALREADY_EXISTS );
BOOST_TEST( ec == posix::file_exists );
BOOST_TEST( ec.default_error_condition().value() == posix::file_exists );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
BOOST_TEST( ec == errc::file_exists );
BOOST_TEST( ec.default_error_condition().value() == errc::file_exists );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the third entry in the decoder table:
ec = error_code( ERROR_BAD_UNIT, system_category );
ec = error_code( ERROR_BAD_UNIT, system_category() );
BOOST_TEST( ec.value() == ERROR_BAD_UNIT );
BOOST_TEST( ec == posix::no_such_device );
BOOST_TEST( ec.default_error_condition().value() == posix::no_such_device );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
BOOST_TEST( ec == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().value() == errc::no_such_device );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last non-Winsock entry in the decoder table:
ec = error_code( ERROR_WRITE_PROTECT, system_category );
ec = error_code( ERROR_WRITE_PROTECT, system_category() );
BOOST_TEST( ec.value() == ERROR_WRITE_PROTECT );
BOOST_TEST( ec == posix::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test the last Winsock entry in the decoder table:
ec = error_code( WSAEWOULDBLOCK, system_category );
ec = error_code( WSAEWOULDBLOCK, system_category() );
BOOST_TEST( ec.value() == WSAEWOULDBLOCK );
BOOST_TEST( ec == posix::operation_would_block );
BOOST_TEST( ec.default_error_condition().value() == posix::operation_would_block );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
BOOST_TEST( ec == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().value() == errc::operation_would_block );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
// test not-in-table condition:
ec = error_code( 1234567890, system_category );
ec = error_code( 1234567890, system_category() );
BOOST_TEST( ec.value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().value() == 1234567890 );
BOOST_TEST( ec.default_error_condition().category() == system_category );
BOOST_TEST( ec.default_error_condition().category() == system_category() );
#else // POSIX
std::cout << "POSIX tests...\n";
ec = error_code( EACCES, system_category );
BOOST_TEST( ec == error_code( posix::permission_denied, system_category ) );
BOOST_TEST( error_code( posix::permission_denied, system_category ) == ec );
BOOST_TEST( ec == posix::permission_denied );
BOOST_TEST( posix::permission_denied == ec );
BOOST_TEST( ec.default_error_condition().value() == posix::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == posix_category );
# ifdef __CYGWIN__
std::cout << "Cygwin tests...\n";
ec = cygwin_error::no_package;
BOOST_TEST( ec == cygwin_error::no_package );
BOOST_TEST( ec == error_code( ENOPKG, system_category ) );
BOOST_TEST( ec == error_code( cygwin_error::no_package, system_category ) );
BOOST_TEST( ec.default_error_condition().category() == system_category );
# elif defined(linux) || defined(__linux) || defined(__linux__)
std::cout << "Linux tests...\n";
ec = linux_error::dot_dot_error;
BOOST_TEST( ec == linux_error::dot_dot_error );
BOOST_TEST( ec == error_code( EDOTDOT, system_category ) );
BOOST_TEST( ec == error_code( linux_error::dot_dot_error, system_category ) );
BOOST_TEST( ec.default_error_condition().category() == system_category );
# endif
ec = error_code( EACCES, system_category() );
BOOST_TEST( ec == error_code( errc::permission_denied, system_category() ) );
BOOST_TEST( error_code( errc::permission_denied, system_category() ) == ec );
BOOST_TEST( ec == errc::permission_denied );
BOOST_TEST( errc::permission_denied == ec );
BOOST_TEST( ec.default_error_condition().value() == errc::permission_denied );
BOOST_TEST( ec.default_error_condition().category() == generic_category() );
#endif
return ::boost::report_errors();
}

94
test/error_code_test2.cpp Normal file
View File

@ -0,0 +1,94 @@
// Copyright 2020, 2021 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>
namespace sys = boost::system;
int main()
{
char buffer[ 1024 ];
sys::error_code ec;
BOOST_TEST_EQ( ec.value(), 0 );
BOOST_TEST( ec.category() == sys::system_category() );
BOOST_TEST_EQ( ec.message(), ec.category().message( ec.value() ) );
BOOST_TEST_CSTR_EQ( ec.message( buffer, sizeof( buffer ) ), ec.category().message( ec.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec.failed() );
BOOST_TEST( !ec );
BOOST_TEST_EQ( ec.to_string(), std::string( "system:0" ) );
{
sys::error_code ec2( ec );
BOOST_TEST_EQ( ec2.value(), 0 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec2.failed() );
BOOST_TEST( !ec2 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST_NOT( ec != ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
}
{
sys::error_code ec2( ec.value(), ec.category() );
BOOST_TEST_EQ( ec2.value(), 0 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !ec2.failed() );
BOOST_TEST( !ec2 );
BOOST_TEST_EQ( ec, ec2 );
BOOST_TEST_NOT( ec != ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:0" ) );
}
{
sys::error_code ec2( 5, sys::generic_category() );
BOOST_TEST_EQ( ec2.value(), 5 );
BOOST_TEST( ec2.category() == sys::generic_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( ec2.failed() );
BOOST_TEST( ec2 );
BOOST_TEST_NOT( !ec2 );
BOOST_TEST_NE( ec, ec2 );
BOOST_TEST_NOT( ec == ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "generic:5" ) );
}
{
sys::error_code ec2( 5, sys::system_category() );
BOOST_TEST_EQ( ec2.value(), 5 );
BOOST_TEST( ec2.category() == sys::system_category() );
BOOST_TEST_EQ( ec2.message(), ec2.category().message( ec2.value() ) );
BOOST_TEST_CSTR_EQ( ec2.message( buffer, sizeof( buffer ) ), ec2.category().message( ec2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( ec2.failed() );
BOOST_TEST( ec2 );
BOOST_TEST_NOT( !ec2 );
BOOST_TEST_NE( ec, ec2 );
BOOST_TEST_NOT( ec == ec2 );
BOOST_TEST_EQ( ec2.to_string(), std::string( "system:5" ) );
}
return boost::report_errors();
}

View File

@ -18,7 +18,7 @@
#include <boost/cerrno.hpp>
#include <string>
#include <cstdio>
#include <boost/test/minimal.hpp>
#include <boost/detail/lightweight_test.hpp>
#ifdef BOOST_POSIX_API
# include <sys/stat.h>
@ -40,7 +40,7 @@ boost::system::error_code my_mkdir( const std::string & path )
# else
::CreateDirectoryA( path.c_str(), 0 ) != 0 ? 0 : ::GetLastError(),
# endif
boost::system::system_category );
boost::system::system_category() );
}
// ------------------------------------------------------------------------ //
@ -53,9 +53,9 @@ boost::system::error_code my_remove( const std::string & path )
{
return boost::system::error_code(
std::remove( path.c_str() ) == 0 ? 0 : errno,
boost::system::posix_category ); // OK for both Windows and POSIX
// Alternatively, could use posix_category
// on Windows and system_category on
boost::system::generic_category() ); // OK for both Windows and POSIX
// Alternatively, could use generic_category()
// on Windows and system_category() on
// POSIX-based systems.
}
@ -73,7 +73,7 @@ namespace boost
namespace lib3
{
// lib3 has its own error_category:
const boost::system::error_category & get_lib3_error_category();
const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib3_error_category = get_lib3_error_category();
enum error
@ -108,16 +108,18 @@ namespace boost
class lib3_error_category_imp : public boost::system::error_category
{
public:
const char * name() const
lib3_error_category_imp() : boost::system::error_category() { }
const char * name() const BOOST_SYSTEM_NOEXCEPT
{
return "lib3";
}
boost::system::error_condition default_error_condition( int ev ) const
boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{
return ev == boo_boo
? boost::system::error_condition( boost::system::posix::io_error,
boost::system::posix_category )
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev,
boost::lib3::lib3_error_category );
}
@ -131,7 +133,7 @@ namespace boost
};
const boost::system::error_category & get_lib3_error_category()
const boost::system::error_category & get_lib3_error_category() BOOST_SYSTEM_NOEXCEPT
{
static const lib3_error_category_imp l3ecat;
return l3ecat;
@ -152,7 +154,7 @@ namespace boost
namespace lib4
{
// lib4 has its own error_category:
const boost::system::error_category & get_lib4_error_category();
const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT;
const boost::system::error_category & lib4_error_category = get_lib4_error_category();
extern const boost::system::error_code boo_boo;
@ -168,16 +170,18 @@ namespace lib4
class lib4_error_category_imp : public boost::system::error_category
{
public:
const char * name() const
lib4_error_category_imp() : boost::system::error_category() { }
const char * name() const BOOST_SYSTEM_NOEXCEPT
{
return "lib4";
}
boost::system::error_condition default_error_condition( int ev ) const
boost::system::error_condition default_error_condition( int ev ) const BOOST_SYSTEM_NOEXCEPT
{
return ev == boo_boo.value()
? boost::system::error_condition( boost::system::posix::io_error,
boost::system::posix_category )
? boost::system::error_condition( boost::system::errc::io_error,
boost::system::generic_category() )
: boost::system::error_condition( ev, lib4::lib4_error_category );
}
@ -189,7 +193,7 @@ namespace lib4
}
};
const boost::system::error_category & get_lib4_error_category()
const boost::system::error_category & get_lib4_error_category() BOOST_SYSTEM_NOEXCEPT
{
static const lib4_error_category_imp l4ecat;
return l4ecat;
@ -233,15 +237,15 @@ namespace lib4
// switch (ev)
// {
// case user_success:
// return boost::system::error_code(boost::system::posix::success, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::success, boost::system::generic_category());
// case user_permission_denied:
// return boost::system::error_code(boost::system::posix::permission_denied, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::permission_denied, boost::system::generic_category());
// case user_out_of_memory:
// return boost::system::error_code(boost::system::posix::not_enough_memory, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::not_enough_memory, boost::system::generic_category());
// default:
// break;
// }
// return boost::system::error_code(boost::system::posix::no_posix_equivalent, boost::system::posix_category);
// return boost::system::error_code(boost::system::errc::no_posix_equivalent, boost::system::generic_category());
// }
//
// };
@ -260,8 +264,8 @@ namespace lib4
//
// void check_success(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::success) == expect );
// if (ec == boost::system::posix::success)
// BOOST_TEST( (ec == boost::system::errc::success) == expect );
// if (ec == boost::system::errc::success)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@ -269,8 +273,8 @@ namespace lib4
//
// void check_permission_denied(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::permission_denied) == expect );
// if (ec == boost::system::posix::permission_denied)
// BOOST_TEST( (ec == boost::system::errc::permission_denied) == expect );
// if (ec == boost::system::errc::permission_denied)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@ -278,8 +282,8 @@ namespace lib4
//
// void check_out_of_memory(const boost::system::error_code& ec, bool expect)
// {
// BOOST_CHECK( (ec == boost::system::posix::not_enough_memory) == expect );
// if (ec == boost::system::posix::not_enough_memory)
// BOOST_TEST( (ec == boost::system::errc::not_enough_memory) == expect );
// if (ec == boost::system::errc::not_enough_memory)
// std::cout << "yes... " << (expect ? "ok" : "fail") << '\n';
// else
// std::cout << "no... " << (expect ? "fail" : "ok") << '\n';
@ -291,23 +295,23 @@ namespace lib4
// printf("=====\n");
// boost::system::error_code ec;
// check_success(ec, true);
// check_success(boost::system::posix::success, true);
// check_success(boost::system::posix::permission_denied, false);
// check_success(boost::system::posix::not_enough_memory, false);
// check_success(boost::system::errc::success, true);
// check_success(boost::system::errc::permission_denied, false);
// check_success(boost::system::errc::not_enough_memory, false);
// check_success(user_success, true);
// check_success(user_permission_denied, false);
// check_success(user_out_of_memory, false);
// check_permission_denied(ec, false);
// check_permission_denied(boost::system::posix::success, false);
// check_permission_denied(boost::system::posix::permission_denied, true);
// check_permission_denied(boost::system::posix::not_enough_memory, false);
// check_permission_denied(boost::system::errc::success, false);
// check_permission_denied(boost::system::errc::permission_denied, true);
// check_permission_denied(boost::system::errc::not_enough_memory, false);
// check_permission_denied(user_success, false);
// check_permission_denied(user_permission_denied, true);
// check_permission_denied(user_out_of_memory, false);
// check_out_of_memory(ec, false);
// check_out_of_memory(boost::system::posix::success, false);
// check_out_of_memory(boost::system::posix::permission_denied, false);
// check_out_of_memory(boost::system::posix::not_enough_memory, true);
// check_out_of_memory(boost::system::errc::success, false);
// check_out_of_memory(boost::system::errc::permission_denied, false);
// check_out_of_memory(boost::system::errc::not_enough_memory, true);
// check_out_of_memory(user_success, false);
// check_out_of_memory(user_permission_denied, false);
// check_out_of_memory(user_out_of_memory, true);
@ -333,7 +337,7 @@ namespace lib4
// ------------------------------------------------------------------------ //
int test_main( int, char *[] )
int main( int, char *[] )
{
boost::system::error_code ec;
@ -342,35 +346,35 @@ int test_main( int, char *[] )
ec = my_mkdir( "/no-such-file-or-directory/will-not-succeed" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory );
BOOST_CHECK( ec.category() == boost::system::system_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::system_category() );
// Library 2 tests:
ec = my_remove( "/no-such-file-or-directory" );
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::system::posix::no_such_file_or_directory );
BOOST_CHECK( ec.category() == boost::system::posix_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::system::errc::no_such_file_or_directory );
BOOST_TEST( ec.category() == boost::system::generic_category() );
// Library 3 tests:
ec = boost::lib3::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == boost::lib3::boo_boo );
BOOST_CHECK( ec.value() == boost::lib3::boo_boo );
BOOST_CHECK( ec.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec );
BOOST_TEST( ec == boost::lib3::boo_boo );
BOOST_TEST( ec.value() == boost::lib3::boo_boo );
BOOST_TEST( ec.category() == boost::lib3::lib3_error_category );
BOOST_CHECK( ec == boost::system::posix::io_error );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec3( boost::lib3::boo_boo+100,
boost::lib3::lib3_error_category );
BOOST_CHECK( ec3.category() == boost::lib3::lib3_error_category );
BOOST_CHECK( ec3.default_error_condition().category()
BOOST_TEST( ec3.category() == boost::lib3::lib3_error_category );
BOOST_TEST( ec3.default_error_condition().category()
== boost::lib3::lib3_error_category );
// Library 4 tests:
@ -378,21 +382,21 @@ int test_main( int, char *[] )
ec = lib4::boo_boo;
std::cout << "ec.value() is " << ec.value() << '\n';
BOOST_CHECK( ec );
BOOST_CHECK( ec == lib4::boo_boo );
BOOST_CHECK( ec.value() == lib4::boo_boo.value() );
BOOST_CHECK( ec.category() == lib4::lib4_error_category );
BOOST_TEST( ec );
BOOST_TEST( ec == lib4::boo_boo );
BOOST_TEST( ec.value() == lib4::boo_boo.value() );
BOOST_TEST( ec.category() == lib4::lib4_error_category );
BOOST_CHECK( ec == boost::system::posix::io_error );
BOOST_TEST( ec == boost::system::errc::io_error );
boost::system::error_code ec4( lib4::boo_boo.value()+100,
lib4::lib4_error_category );
BOOST_CHECK( ec4.default_error_condition().category()
BOOST_TEST( ec4.default_error_condition().category()
== lib4::lib4_error_category );
// Test 3
//test3::run();
return 0;
return ::boost::report_errors();
}

View File

@ -0,0 +1,31 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
sys::error_condition en;
BOOST_TEST_EQ( en.value(), 0 );
BOOST_TEST( !en );
sys::error_condition en2( en );
BOOST_TEST( en == en2 );
BOOST_TEST_NOT( en != en2 );
en2.assign( 1, en.category() );
BOOST_TEST_EQ( en2.value(), 1 );
BOOST_TEST( en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST( en != en2 );
return boost::report_errors();
}

View File

@ -0,0 +1,25 @@
// Copyright 2020 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/system/errc.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
sys::error_condition en( sys::errc::no_such_file_or_directory );
BOOST_TEST_EQ( en.value(), ENOENT );
BOOST_TEST( en );
BOOST_TEST( !!en );
BOOST_TEST( en == make_error_condition( sys::errc::no_such_file_or_directory ) );
BOOST_TEST( en.category() == sys::error_condition().category() );
return boost::report_errors();
}

View File

@ -0,0 +1,94 @@
// Copyright 2020, 2021 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/error_condition.hpp>
#include <boost/system/generic_category.hpp>
#include <boost/system/system_category.hpp>
#include <boost/core/lightweight_test.hpp>
namespace sys = boost::system;
int main()
{
char buffer[ 1024 ];
sys::error_condition en;
BOOST_TEST_EQ( en.value(), 0 );
BOOST_TEST( en.category() == sys::generic_category() );
BOOST_TEST_EQ( en.message(), en.category().message( en.value() ) );
BOOST_TEST_CSTR_EQ( en.message( buffer, sizeof( buffer ) ), en.category().message( en.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en.failed() );
BOOST_TEST( !en );
BOOST_TEST_EQ( en.to_string(), std::string( "cond:generic:0" ) );
{
sys::error_condition en2( en );
BOOST_TEST_EQ( en2.value(), 0 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en2.failed() );
BOOST_TEST( !en2 );
BOOST_TEST_EQ( en, en2 );
BOOST_TEST_NOT( en != en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
}
{
sys::error_condition en2( en.value(), en.category() );
BOOST_TEST_EQ( en2.value(), 0 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( !en2.failed() );
BOOST_TEST( !en2 );
BOOST_TEST_EQ( en, en2 );
BOOST_TEST_NOT( en != en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:0" ) );
}
{
sys::error_condition en2( 5, sys::generic_category() );
BOOST_TEST_EQ( en2.value(), 5 );
BOOST_TEST( en2.category() == sys::generic_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( en2.failed() );
BOOST_TEST( en2 );
BOOST_TEST_NOT( !en2 );
BOOST_TEST_NE( en, en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:generic:5" ) );
}
{
sys::error_condition en2( 5, sys::system_category() );
BOOST_TEST_EQ( en2.value(), 5 );
BOOST_TEST( en2.category() == sys::system_category() );
BOOST_TEST_EQ( en2.message(), en2.category().message( en2.value() ) );
BOOST_TEST_CSTR_EQ( en2.message( buffer, sizeof( buffer ) ), en2.category().message( en2.value(), buffer, sizeof( buffer ) ) );
BOOST_TEST( en2.failed() );
BOOST_TEST( en2 );
BOOST_TEST_NOT( !en2 );
BOOST_TEST_NE( en, en2 );
BOOST_TEST_NOT( en == en2 );
BOOST_TEST_EQ( en2.to_string(), std::string( "cond:system:5" ) );
}
return boost::report_errors();
}

View File

@ -0,0 +1,66 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
#include <boost/system/error_code.hpp>
#include <boost/config/pragma_message.hpp>
#include <boost/static_assert.hpp>
#if !defined(BOOST_SYSTEM_HAS_CONSTEXPR)
BOOST_PRAGMA_MESSAGE("Skipping constexpr test, BOOST_SYSTEM_HAS_CONSTEXPR isn't defined")
int main() {}
#else
using namespace boost::system;
constexpr error_code ec1( 1, system_category() );
BOOST_STATIC_ASSERT( ec1.failed() );
BOOST_STATIC_ASSERT( ec1 );
BOOST_STATIC_ASSERT( !!ec1 );
constexpr error_code ec2( 2, generic_category() );
BOOST_STATIC_ASSERT( ec2.failed() );
BOOST_STATIC_ASSERT( ec2 );
BOOST_STATIC_ASSERT( !!ec2 );
constexpr error_code ec3;
BOOST_STATIC_ASSERT( !ec3.failed() );
BOOST_STATIC_ASSERT( ec3? false: true );
BOOST_STATIC_ASSERT( !ec3 );
#if defined(__GNUC__) && __GNUC__ == 7 && __cplusplus == 201703L
// 'cat_' is not a constant expression
#else
constexpr error_condition en1( 1, system_category() );
BOOST_STATIC_ASSERT( en1.failed() );
BOOST_STATIC_ASSERT( en1 );
BOOST_STATIC_ASSERT( !!en1 );
constexpr error_condition en2( 2, generic_category() );
BOOST_STATIC_ASSERT( en2.failed() );
BOOST_STATIC_ASSERT( en2 );
BOOST_STATIC_ASSERT( !!en2 );
constexpr error_condition en3;
BOOST_STATIC_ASSERT( !en3.failed() );
BOOST_STATIC_ASSERT( en3? false: true );
BOOST_STATIC_ASSERT( !en3 );
#endif
int main()
{
}
#endif

185
test/failed_test.cpp Normal file
View File

@ -0,0 +1,185 @@
// Copyright 2018 Peter Dimov.
// Distributed under the Boost Software License, Version 1.0.
// Avoid spurious VC++ warnings
#define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstdio>
using namespace boost::system;
struct http_category_impl: public error_category
{
// clang++ 3.8 and below: initialization of const object
// requires a user-provided default constructor
BOOST_SYSTEM_CONSTEXPR http_category_impl() BOOST_NOEXCEPT
{
}
char const * name() const BOOST_NOEXCEPT
{
return "http";
}
std::string message( int ev ) const
{
char buffer[ 32 ];
std::sprintf( buffer, "HTTP/1.0 %d", ev );
return buffer;
}
bool failed( int ev ) const BOOST_NOEXCEPT
{
return !( ev >= 200 && ev < 300 );
}
};
error_category const & http_category()
{
static const http_category_impl instance;
return instance;
}
#define TEST_NOT_FAILED(ec) BOOST_TEST( !ec.failed() ); BOOST_TEST( ec? false: true ); BOOST_TEST( !ec );
#define TEST_FAILED(ec) BOOST_TEST( ec.failed() ); BOOST_TEST( ec ); BOOST_TEST( !!ec );
template<class Ec> void test()
{
{
Ec ec;
TEST_NOT_FAILED( ec );
ec.assign( 1, generic_category() );
TEST_FAILED( ec );
ec.clear();
TEST_NOT_FAILED( ec );
ec = Ec( 1, generic_category() );
TEST_FAILED( ec );
ec = Ec();
TEST_NOT_FAILED( ec );
}
{
Ec ec;
TEST_NOT_FAILED( ec );
ec.assign( 1, system_category() );
TEST_FAILED( ec );
ec.clear();
TEST_NOT_FAILED( ec );
ec = Ec( 1, system_category() );
TEST_FAILED( ec );
ec = Ec();
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, generic_category() );
TEST_NOT_FAILED( ec );
ec.assign( 1, system_category() );
TEST_FAILED( ec );
ec = Ec( 0, system_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 1, generic_category() );
TEST_FAILED( ec );
ec.assign( 0, system_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, system_category() );
TEST_NOT_FAILED( ec );
ec.assign( 1, generic_category() );
TEST_FAILED( ec );
ec = Ec( 0, generic_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 1, system_category() );
TEST_FAILED( ec );
ec.assign( 0, generic_category() );
TEST_NOT_FAILED( ec );
}
{
Ec ec( 0, http_category() );
TEST_FAILED( ec );
ec.assign( 200, http_category() );
TEST_NOT_FAILED( ec );
ec = Ec( 404, http_category() );
TEST_FAILED( ec );
}
}
int main()
{
BOOST_TEST( !generic_category().failed( 0 ) );
BOOST_TEST( generic_category().failed( 7 ) );
BOOST_TEST( !system_category().failed( 0 ) );
BOOST_TEST( system_category().failed( 7 ) );
BOOST_TEST( http_category().failed( 0 ) );
BOOST_TEST( !http_category().failed( 200 ) );
BOOST_TEST( http_category().failed( 404 ) );
test<error_code>();
test<error_condition>();
{
error_condition ec( errc::success );
TEST_NOT_FAILED( ec );
ec = errc::address_family_not_supported;
TEST_FAILED( ec );
}
{
error_condition ec( errc::address_family_not_supported );
TEST_FAILED( ec );
ec = errc::success;
TEST_NOT_FAILED( ec );
}
{
error_code ec( make_error_code( errc::success ) );
TEST_NOT_FAILED( ec );
ec = make_error_code( errc::address_family_not_supported );
TEST_FAILED( ec );
}
{
error_code ec( make_error_code( errc::address_family_not_supported ) );
TEST_FAILED( ec );
ec = make_error_code( errc::success );
TEST_NOT_FAILED( ec );
}
return boost::report_errors();
}

View File

@ -0,0 +1,41 @@
// Copyright 2018 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
// Avoid spurious VC++ warnings
# define _CRT_SECURE_NO_WARNINGS
#include <boost/system/error_code.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cstring>
//
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
// message
for( int i = -2; i < 1024; ++i )
{
{
BOOST_TEST_CSTR_EQ( cat.message( i ).c_str(), std::strerror( i ) );
}
{
char buffer[ 256 ];
BOOST_TEST_CSTR_EQ( cat.message( i, buffer, sizeof( buffer ) ), std::strerror( i ) );
}
}
return boost::report_errors();
}

View File

@ -0,0 +1,20 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/generic_category.hpp>
#include <boost/core/lightweight_test.hpp>
// Tests whether generic_category() is functional when only
// generic_category.hpp is included
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
return boost::report_errors();
}

View File

@ -0,0 +1,30 @@
// Copyright 2020 Peter Dimov
// Distributed under the Boost Software License, Version 1.0
// http://www.boost.org/LICENSE_1_0.txt
#include <boost/system/generic_category.hpp>
#include <boost/system/error_condition.hpp>
#include <boost/core/lightweight_test.hpp>
#include <cerrno>
namespace sys = boost::system;
int main()
{
sys::error_category const & cat = sys::generic_category();
// name
BOOST_TEST_CSTR_EQ( cat.name(), "generic" );
// default_error_condition
BOOST_TEST( cat.default_error_condition( 0 ) == sys::error_condition( 0, cat ) );
BOOST_TEST( cat.default_error_condition( ENOENT ) == sys::error_condition( ENOENT, cat ) );
BOOST_TEST( cat.default_error_condition( -1 ) == sys::error_condition( -1, cat ) );
// failed
BOOST_TEST( !cat.failed( 0 ) );
BOOST_TEST( cat.failed( ENOENT ) );
BOOST_TEST( cat.failed( -1 ) );
return boost::report_errors();
}

View File

@ -1,4 +1,4 @@
// error_code_test.cpp -----------------------------------------------------//
// header_only_test.cpp -----------------------------------------------------//
// Copyright Beman Dawes 2007
@ -13,12 +13,13 @@
#define BOOST_ERROR_CODE_HEADER_ONLY
#include <boost/test/minimal.hpp>
#include <boost/detail/lightweight_test.hpp>
#include <boost/system/error_code.hpp>
int test_main( int, char*[] )
int main()
{
boost::system::error_code ec( 0, boost::system::system_category );
return 0;
boost::system::error_code ec( 0, boost::system::system_category() );
(void)ec;
return ::boost::report_errors();
}

Some files were not shown because too many files have changed in this diff Show More