Error: shadowing declaration is deprecated

Bill Baxter dnewsgroup at
Sun Dec 24 15:52:12 PST 2006

jicman wrote:
> == Quote from Bill Baxter's article
>> jicman wrote:
>>> Greetings!
>>> this code,
>>>   foreach(char[] u; FPUsers)
>>>   {
>>>   }
>>> results in,

> Ok, I'll buy that, but this is not working either:
> char[] u;
> foreach(u; FPUsers)
> {
> }
> That should work.

Ah ok, good point.  This is because foreach(u; blah) is always taken to 
mean foreach(auto u; blah).   It's a little special case to save some 
typing.  I think it's a bad idea to have such a special case, but oh 
well.  Now that you mention it I do remember ranting about this one at 
one point, but I wasn't annoyed enough by it to follow through.  For one 
it means that you can't have a loop variable in a foreach that 
'escapes', which eliminates some handy patterns like
    char[] u;
    foreach(u; FPUsers) { if match(u) break; }
    /* use u here */

Maybe there's some reason for this that has to do with how foreach is 
implemented for classes?  But I don't see how that could be the case 
when this certainly works:
    char[] u;
    foreach(utmp; FPUsers) { u=utmp; if match(u) break; }
    /* use u here */

Anyway foreach could certainly be smarter than it is.  For instance I 
believe the magic 'int' return value that opApply implementations must 
handle and diligently return back to their caller could be eliminated 
with some hidden variables on the stack.  But Walter and others here 
don't seem to see that as a wart for some reason.


More information about the Digitalmars-d-learn mailing list