Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Rob Stewart (robertstewart_at_[hidden])
Date: 2013-10-09 05:43:04

On Oct 8, 2013, at 2:37 PM, Daniel James <daniel_at_[hidden]> wrote:

> On 6 October 2013 19:14, Matt Calabrese <rivorus_at_[hidden]> wrote:
>> On Sun, Oct 6, 2013 at 2:11 AM, Daniel James <daniel_at_[hidden]> 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?


(Sent from my portable computation engine)

Boost list run by bdawes at, gregod at, cpdaniel at, john at