Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2023-01-10 17:13:44


Hans Dembinski wrote:
> > On 9. Jan 2023, at 19:15, Peter Dimov via Boost <boost_at_[hidden]>
> wrote:
> >
> > It will be better if you show how the existing code (before the
> > delayed_forward
> > transformation) looks like.
>
> I added FooOld, which corresponds to the unsafe design I want to replace.
> https://godbolt.org/z/15q9EqnfP

Thanks. I note that as written, FooOld actually has the same problem even
if the argument is not taken by value.

template <class T>
struct FooOld2 {
    FooOld2(bool b, T const& targ) : t_(targ) {
        if (b)
            throw 1;
    }
    FooOld2(bool b, T&& targ = {}) : t_(std::move(targ)) {
        if (b)
            throw 1;
    }
private:
    T t_;
};

There might be a difference between passing by value or not, but for that,
the exception would have to be thrown from a base or previous member
initialization, and not the constructor body.


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