C++ Logo

std-proposals

Advanced search

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

From: Jan Schultke <janschultke_at_[hidden]>
Date: Thu, 19 Dec 2024 09:17:48 +0100
> It will break all current usages of labels that have one of those control flow gadgets following it.

How so?

> label: while (true) { /* .. */ }
> goto label;

This code was valid, and remains valid. No code is broken.

> Why couldn't
> for <extra properties of the for loop, like the name> ()
> work as well?

Because the precedent is that the first keyword states what control
flow takes place, and the subsequent keyword modifies it in some way.

Only declarations have an identifier which states the name, such as
"class X", "int X", etc., but control flow is not a declaration. To be
fair, this is not a technical empirical argument; it just "feels"
wrong to think of a for loop as something like a declaration.

Furthermore, labels and declaration names are completely separate
pots. It wouldn't make sense for "x = 0;" to look up the name of a
label "x:", only the name of declarations. The syntax "for name(...)"
implies that something is being declared, similar to "int x(...)", but
that is not the case. I find this to be misleading.

Received on 2024-12-19 08:18:01