foreach problem
    Dejan Lekic 
    dejan.lekic at gmail.com
       
    Fri Jan  5 02:10:42 PST 2007
    
    
  
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.
Kind regards
Dejan
-- 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
-- foreach_ok.d ----------8<------------------------------------------
import std.stdio;
int main(char[][] args) {
  foreach (char[] arg; args)
    writefln(arg);
  return 0;
}
-- version info ----------8<------------------------------------------
Digital Mars D Compiler v1.0
GCC 4.1.1
GNU/Linux (Fedora Core 6, linux 2.6.18)
    
    
More information about the Digitalmars-d-bugs
mailing list