Remove try/catch block on unique_resource move constructor#20
Remove try/catch block on unique_resource move constructor#20windowsair wants to merge 1 commit into
Conversation
The clang-21 says:
include/nonstd/scope.hpp:1007:40: error:
cannot refer to a non-static member from the handler of a constructor function try block
[-Werror,-Wexceptions]
1007 | other.get_deleter()( this->get() );
| ^
1 error generated.
Since the move constructor already provides an noexcept guarantee,
no exceptions will be thrown here. The try-catch block is redundant.
And a further approach is to provide a throwable exception variant of
the move constructor.
|
There seems to be a bit more to it than providing the move constructor as: unique_resource( unique_resource && other )
scope_noexcept_op(
std11::is_nothrow_move_constructible<R1>::value && std11::is_nothrow_move_constructible<D>::value
)
: resource( conditional_move( std::move(other.resource), typename std11::bool_constant< std11::is_nothrow_move_assignable<R>::value >() ) )
, deleter( conditional_move( std::move(other.deleter ), typename std11::bool_constant< std11::is_nothrow_move_constructible<D>::value >() ) )
, execute_on_reset( std14::exchange( other.execute_on_reset, false ) )
{}Proposal p0052 writes: unique_resource(unique_resource&& rhs) noexcept (see below )9 Effects: First, initialize 10 [Note: The explained mechanism ensures no leaking and no double release of resources. — end note ] 11 Remarks: The expression inside noexcept is equivalent to |
|
If my understanding is correct, the two variants below still require implementation: // from std::move(other.resource)
unique_resource( unique_resource && other )
scope_noexcept_op(
std11::is_nothrow_move_constructible<R1>::value &&
!std11::is_nothrow_move_constructible<D>::value
) {}
// from other.resource
unique_resource( unique_resource && other )
scope_noexcept_op(
!std11::is_nothrow_move_constructible<D>::value
) {} |
|
Thanks @windowsair , I'll look into it (don't hold your breath :) |
The clang-21 says:
include/nonstd/scope.hpp:1007:40: error:
cannot refer to a non-static member from the handler of a constructor function try block
[-Werror,-Wexceptions]
1007 | other.get_deleter()( this->get() );
| ^
1 error generated.
Since the move constructor already provides an noexcept guarantee, no exceptions will be thrown here. The try-catch block is redundant.
And a further approach is to provide a throwable exception variant of the move constructor.