C++ Logo

std-proposals

Advanced search

Re: [std-proposals] return if

From: Jan Schultke <janschultke_at_[hidden]>
Date: Mon, 12 Jan 2026 06:52:31 +0100
The idea isn't bad in a vacuum, but it provides too little value:

if (auto r = some_function()) return r;
// vs.
return if some_function();

The argument you're making with a proposal is that code above is
problematic and verbose to a degree where we need compiler support so we
can write the code below. I'm not seeing that.

The original does not suffer from multiple evaluations or from some kind of
performance problem, or from some major bug potential that cannot be
resolved with compiler warnings, or some other major issue. In fact, it
only has a single evaluation of some_function(), r is limited to the scope
of the if statement, and if you accidentally return something other than r,
you may get a warning due to an unused variable. It's quite amazing
already. The only downside is that it's a few characters longer, but we'd
never see the end of it if we added new compiler features each time there
are a dozen characters to be saved.

Received on 2026-01-12 05:52:48