Boost logo

Boost :

Subject: Re: [boost] [outcome] To variant, or not to variant?
From: Peter Dimov (lists_at_[hidden])
Date: 2017-06-02 00:43:57


Gavin Lambert wrote:
> On 2/06/2017 00:15, Peter Dimov wrote:
> > That's what I was thinking - that you want to place an assert there - I
> > just wanted to confirm that this is the only objection. Do we agree that
> > returning nullptr from operator-> is good for informing the static
> > analyzer and the optimizer that a value is present?
>
> I assume you meant "not present" there.

No, I do mean "present". If you do `r->x` in your code, the compiler from
this point on will optimize based on the assumption that a value was
present - otherwise what you did would have been undefined.

Actually, it will even propagate the "has_value()" assumption backwards from
the `r->x` point, not just forwards.

Returning a reinterpret_cast'ed pointer, on the other hand, will not do so,
although maybe an `assert( has_value() )` will, depending. (Last time I
recall Microsoft tried feeding asserts to the optimizer, they reverted it,
as it broke too much code, but things may have changed in the meantime.)


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk