gcc-4.0 non-local variable uses anonymous type warning

William S Fulton wsf@fultondesigns.co.uk
Mon May 9 16:06:00 GMT 2005


James E Wilson wrote:
> William S Fulton wrote:
>> test.cxx:15: warning: non-local variable ‘<unnamed>::<anonymous enum> 
>> <unnamed>::InstanceÂ’ uses anonymous type
> 
> Just grepping the sources for the warning, I find this comment
>       /* [basic.link]: A name with no linkage (notably, the name of a class
>          or enumeration declared in a local scope) shall not be used to
>          declare an entity with linkage.
>          Only check this for public decls for now.  */
> Also this:
>                   /* DRs 132, 319 and 389 seem to indicate types with
>                      no linkage can only be used to declare extern "C"
>                      entities.  Since it's not always an error in the
>                      ISO C++ 90 Standard, we only issue a warning.  */
> 
>>   static enum { foo, bar = 10 } Instance;
> 
> The "public decls" comment above means that we deliberately don't emit 
> the warning for static variables, but it is possible this may change in 
> the future.  It may depend on how the defect reports get resolved.
> 
> I'm not a C++ expert, and don't have a copy of the C++ standard, so I 
> can't comment further.

Interesting, thanks James. Indeed, the warning disappears when the enum 
declaration is made extern "C" and that is good enough for me :)

William



More information about the Gcc mailing list