[cfe-dev] Patch: Re: -Wshadow rationale for data members

John McCall rjmccall at apple.com
Fri Nov 12 10:11:53 PST 2010


On Nov 12, 2010, at 1:19 AM, Adam Nohejl wrote:

>>> 2.5. An enum constant cannot shadow or be shadowed. Do you agree that enum constants should be treated similarly to variables or, within a class/structure context, to static data members?
>> 
>> I think we shouldn't warn about shadowing enumerators.
> 
> I'm not sure whether we mean the same thing. I mean "a" (enum constant), not "A" (enum tag), in "enum A{a};".

Yes.  The constants are sometimes also called enumerators; sorry for being unclear.

> Enum constants are little different from variables/static data variables: they can be defined at the same places, have the same scoping rules, and can mostly be used in the same syntactic context (of course there's no storage associated with enum constants).

> I can't see why there should be any difference between how x's and y's are handled in the following:

I am primarily worried about flooding the world with -Wshadow warnings that we, and gcc, have never emitted before.  On the other hand, I don't personally enable -Wshadow, and it's not part of -Wall, and I can't deny the inconsistency, so if you think that -Wshadow should warn about shadowing enumerators (treating them as static variables when they're class members) then we can try that experiment.

John.



More information about the cfe-dev mailing list