Annoyance: 'Shadowing declaration is deprecated'+ mixins

downs default_357-line at yahoo.de
Tue Jul 24 10:43:48 PDT 2007


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.
There's a workaround, but it's slightly perverted.

void main()
{
	double i=300.0;
	() { mixin("for int i=0; i<10; ++i) { func(i); }"); }();
}

This declares and calls a delegate in the same line, thereby establishing a distinct scope.
Beware performance degredation though.
  --downs



More information about the Digitalmars-d mailing list