Date: Thu, 19 Dec 2024 10:00:28 +0100
>From a compiler perspective, it could have to produce slightly different code, when encountering `goto label` vs. `break label` or `continue label`.
But that is no problem, as long as the labels do not span translation units.
From a control flow perspective, either goto label or keyword label or return potentially jump more than one scope, but so does break or continue, if the intermediate scopes do not use break. labels are eiter at the beginning of the line (often without any indentation, sometimes with) or directly in front of the instruction or in the line before. The same could be okay for naming constructs. If you do break label, the target is easier to be found, if the label is in front, as it could be a while, a for loop, a do for loop, a case switch.
What is not the nice is
myfor:
for (int i = 0, Object o; i < 10; i++) {
if (stay())
continue myfor;
break;
}
The myfor label is outside of the for loop, but continue myfor does not destroy o and constructing a new one, but stays inside the loop.
In this case, naming locations in the program (which would be here outside the while scope) and naming the for loop itself, clash.
Currently, when writing a goto version of the for loop above, the label would have to go inside the for loop.
{
int i = 0;
Object o;
myfor:
if (stay())
goto myfor;
i++;
if (i < 10)
goto myfor;
}
So the label is placed differently between the labeled for loop and the equivalent (currently valid) goto version.
We probably need the following ;-)
for (int i = 0, Object o;
myfor:
i < 10; i++) {
if (stay())
continue myfor;
break;
}
-----Ursprüngliche Nachricht-----
Von:Tiago Freire via Std-Proposals <std-proposals_at_[hidden]>
Gesendet:Do 19.12.2024 08:18
Betreff:Re: [std-proposals] Bringing break/continue with label to C++
An:std-proposals_at_[hidden];
CC:Tiago Freire <tmiguelf_at_[hidden]>;
I personally agree with N3377, N3355 is simply too ambiguous and would break code.
Let's think about what we are trying to achieve in this case.
We are just trying to give a name to a for/while/do/switch such that when we use "break/continue", we are able to identify exactly which for/while/do/switch do we mean.
Calling it a "label" is slightly misleading as it leads to confusion with the "goto label" which names a singular point in the code that can be jumped into regardless of any surrounding code (within certain limitations).
We are trying to name a control flow statement, not create a jump point.
Received on 2024-12-19 09:02:43