C++ Logo

std-proposals

Advanced search

Re: [std-proposals] goto is not harmful (was: "once" keyword)

From: Alejandro Colomar <alx.manpages_at_[hidden]>
Date: Wed, 24 May 2023 15:14:47 +0200
Hi Federico,

On 5/24/23 15:07, Federico Kircheis via Std-Proposals wrote:
> On Wed, May 24, 2023 at 03:02:56PM +0200, Alejandro Colomar via Std-Proposals wrote:

>> The keyword exists, with a lovely name: goto
>>
>> ```c
>> if (failed(foo))
>> goto x;
>> if (failed(bar))
>> goto x;
>>
>> baz();
>> x:
>> ```
>>
>>
>>
>> [...]
>>
>
> Unfortunately it cannot be used in constexpr functions, maybe it is a
> good time to lift that restriction...

I didn't even know that. I'd say yes, goto is a great feature, and I
don't see why it shouldn't be available anywhere loops are available.

$ cat for.c++
constexpr int
foo(int x)
{
 for (; x < 3; x++);

 return x;
}
$ g++ -Wall -Wextra for.c++ -c
$

Cheers,
Alex

Received on 2023-05-24 13:14:50