C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 13 Jan 2026 22:50:37 +0000
On Tue, Jan 13, 2026 at 10:41 PM I wrote:
>
> return if SomeFunction() => if ( decltype(auto) x =
> SomeFunction() ) return x;
>
> And here's the inverted one:
>
> return ! if SomeFunction() => if ( decltype(auto) x =
> SomeFunction() ) return !x;


Just realising that both of them are wrong as the return statement is
discarding the value type. Should be:

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

and:

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

Received on 2026-01-13 22:49:35