Red Hat Bugzilla – Bug 32160
g++ produces bogus warnings when -Wshadow is given
Last modified: 2007-04-18 12:32:15 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.76 [en] (X11; U; Linux 2.2.16-22smp i686)
According to the man page, the purpose of -Wshadow is to warn whenever a
local variable shadows another local variable. However, it also gives you
undesirable warnings when a local variable shadows a global variable.
Steps to Reproduce:
Just compile the code below with g++ -Wshadow
int main ()
Actual Results: In file included from
/usr/include/g++-3/std/bastring.cc: In function `istream &getline
(istream &, basic_string<charT, traits, Allocator> &, charT)':
/usr/include/g++-3/std/bastring.cc:479: warning: declaration of `count'
shadows global declaration
Expected Results: Since count is global, g++ should not issue that
Maybe -shadow should be split into two: -shadow-local and -shadow-global.
I've changed bastring.cc so that you don't get this warning for it.
Concerning behaviour of -Wshadow, the documentation is just incomplete,
gcc has been warning about shadowing many things for very long time and this
behaviour has not changed. E.g. it warns if a static function shadows
a builtin, local variable shadows a parameter etc.
These two changes are in gcc 2.96-80.