C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Bringing break/continue with label to C++

From: Filip <fph2137_at_[hidden]>
Date: Fri, 20 Dec 2024 09:45:15 +0100
Hi,

I made a proposal about this problem earlier and I still believe that using continue/break with labels is just a nice looking goto.

I would prefer using some syntax manipulation and using ‘break for while’ , instead of ‘break outerWhileLabel’.

Both approaches solve the problem but the goto replacement seems like it would clutter the code with labels that we have to detect to be a control flow label. Maybe it should be done with attribute as a label? But then it would be too long to write and hard to read. That’s why I like mine minimalist approach, what do you think?

Cheers,
Filip

> Wiadomość napisana przez Lénárd Szolnoki via Std-Proposals <std-proposals_at_[hidden]> w dniu 19 gru 2024, o godz. 22:41:
>
> 
>
>> On 19 December 2024 21:31:42 GMT, "Lénárd Szolnoki via Std-Proposals" <std-proposals_at_[hidden]> wrote:
>>
>>
>>> On 19 December 2024 17:21:15 GMT, Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
>>> On Thursday 19 December 2024 14:07:20 Brasilia Standard Time Richard Hodges
>>> via Std-Proposals wrote:
>>>> extern bool cond();
>>>> extern void something(int);
>>>>
>>>> void test()
>>>> {
>>>> while (cond())
>>>> {
>>>> for (int i = 0 ; i < 100 ; ++i) {
>>>
>>> SomeNonTrivialType t;
>>>
>>>> if (i == 50) goto continueat1;
>>>> something(i);
>>>> }
>>>
>>> SomeNonTrivialType t;
>>>
>>>> continueat1: ;
>>>> }
>>>> }
>>>
>>> Now this can't compile. You'll need an extra scope to ensure that no non-
>>> trivial type lifetimes start OR end between the goto statement and the target
>>> label. For the second variable in the modified example above, it suffices to
>>> place a scope that starts after the for and ends before the label.
>>>
>>> For the first one, there's no solution. You can't goto out of a block with a
>>> live variable whose destructor isn't trivial (assumption: you need that
>>> variable).
>>
>> That is incorrect, you can, and the destructor is called.
>
> See https://eel.is/c++draft/stmt.dcl#2 for reference and example,
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-12-20 08:45:29