Folks, I really like the -Wshadow option since it helps to spot some possible problematic pieces of code. I want to use it in a really large project but I can’t since it’s too strict. For example it throws a warning for the following case:
struct Foo
{
Foo(int info) : info_(info) {} //shadow warning is here
void info(){ ... }
int info_;
};
gcc throws a warning about “int info” variable shadowing “void info” method in constructor which is… well, not really a useful warning for me.
What I really care about is cases such as the following:
int i = 0;
for(int j=0;j<10;++j)
{
int i = j; //local scope variable "int i" shadows outer scope variable
++i;
}
Is it possible to make gcc warn about these cases only?
For external libraries you can try to specify their include path with
-isysteminstead of-I, this will cause gcc to stop reporting warnings in them most of the time.When the warning only pops up in a few limited cases you can work around it with:
#pragma GCC diagnostic ignored "-Wshadow"For the rest of the cases refactoring the code or doing the
greptrick Peter mentioned seem to be the only options.