foreach problem

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Fri Jan 5 02:49:00 PST 2007


Dejan Lekic wrote:
> Compiling foreach_bug.d produces an error, while compiling foreach_ok.d does
> not. IMHO that is a bug - it is clearly stated in current specification of The
> Language (http://www.digitalmars.com/d/statement.html#ForeachStatement) that
> variable can be declared outside.

No it's not. I just reread all of it. I didn't find any mention of that, 
nor a code sample that would support your case.
Furthermore, if it _did_ state that somewhere, it'd be a 'bug' in the 
specification, not in the compiler.

> -- foreach_bug.d ---------8<------------------------------------------
> import std.stdio;
> 
> int main(char[][] args) {
>   char[] arg;
>   foreach (arg; args)  // (*)
>     writefln(arg);
>   return 0;
> }
> // (*) Error: shadowing declaration foreach_bug.main.arg is deprecated


More information about the Digitalmars-d-bugs mailing list