Comment #0 by pro.mathias.lang — 2019-08-29T03:11:02Z
The following code:
```
string foo () { return null; }
void main ()
{
if (auto str = foo())
{
assert(str.length);
L1:
}
else
goto L1;
}
```
Produces "oa.d(10): Error: goto skips declaration of variable oa.main.str at oa.d(5)"
But the variable is not used after L1.
Comment #1 by razvan.nitu1305 — 2023-04-18T11:06:29Z
The compiler does not do any dataflow analysis so it cannot know whether `str` is used or not below L1. However, `str` could be used, therefore the compiler is conservative in this case and errors. In most cases, I think that the error could actually prevent wrong code.
Anyway, if last use analysis is implemented for move constructors/perfect fordwarding maybe this will have a chance of being fixed, however, chances are slim.
Comment #2 by robert.schadek — 2024-12-13T19:05:17Z