[cfe-commits] [Patch][Review request] RecursiveASTVisitor can now traverse template specializations

John McCall rjmccall at apple.com
Tue Aug 31 15:24:49 PDT 2010


On Aug 31, 2010, at 2:57 PM, Benoit Belley wrote:
> I have made good progress today with the help of your comments.

Glad to hear it!

> Visiting the class template definition while skipping the re-declarations turns out to be not so obvious. FunctionDecl and VarDecl have isThisDeclarationADefiniton(). RecordDecl has getDefintion()... But, ClassTemplateDecl has none of this. I have found that the following trick seems to work in practice:
> 
>    ClassTemplateDecl* D = ...;
>    CXXRecordDecl* TemplDecl = D->getTemplatedDecl();
>    if (TemplDecl) {
>      if (CXXRecordDecl* TemplDef = TemplDecl->getDefinition()) {
>        if (TemplDecl == TemplDef) {
>          TRY_TO(TraverseImplicitClassInstantiations(D));
>        }
>      }
>    }
> 
> Is this the correct approach ?

This works, but it's sufficient to call isDefinition() on the templated decl.  I've also just added isThisDeclarationADefinition() overloads to the template decls, so it should be even easier. :)

John.



More information about the cfe-commits mailing list