[GCC-XML]RE: typdef vs. tagged enums

Brad King brad.king at kitware.com
Thu Apr 1 11:02:57 EST 2004


John Waggenspack wrote:
> Outlook mangled my last message.  Here it is again.
> 
> These enums:
>     enum tagged {
>         tagged0
>     };
> 
>     typedef enum {
>         tdeffed0
>     } tdeffed;
> 
> Generate the following xml:
>     <?xml version="1.0"?>
>     <GCC_XML>
>       <Namespace id="_1" name="::" members="_3 _4 " mangled="_Z2::"/>
>       <Namespace id="_2" name="std" context="_1" members="" mangled="_Z3std"/>
>       <Enumeration id="_3" name="tdeffed" context="_1" location="f0:8" file="f0" line="8">
>         <EnumValue name="tdeffed0" init="0"/>
>       </Enumeration>
>       <Enumeration id="_4" name="tagged" context="_1" location="f0:2" file="f0" line="2">
>         <EnumValue name="tagged0" init="0"/>
>       </Enumeration>
>       <File id="f0" name="test.h"/>
>     </GCC_XML>
> 
> Note there is no difference in the XML output for the two different styles of enum specification.
> 
> However, gcc 2.95 expect functions that use these enums to have different signatures.  
> 
> This compiles without errors:
>     #include "test.h"
>     extern void foo();
> 
>     enum tagged returnTagged()
>     {
>         return(tagged0);
>     }
> 
>     tdeffed returnTdeffed()
>     {
>         return(tdeffed0);
>     }
> 
>     void useTagged(enum tagged e)
>     {
>         if (e == tagged0)
>             foo();
>     }
> 
>     void useTDeffed(tdeffed e)
>     {
>         if (e == tdeffed0)
>             foo();
>     }
> 
> This has errors:
>     #include "test.h"
> 
>     extern void foo();
> 
>     tagged returnTagged()
>     {
>         return(tagged0);
>     }
> 
>     enum tdeffed returnTdeffed()
>     {
>         return(tdeffed0);
>     }
> 
>     void useTagged(tagged e)
>     {
>         if (e == tagged0)
>             foo();
>     }
> 
>     void useTDeffed(enum tdeffed e)
>     {
>         if (e == tdeffed0)
>             foo();
>     }
> 
>  gcc -c test_ERRORS.c
>     test_ERRORS.c:5: syntax error before `returnTagged'
>     test_ERRORS.c:11: return-type is an incomplete type
>     test_ERRORS.c: In function `returnTdeffed':
>     test_ERRORS.c:12: warning: `return' with a value, in function returning void
>     test_ERRORS.c: At top level:
>     test_ERRORS.c:15: syntax error before `e'
>     test_ERRORS.c: In function `useTagged':
>     test_ERRORS.c:17: `e' undeclared (first use in this function)
>     test_ERRORS.c:17: (Each undeclared identifier is reported only once
>     test_ERRORS.c:17: for each function it appears in.)
>     test_ERRORS.c: At top level:
>     test_ERRORS.c:22: parameter `e' has incomplete type
> 
> Is there anyway to have the generated XML indicate if an enum is
> typedefed?

There is now.  I've just committed a change to the CVS and 0.6 release 
branch versions that will add an attribute to the "tagged" enumeration 
like this:

<Enumeration id="_4" name="tagged" context="_1" location="f0:2" 
file="f0" line="2" artificial="1">

Note the new "artificial" attribute.  The only difference in the GCC 
internal representation between the "tagged" and "tdeffed" TYPE_DECL 
nodes is that the former is marked "artificial" since it is an implicit 
typedef generated by GCC and not written explicitly by the user.  In C++ 
there is not much difference, but as you pointed out it does matter for 
C.  This change should let you tell them apart.

You can get the updated 0.6 version with tag gccxml-0-6 from the CVS 
repository.

-Brad




More information about the gccxml mailing list