2
0
mirror of https://github.com/boostorg/scope.git synced 2026-01-19 04:42:10 +00:00

35 Commits

Author SHA1 Message Date
Andrey Semashev
03252fd0af Silence -Wmissing-field-initializers gcc warning in unique_fd test. 2025-06-19 04:46:05 +03:00
Andrey Semashev
3e1e0a98b2 Attach C++ requirements to the library target.
This exposes C++ requirements of Boost.Scope to the downstream users.
2025-06-19 04:25:20 +03:00
Andrey Semashev
eb55e3eb05 Added a workaround in tests for MSVC 14.1 in C++17 mode.
The compiler ICEs when tests for unallocated_resource helper are
compiled. It isn't clear what upsets the compiler, but changing the
unique_resource constructor that is being called works around the
problem.

Since unallocated_resource is still usable, we're not disabling it
for this compiler and just update the test. Users encountering ICEs
will have to deal with them on their end (upgrading the compiler might
be one way to do it).

https://developercommunity.visualstudio.com/t/ICE-when-compiling-NTTP-related-BoostSc/10922599
2025-06-14 17:59:26 +03:00
Andrey Semashev
f4abde30e2 Move MSVC C4702 warning silencing past includes. 2024-02-05 00:47:51 +03:00
Andrey Semashev
0cfc01818c Disabled MSVC warning C4702: unreachable code.
This warning is triggered by tests that throw exceptions and then check
that the code that follows is not reached.
2024-02-05 00:35:50 +03:00
Andrey Semashev
183715b90f Disable warnings for auxiliary definitions on unique_fd test. 2024-02-05 00:19:09 +03:00
Andrey Semashev
127c3aaa4e Enabled warnings-as-errors for tests. 2024-02-05 00:03:54 +03:00
Andrey Semashev
45317772d1 Removed support for "reduced" resource traits in unique_resource.
The support required to be permissive wrt. is_allocated being callable
with a resource argument. This could lead to unexpected behavior, where
the user provided a seemingly conforming resource traits but
unique_resource would still reject them for some reason (e.g. if
is_allocated is not callable with the const resource value, as tested
by unique_resource) and work in "reduced" resource traits mode. This
would change the behavior of the APIs that accept resource values as
an argument (e.g. constructing unique_resource with a resource value
would always produce an object in the allocated state, while the user
would expect it to depend on the resource value).

Removing the support for "reduced" resource traits makes the behavior
more predictable. If the user specified resource traits, it either
compiles and works according to the resource traits, or fails to compile
if the resource traits are somehow not conforming.

The support for customizing default-constructed resource value is not
important enough. It can be worked around by either implementing proper
resource traits, or by specifying the default value in
make_unique_resource_checked.

Additionally, modified unallocated_resource to relax the argument type
of is_allocated and the types of the unallocated values. This can be
useful when the types of the unallocated resource values don't match
the actual resource type (e.g. std::nullptr_t vs. typed pointers).
2024-02-04 19:32:24 +03:00
Andrey Semashev
d53d4f43af Enforced correctness checks for resource traits, improved docs.
Instead of silently switching to the unique_resource implementation
based on the "allocated" flag if the resource traits don't conform
to the requirements, issue hard compilation errors. This should better
protect against mistakes, where the user assumes unique_resource
behaves as if it is using the resource traits while it actually doesn't.

Improved documentation of requirements for resource traits and documented
the "reduced" form of resource traits, where the traits only provide
the default resource value but otherwise don't change unique_resource
behavior.
2024-01-31 04:52:12 +03:00
Andrey Semashev
e595286ad3 Converted typedefs to using type aliases.
One person during review complained that the library implementation
used typedefs instead of C++11 using type aliases. Not an essential
difference, but if it helps code readability, let it be.
2024-01-31 01:11:01 +03:00
Andrey Semashev
8c985b565c Changed behavior of unique_resource constructor to be non-destructive.
If the resource type is nothrow move-constructible and the deleter type
is not, and the deleter's copy constructor throws during unique_resource
move constructor, then move the move-constructed resource back to the
original object instead of invoking the deleter on it. This leaves the
move source in its original state rather than in unallocated state,
which means unique_resource move constructor now provides strong
exception guarantee.
2024-01-28 23:27:53 +03:00
Andrey Semashev
3d228f7294 Switched to BOOST_NO_CXX17_AUTO_NONTYPE_TEMPLATE_PARAMS from Boost.Config. 2024-01-26 22:57:25 +03:00
Andrey Semashev
518557da18 Switch to Boost.Config macro for C++17 fold expressions.
Turns out, Boost.Config's macro is not excessively restrictive.
2024-01-24 03:12:32 +03:00
Andrey Semashev
d45a6255aa Added unallocated_resource for simplified declaration of resource traits.
A new unallocated_resource class template allows to automatically generate
resource traits from one or more unallocated resource values.

