Date: Thu, 19 Dec 2024 21:31:42 +0000
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.
Cheers,
Lénárd
>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.
Cheers,
Lénárd
Received on 2024-12-19 21:31:49