C++ Logo

std-proposals

Advanced search

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

From: Tiago Freire <tmiguelf_at_[hidden]>
Date: Thu, 19 Dec 2024 07:18:20 +0000
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.


The problem is, if
`
name: for()
{
}
`
names the "for" the loop, so does this:
`
name:

for()
{}
`

Now, did I mean name the "for" or create a "goto label"?

I should still be able to create a jumpable label that is followed by a for/while/do/switch without accidentally naming the control flow gadget instead of creating the label that I wanted.

For that reason, N3355 syntax is dead in the water. N3377 syntax:
`for name ()`
is workable within the status quo of the language.
But so would:
`[[name=Myname]] for ()`
although I have to admit the later has the issue of ignorable attributes.

Even tough there are interesting point being raised regarding goto, I'm afraid it just isn't the right tool, a goto can only motion towards a singular jump point while flow statements like for/while/do define 2 jump points (to continue the iteration or to stop the iteration and break out, i.e. break/continue), and while switch has only 1 break out point using goto would still not be satisfactory as you would typically want to jump to the end of the switch statement and not to beginning (and try the switch statement again) where the "label/name" would typically be defined.

Received on 2024-12-19 07:18:23