Boost logo

Boost :

Subject: Re: [boost] Looking for thoughts on a new smart pointer: shared_ptr_nonnull
From: Thorsten Ottosen (thorsten.ottosen_at_[hidden])
Date: 2013-10-10 04:54:54

On 09-10-2013 17:18, Nevin Liber wrote:
> On 9 October 2013 01:31, Thorsten Ottosen <thorsten.ottosen_at_[hidden]>wrote:
> You seem to be completely obsessed by the point that a precondition or
>> invariant violation must always be checked by compiled-away assertions.
> You seem completely obsessed to call it a precondition or invariant
> violation. Why? All you have to do is make it defined behavior in your
> library; then it isn't a bug and apparently everyone will be happy.

I'm ok with that, although I think it's possible to have the concept of
broken contracts separate from the concept of how to deal with broken
contracts. Is that an unreasonable oppinion?

Someone suggested that there should be both an assertion and a throw. I
would prefer that approach.

>> Your argument is that there is a bug in the program and that you should
>> terminate anyway. Sadly, must programs have bugs, but we use them anyway.
> Most programs don't have detectable (by code) bugs.
> Just make sure your engineers, business owners and clients understand the
> risk they are taking on.
>> In practice it matters for some to avoid UB.
> I thought in practice it matters to avoid bugs.

That matter's too, of course.

>> It's a major benefit of using Java or C#.
> And yet programming bugs happen in those languages too.

Of course.

> The great thing about UB is that you can tell people "there be dragons;
> don't go there", and you can even add checks in some builds to detect such
> bugs. If the behavior is well defined, you can't do that, because a
> programmer could be legitimately calling it for that behavior.

Well, the object won't be constructed, so it would just be equivalent
to a throw statement. (I have never been part of any discussion saying
exceptions are particular bad. They have uses and misuses.)
I can't think of anyone that would do that on purpose, but I can think
of people that might do it by accident.



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