C++ Logo

std-proposals

Advanced search

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

From: Jan Schultke <janschultke_at_[hidden]>
Date: Fri, 20 Dec 2024 10:26:12 +0100
Hi Filip, thanks for your feedback.

> 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 saw that, and I very briefly discuss it under
https://eisenwave.github.io/cpp-proposals/break-continue-label.html#why-not-break-n
In my opinion, even if we designed from a blank slate, "break N" or
"break break" or "break for" are much harder to reason about when you
start nesting loops more deeply. It's also possible to break or change
the meaning of code when replacing a while loop with a for loop, a
loop with an if statement, etc.

The only other language that takes this non-label approach is PHP, so
there's very little precedent in other languages. On the contrary,
there is tons of precedent for "break label" in other mainstream
languages; see https://eisenwave.github.io/cpp-proposals/break-continue-label.html#argumentum-ad-populum
Just counting source files on GitHub, we have hundreds of thousands of
such uses. "break label' is what people expect. It works.

However, also keep in mind that C2y has already decided on having
"break label", and even N3377 does not fundamentally change that
design. Your idea is not C-compatible (neither with N3355 nor with
N3377), and that's reason alone not to pursue it further.

> Maybe it should be done with attribute as a label?

Attributes are designed as information that the compiler is free to
ignore. "break label" cannot refer to a label that's simply ignored by
the compiler in some way, so attributes are not an option.

Received on 2024-12-20 09:26:29