[GCC-XML]gccxml and templates?

andy.glew at amd.com andy.glew at amd.com
Mon Oct 20 22:47:50 EDT 2003


> > Q: GCC-XML handles nested classes, but doesn't appear to support
> > templates.
> >
> > Can anyone tell me this ain't so?
> 
> It does support templates, but the dump currently does not include
> uninstantiated templates.  The dump will include any instantiated
> templates in the translation unit. Try running GCC-XML on 
> this program:
> 
> template <class T> struct A {};
> 
> // Using :: to access a member forces instantiation:
> typedef A<int>::A A_int;
> 
> This may be sufficient for your purposes because you have to 
> instantiate a
> class template before it is useful anyway.  You can generate print
> functions/accessors for any instantiations your program uses.
> 
> -Brad


Well, one of the reasons that I want to use gccxml is
to implement a code checking/generation tool that 
   (a) checks that templates obey certain rules
   (b) ensures that templates have been instantiated
       and tested - if you will, a test coverage tool
       for templates
            e.g. given a template<class T>
       tests it with implementations of classes
       that it is expected to handle;
       conversely, which ensures that template<typename T>foo
       can be instantiated as foo<int> or foo<char>.
            i.e. default tests for templates
   (c) generates certain pieces of code that the
       template requires - such as, default methods.

I.e. I want to use the code I generate (from a tool
that looks at gccxml) to instantiate the template.



But, okay, I'm used to this sort of limitation:
SWIG has the same problem.  Easy enough to work around.





More information about the gccxml mailing list