Missing compiler warning?
Jonathan M Davis
jmdavisProg at gmx.com
Fri Oct 18 10:42:10 PDT 2013
On Friday, October 18, 2013 18:32:32 bearophile wrote:
> Currently D doesn't give an error or warning if in a method you
> declare a local variable with the same name of a instance member.
> This is indeed a source of bugs and I have had similar problems.
> Generally D prefers to minimize the number of warnings, so
> according to the D style that should become an error.
There's no way that that's ever going to become an error. It's just too
useful. The issue has come up before, and it's not going away. The prime
example is constructors.
this(int a, string b)
{
this.a = a;
this.b = b;
...
}
Too many people would get annoyed if they were required to name their local
variables differently - especially in a case like this. If you want to avoid
the problem, then just don't name your local variables the same as your member
variables - the most obvious solution being to do name your member variables
differently - e.g. by prepending them with _.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list