In the following example:
class A
{
public:
int len();
void setLen(int len) { len_ = len; } // warning at this line
private:
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 consensus of what "shadow" means. And from a formal point of view, the compiler does exactly what it's meant to do.
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 was 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 issues tons 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, are there other gcc warning flags that do what I described?
Update 2
I'm not the only one who thinks -Wshadow is somehow not useful link text. I'm not alone :) Less strict checking could be much more useful.