Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

function::swap : remove noexcept. #264

Conversation

faithandbrave
Copy link
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
Copy link
Contributor

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
Copy link
Member

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
Copy link
Contributor Author

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

@jwakely
Copy link
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
Copy link
Contributor Author

@jwakely
Thanks, I missed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants