Declaration in expression - Re: Python-like Use of the Comma Expression
Nick Treleaven
nick at geany.org
Fri Aug 11 12:16:49 UTC 2023
On Thursday, 10 August 2023 at 21:38:25 UTC, Basile B. wrote:
> whe have var decl syntax for `if`, since recently for `while`
> too... It's pretty clear that "in situ" variable decls are
> required...unless D continues on making special cases.
For `if (auto x = expr)`, the scope of `x` includes the
*ThenStatement*.
For `if ((auto x = expr) || b)`, `x` can have similar scope.
For `if (b && (auto x = expr))`, `x` can have similar scope.
I think the above two cases could be supported in D.
For `if (b || (auto x = expr))`, `x` may be uninitialized if it
is accessible in the *ThenStatement*. Does Styx forbid that and
similar cases?
Also for `if (b || ((auto x = expr) && x.b))`, `x` is safely used
but it may be uninitialized if its scope extends to the
*ThenStatement*.
More information about the Digitalmars-d
mailing list