There is another solution that doesn't require a hidden variable, at the cost of duplicating generated code:

    void foo() {
        S s;
        if(cond)
            bar(s);
        some();
        more();
        code();
    }

Can be rewritten as:

    void foo() {
        S s;
        if(cond) {
            bar(s);
            some();
            more();
            code();
            // don't destroy here
        } else {
            some();
            more();
            code();
            s.~this(); // destroy here
        }
    }

But I think this is best left to an optimizer which has more info about the costs of the additional code vs the hidden var to decide whether its worth it.

Reply via email to