Annoyance: 'Shadowing declaration is deprecated'+ mixins
Don Clugston
dac at nospam.com.au
Tue Jul 24 23:32:03 PDT 2007
Bill Baxter wrote:
> Don Clugston wrote:
>> Is there any chance of getting the 'shadowing declaration is
>> deprecated' error message disabled, for code inserted via a mixin?
>>
>> It means that if you inject a 'for' loop into the current function, it
>> appears to work, but will fail if another variable with the same name
>> already exists.
>>
>> void main()
>> {
>> // double i=300.0;
>> mixin("for (int i=0; i<10; ++i) { func(i); }");
>> }
>>
>> When such code is generated by a mixin, the shadowing does not
>> indicate a probable error.
>>
>> This is proving to be quite annoying for my BLADE rewrite.
>
> I guess one obvious solution is to give your counter variables some
> names that are more likely to be unique:
>
> mixin("for (int __i8473=0; __i8473<10; ++__i8473) { func(__i8473); }");
Yes. Although I don't like "likely" <g>. More difficult is the situation when
the mixin is recursive. Each nested level needs to use a different name.
More information about the Digitalmars-d
mailing list