Bug 45615 - -Wshadow doesn't report class member shadowing
Summary: -Wshadow doesn't report class member shadowing
Status: RESOLVED DUPLICATE of bug 12341
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2010-09-09 14:56 UTC by Joseph Garvin
Modified: 2021-10-25 05:10 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-11-13 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Joseph Garvin 2010-09-09 14:56:06 UTC
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.
Comment 1 Jonathan Wakely 2010-09-09 16:31:17 UTC
I agree this would be useful, I've had problems with such shadowing when moving members higher in inheritance hierarchies and accidentally missing occurrences in some derived classes.

4.2 is unmaintained now, but current releases don't warn either.
Comment 2 Trass3r 2018-11-14 02:29:29 UTC
Confirmed on trunk: https://godbolt.org/z/jL0ony
Comment 3 Eric Gallager 2018-11-14 03:18:25 UTC
(In reply to krux from comment #2)
> Confirmed on trunk: https://godbolt.org/z/jL0ony

OK, updating "Last reconfirmed" date then
Comment 4 Andrew Pinski 2021-10-25 05:10:31 UTC
Dup of bug 12341.

*** This bug has been marked as a duplicate of bug 12341 ***