The idea for a more compact unique_resource declaration was given
by Janko Dedic in his review.
2024-01-24 02:59:54 +03:00
Andrey Semashev
fa650d558d Added explicit operator bool to unique_resource.
The operator tests if the resource wrapper is in an allocate state.
2024-01-21 19:52:29 +03:00
Andrey Semashev
a53bdaad49 Removed release() member of scope guards.
Although it was there to make the scope guards intergace-compatible with
the TS, the review conclusion indicated that strict conformance with
the TS is not a desired goal. So remove the release() method and keep
set_active() as the way to (de)activate the scope guard.
2024-01-21 19:47:46 +03:00
Andrey Semashev
b0117a4b2e Renamed scope_final to defer_guard and BOOST_SCOPE_FINAL to BOOST_SCOPE_DEFER.
This follows the suggestion by Peter Dimov during the review.
2024-01-19 01:13:26 +03:00
Andrey Semashev
46cd547bb4 Switched noexcept conditions checking the deleter to use is_nothrow_invocable.
Also hidden these conditions from docs since they now involve symbols
from namespace detail.

Added test for noexcept(reset()).

Closes https://github.com/Lastique/scope/issues/7.
2023-11-28 15:08:02 +03:00
Andrey Semashev
016a3a3820 Decay references to functions to pointers in scope guards CTAD.
Apparently, the Library Fundamentals TS does permit pointers to functions
in scope guards (via the "function object type" definition in the standard),
so instead of taking the effort to preserve the function references decay
those to pointers to functions.

Updated docs and tests.
2023-11-28 14:50:12 +03:00
Andrey Semashev
c9725c4577 Changed unique resource deduction guide to use decay semantics.
This reflects the decay type trait that is used in make_unique_resource_checked
and is needed to support references to functions for deleters.

Added tests for unique_resource type deductions involving references
to functions.
2023-11-28 14:18:09 +03:00
Andrey Semashev
052b3b156a Fixed scope guard function type deduction for function references.
Scope guard factory functions used to generate scope guards with incorrect
action and condition types if the factory was called with function
references. The scope guard template arguments used to be function types
instead of references to functions.

Also, deduction guides used to decay the arguments, which would produce
scope guards with pointers to functions in template arguments. Although
this worked, formally only references to functions are supported. So
changed the deduction guides to produce references to functions.

Updated docs and tests.

Fixes https://github.com/Lastique/scope/issues/6.
2023-11-28 01:38:35 +03:00
Andrey Semashev
fbfdb8a494 Merged scope_check into scope_exit.
As suggested by Peter Dimov on boost-dev ML, scope_check functionality
is merged into scope_exit. Thus scope_exit now has an optional condition
function object, which by default always returns true. If a custom
function object is specified, scope_exit works equivalently to the
previous scope_check, i.e. calls the condition function object to check
whether the action function object needs to be called.
2023-10-14 19:23:32 +03:00
Andrey Semashev
c5635f21cc Implemented scope_check and added support for arbitrary fail conditions.
The new scope_check scope guard is a generalization of scope_success and
scope_fail and allows specifying arbitrary conditions for executing the
scope exit action. The scope_success and scope_fail have been
reimplemented in terms of scope_check and now also support arbitrary
fail conditions.

Added exception_checker and error_code_checker conditions for testing
for an exception being thrown and for an error code, respectively.
scope_success and scope_fail use exception_checker by default.

Added tests for the new components.
2023-03-26 21:02:11 +03:00
Andrey Semashev
4f00244b8e Also disable MSVC aborts in release mode. 2023-03-20 03:53:30 +03:00
Andrey Semashev
f4c70e1523 Suppress assertion failure aborts with MSVC. 2023-03-20 03:23:36 +03:00
Andrey Semashev
0e83fcbde7 Added support for file descriptors on Windows. 2023-03-20 00:21:06 +03:00
Andrey Semashev
f3cfd937f6 Updated license headers. 2023-02-24 19:30:55 +03:00
Andrey Semashev
18b135804a Added support for default_resource keyword. 2023-02-22 01:38:35 +03:00
Andrey Semashev
f12546687e Added checks for whether the function object is destroyed after throwing. 2023-02-21 02:35:23 +03:00
Andrey Semashev
678253f727 Added more tests for exception handling, fixed bugs. 2023-02-21 02:27:42 +03:00
Andrey Semashev
43819ad703 Added more tests for exception handling. 2023-02-20 03:27:43 +03:00
Andrey Semashev
5abe4610ea Use test executable file in unique_posix_fd test.
Opening /dev/null may fail on Cygwin and possibly other systems
where it doesn't exist.
2023-02-18 14:59:02 +03:00
Andrey Semashev
928160b613 Added unique_posix_fd. Fixed unique_resource traits support. Added tests. 2023-02-12 20:13:53 +03:00
Andrey Semashev
166d6a178b Fixes and tests for unique_resource. 2023-01-24 02:22:16 +03:00
Andrey Semashev
9f55473af2 Initial commit. 2023-01-10 02:18:35 +03:00