The following simple test program when compiled with -Wshadow produces no
output. I'd expect to get warnings for both the x and y declaration in class B.

class A {
        static int x;
        int y;
};

class B : public A {
        static int x;
        int y;
};

int main()
{
        B a;
        return 0;
}

If this is intentional, perhaps another -W flag is appropriate. I spent about
an hour trying to figure out why an app broke when I change a static class
member declared in a class's header to instead be an anonymous global in that
class's source file, and it was because all of the source file's references to
the variable after the change went to a parent class variable of the same name
and type rather than the global.


-- 
           Summary: -Wshadow doesn't report class member shadowing
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: joseph dot h dot garvin at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45615

Reply via email to