function::swap : remove noexcept. #264

Closed
wants to merge 1 commit into
from

Projects

None yet

4 participants

@faithandbrave
Contributor

Member function version function::swap() has noexcept. But non member function version swap(function, function) doesn't have noexcept.
I think member function version is mistake, unnecessary noexcept. Because copy (or move) constructor of target function object may throw exception.

function constructor specification is follow:

function(const function& f);
template <class A> function(allocator_arg_t, const A& a, const function& f);

Postconditions: !*this if !f; otherwise, *this targets a copy of f.target().

Throws: shall not throw exceptions if f’s target is a callable object passed via reference_wrapper or
a function pointer. Otherwise, may throw bad_alloc or any exception thrown by the copy constructor
of the stored callable object. [Note: Implementations are encouraged to avoid the use of dynamically
allocated memory for small callable objects, for example, where f’s target is an object holding only a
pointer or reference to an object and a member function pointer. —end note ]
@K-ballo
Member
K-ballo commented Feb 6, 2014

In the general case, function::swap does not require any constructors as it merely swaps pointers. Only when the small callable object optimization is chosen function::swap could end up copy/move constructing the target callable, and noexcept here would restrict the types for which this optimization applies. Nevertheless, this is certainly an inconsistency not only with non-member swap but also with function's move constructor and move assignment operator.

@zygoloid
Contributor
zygoloid commented Feb 6, 2014

This inconsistency looks like a defect, especially since the non-member swap is specified to just call the member swap, but this is not editorial. I suggest mailing lwgchair@gmail.com to get a library issue opened for this.

@faithandbrave
Contributor

@zygoloid
OK, I will submit issue to the mailing list. Thanks.

@jwakely
Member
jwakely commented Feb 6, 2014

This is definitely not editorial, but there is already an issue opened to deal with it, see http://cplusplus.github.io/LWG/lwg-active.html#2062

@faithandbrave
Contributor

@jwakely
Thanks, I missed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment