On Oct 8, 2013, at 2:37 PM, Daniel James
On 6 October 2013 19:14, Matt Calabrese
wrote: On Sun, Oct 6, 2013 at 2:11 AM, Daniel James
wrote: How is that not introducing undefined behaviour? Say there's a function:
void foo(boost::shared_ptr<...> const& x) { if (!x) { something_or_other(); } else blah_blah(*x); }
By using shared_ptr_nonull, that check can be removed:
void foo(boost::shared_ptr_nonnull<...> const& x) { blah_blah(*x); }
But then a caller believes that their shared_ptr is never null, so they copy it into a shared_ptr_nonnull without checking for null first, and that action introduces the possibility of undefined behaviour where there was none before (given that there's always a possibility of bugs in non-trivial code).
No response to this example?
Why does the author of foo() know enough to test for null, but the caller of foo(), knowing that they are creating a shared_ptr_nonnull, doesn't? ___ Rob (Sent from my portable computation engine)