C++ Logo

std-proposals

Advanced search

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

From: Lénárd Szolnoki <cpp_at_[hidden]>
Date: Thu, 19 Dec 2024 21:40:57 +0000
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,

Received on 2024-12-19 21:41:14