C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Thu, 15 Jan 2026 08:53:43 +0000
I'm just realising now that the following isn't even good enough:

    if ( decltype(auto) x = expr ) return x;

It actually needs to be:

    if ( decltype(auto) x = CalleeFunction();
static_cast<decltype(x)>(x) ) return static_cast<decltype(x)>(x);

because the following fails to compile:

    struct C {
        operator bool(void) const & = delete;
        operator bool(void) const && { return true; }
    };

    C &&CalleeFunction(void)
    {
        static C var;
        return (C&&)var;
    }

    C &&EnclosingFunction(void)
    {
        if ( decltype(auto) x = CalleeFunction() ) return x;
    }

    int main(void)
    {
        EnclosingFunction();
    }

Received on 2026-01-15 08:52:40