gcc -Wshadow is too strict?

The fact that the parameter has a different type from the member function doesn't affect the fact that the parameter shadows the member function.

Why would you expect there not to be a warning about this?


This seems to be solved on newer versions of GCC.

From version 4.8 changelog:

The option -Wshadow no longer warns if a declaration shadows a function declaration,
unless the former declares a function or pointer to function, because this is a common
and valid case in real-world code.

And it references Linus Torvalds's thoughts on the subject: https://lkml.org/lkml/2006/11/28/253

Unfortunately the newest compiler of the embedded system where I'm currently working is still based on gcc 4.6.


I don't understand why you insist only on some specific types of shadowing. Shadowing is shadowing, and the dangers of it are the same even if the types are different and even if a variable shadows a function, as in your case. The danger of shadowing is that the code might do something different from what its author wanted it to do.

This, BTW, can easily happen when a variable is shadowing a function, since in C++ the distinction between the two is much thinner than it might seem at the first sight.

For example, here a variable shadows a function

struct L { 
  void operator ()(); 
};

struct A {
  void len();

  A(L len) {
    len();
    // Intended to call the member function. Instead got a call to the functor
  }
};

and I think it is pretty obvious that because of the shadowing the code might do something the author did not intend it to do.