Date: Thu, 19 Dec 2024 14:21:15 -0300
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).
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).
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel DCAI Platform & System Engineering
Received on 2024-12-19 17:21:24