Spurious warnings generated by -Wshadow

Kevin P. Fleming kpfleming@digium.com
Tue Apr 12 21:18:00 GMT 2011


The gcc manpage has this to say:

> -Wshadow
> Warn whenever a local variable shadows another local variable, parameter or global variable or whenever a built-in function is shadowed.

However, compiling this code (with g++ 4.4.x or 4.5.x) using -Wshadow:

class foo {
         void baz() {
         }

         int bar(int baz) {
         }
};

produces this diagnostic:

test1.cpp: In member function ‘int foo::bar(int)’:
test1.cpp:5: warning: declaration of ‘baz’ shadows a member of 'this'

'baz' is not a local variable, nor a parameter, nor a global variable or 
a built-in function. I'm not necessarily saying that this warning is not 
useful, but the manpage doesn't say anything about shadowing member 
functions being something that -Wshadow will warn about.

Is the documentation just trailing the code here?

-- 
Kevin P. Fleming
Digium, Inc. | Director of Software Technologies
Jabber: kfleming@digium.com | SIP: kpfleming@digium.com | Skype: kpfleming
445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
Check us out at www.digium.com & www.asterisk.org



More information about the Gcc-help mailing list