-
Notifications
You must be signed in to change notification settings - Fork 13
assignment operator: check if op can throw or not, and create a temp object if it can to keep strong exc guarantee #12
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
base: master
Are you sure you want to change the base?
Conversation
… it can to keep strong exc guarantee
… it can to keep strong exc guarantee - fix unit tests
| { | ||
| constexpr const bool canThrow = | ||
| (std::is_rvalue_reference<_T&&>::value && std::is_nothrow_move_constructible<_T>::value) | ||
| || (std::is_lvalue_reference<_T&&>::value && std::is_nothrow_copy_constructible<_T>::value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I review my own code I see the condition should be the other way around - I forgot the negation in fromt of the is_nothrow... I will change that.
| detail::static_any::throw_tag, | ||
| detail::static_any::nothrow_tag>::type; | ||
|
|
||
| assign(std::forward<_T>(t), ThrowTag{}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see how constexpr if could be useful here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes... !
| CallCounter& operator=(CallCounter&&) { ++move_constructions; return *this; } | ||
| ~CallCounter() { ++destructions; } | ||
|
|
||
| CallCounter(CallCounter&&) noexcept(NoExcept) { ++move_constructions; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
| }; | ||
|
|
||
|
|
||
| /* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what's wrong with this guy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a bad unit test - the name does not mean too much, but more importantly UnsafeCopy is not enough. I should add an UnsafeCopy with a noexcept move ctor and one without, to check both cases.
@maciekgajewski could you have a look at the change? Don't spend too much time looking at the unit tests for now, I need to add more of them. the existing ones don't make too much sense as I should really check thoroughly the cases where copy ctor throw or not, same with move ctor.
Cheers!
David