Date: Tue, 17 May 2022 23:37:31 +0100
On Mon, 16 May 2022 at 08:33, Sebastian Wittmeier <
wittmeier_at_[hidden]> wrote:
> But with a nonlinear program flow (including simple loops or
> conditionals), this can get really problematic.
>
>
>
> void f() {
>
> string s1, s2, s3;
>
> if (flag)
>
> s2 = reloc s1; // removes s1 from lexical scope
>
> else
>
> s3 = reloc s1; // !!! compilation error
>
> }
>
The rule is that if a variable is removed within a substatement of an if
statement, and is not explicitly removed within the other substatement,
then it is implicitly removed *at the end* of the other substatement
(calling its destructor, if appropriate).
As for loops, it is ill-formed to jump over such an expression, in the same
way as it is ill-formed to jump over the initialization of an automatic
variable; so within a loop you can only reloc automatic variables declared
within that loop.
>
wittmeier_at_[hidden]> wrote:
> But with a nonlinear program flow (including simple loops or
> conditionals), this can get really problematic.
>
>
>
> void f() {
>
> string s1, s2, s3;
>
> if (flag)
>
> s2 = reloc s1; // removes s1 from lexical scope
>
> else
>
> s3 = reloc s1; // !!! compilation error
>
> }
>
The rule is that if a variable is removed within a substatement of an if
statement, and is not explicitly removed within the other substatement,
then it is implicitly removed *at the end* of the other substatement
(calling its destructor, if appropriate).
As for loops, it is ill-formed to jump over such an expression, in the same
way as it is ill-formed to jump over the initialization of an automatic
variable; so within a loop you can only reloc automatic variables declared
within that loop.
>
Received on 2022-05-17 22:37:43