<div dir="auto">See P2561</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Mon, 12 Jan 2026, 00:00 Frederick Virchanza Gotham via Std-Proposals, &lt;<a href="mailto:std-proposals@lists.isocpp.org">std-proposals@lists.isocpp.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Consider the following generic line of code:<br>
<br>
    if ( handle const h = CreateHandle( 0xff ) ) return h;<br>
<br>
Right now I&#39;m patching the GNU g++ compiler, inside the file<br>
&quot;gcc/cp/typeck.cc&quot;, inside the function<br>
&quot;finish_class_member_access_expr&quot; because I want it to return early if<br>
it&#39;s dealing with a chimeric_ptr. However if it&#39;s not dealing with a<br>
chimeric_ptr, I want it to keep going. So right now the line of code<br>
I&#39;m adding looks like this:<br>
<br>
        if ( tree const t = check_for_chimera(name, object) ) return t;<br>
<br>
To be very generic about what the above line of code is doing:<br>
   (1) It invokes a function (let&#39;s call it the callee function).<br>
   (2) If the callee&#39;s return value after conversion to bool yields<br>
true, then the callee&#39;s return value is immediately returned from the<br>
enclosing function.<br>
    (3) If the callee&#39;s return value after conversion to bool yields<br>
false, the enclosing function keeps going.<br>
<br>
So to break it down logically, here&#39;s what&#39;s going on:<br>
<br>
    auto const retval = SomeFunction();<br>
    if ( static_cast&lt;bool&gt;(retval) ) return retval;<br>
<br>
Now personally I think that this would be much more succinctly<br>
expressed as follows:<br>
<br>
    return if SomeFunction();<br>
<br>
And so if we take another look at the line of code I&#39;m adding to the<br>
GNU g++ compiler:<br>
<br>
        if ( tree const t = check_for_chimera(name, object) ) return t;<br>
<br>
It could become:<br>
<br>
        return if check_for_chimera(name, object);<br>
<br>
I can think of loads of times over the past 20+ years when I&#39;ve coded<br>
a function that does exactly this -- it returns immediately if the<br>
callee succeeded, or it keeps going if the callee failed. This can be<br>
simplified with &quot;return if&quot;. And you&#39;ll see the benefit of it when you<br>
have multiple function calls:<br>
<br>
Symbol *resolve_symbol(Name &amp;name, Scope &amp;scope)<br>
{<br>
    return if try_fast_path(name, scope);<br>
    return if try_cached(name, scope);<br>
    return if try_builtin_table(name);<br>
<br>
    // Slow path:<br>
    . . .<br>
}<br>
<br>
This feature is about readability and convenience.<br>
-- <br>
Std-Proposals mailing list<br>
<a href="mailto:Std-Proposals@lists.isocpp.org" target="_blank" rel="noreferrer">Std-Proposals@lists.isocpp.org</a><br>
<a href="https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals" rel="noreferrer noreferrer" target="_blank">https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals</a><br>
</blockquote></div>

