dmd
dmd copied to clipboard
Deprecate using an unqualified symbol defined in a `do`–`while` loop in its condition
When a symbol (usually a variable) is defined in the body of a do–while loop, it’s not in scope anymore in the condition. That means, the name of the symbol might refer to a different symbol in some outer scope (e.g. a member or global variable). That use should be deprecated. It’s almost certainly a bug, and if it’s not, it can be clarified using this.name or .name.
int x;
struct S
{
int y;
void f()
{
do
{
int x, y;
…;
}
while (x > y); // likely a bug
}
}
In the example above, one would have to change the condition to while (.x > this.y) or rename the local variables.