[cfe-dev] -Wshadow rationale for data members

Douglas Gregor dgregor at apple.com
Thu Oct 21 08:17:45 PDT 2010


On Oct 21, 2010, at 2:43 AM, Axel Naumann wrote:

> Hi,
> 
> struct A {
>   static void* f; void* g;
>   struct B { static void* f; void* g; };
> };
> struct C { static void* f; void* g;};
> struct D: public C { static void* f; void* g; };
> 
> compiled with
> clang++ -c -Wall -Wshadow -O2 t.cxx
> generates the warning
> 
> t.cxx:3:28: warning: declaration shadows a static data member of 'A'
> [-Wshadow]
>   struct B { static void* f; void* g; };
>                           ^
> t.cxx:2:17: note: previous declaration is here
>   static void* f; void* g;
>                ^

It doesn't seem at all useful for Clang to warn about static data members shadowing something else by the same name. Personally, I'd limit -Wshadow to only complain when a local declaration shadows something from the outer scope.

	- Doug



More information about the cfe-dev mailing list