https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68374
Bug ID: 68374
Summary: G++ -Wshadow doesn't warn about static member
shadowing
Product: gcc
Version: 5.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: xyzdragon at fastmail dot fm
Target Milestone: ---
This bug seems to be related to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45615 but the code example is a
bit different, so I'm not sure. Delete this if necessary.
This is the source code in question:
class f {
static int mVar;
int g(int x) { int mVar=3; return x+mVar; }
};
int f::mVar = 1;
The problem is, that I accidentally added int in front of mVar. When I compile
this with:
g++ -c -Wall -Wextra -Wshadow shadowtest.cpp
I don't get any warning, about the local mVar shadowing the static member mVar.
But if I don't declare the member variable to be static, then g++ correctly
issues a warning:
class f {
int mVar;
f(int rVar) : mVar(rVar) {};
int g(int x) { int mVar=3; return x+mVar; }
};
compile with g++ -c -Wall -Wextra -Wshadow shadowtest2.cpp gets:
shadowtest2.cpp:5:24: warning: declaration of ‘mVar’ shadows a member of ‘f’
[-Wshadow]
int g(int x) { int mVar=3; return x+mVar; }
^
shadowtest2.cpp:3:9: note: shadowed declaration is here
int mVar;
^
Note, as pointed out by other stack users
http://stackoverflow.com/questions/33739066/ and also tested myself clang++
behaves like I would have expected g++ to behave, that's why I'm filing this as
a bug.
The above behavior is the same in g++ 4.9.2 and g++ 5.2.1-17