In the following example:
class A
{
int len();
void setLen(int len) { len_ = len; } // warning at this line
int len_;
};
gcc with -Wshadow issue a warning:
main.cpp:4: warning: declaration of `len' shadows a member of `this'
function len and integer len are of different type. Why the warning?
Update
I see there's a wide cocensuse what "shadow" means. And from formal point of view the compiler do exactly what it meant too.
However IMHO, the flag is not practical. For example commonly used setter/getter idiom :
class A {
void prop(int prop); // setter
int prop() const; // getter
int prop;
};
It would be nice if there will be a warning flag that won't issue warning in the case, but will warn in case "int a" hides "int a".
Adding -Wshadow on my legacy code issue tones of warnings, while from time to time I discover bugs caused by "shadowing" problem.
I don't mind how it will be called "-Wmuch_more_practical_and_interesting_shadow" or "-Wfoooooo".
So, is there're other gcc warning flag that does what I described?
Update 2
Not only me thinks -Wshadow somehow not usefull link text. I'm not alone :) Less strict checkings could be much more usefull.