Hi John,

I have made good progress today with the help of your comments.  I’ll test some 
more before submitting the new patch.

Le 2010-08-30 à 21:08, John McCall a écrit :

On Aug 30, 2010, at 5:33 PM, Benoit Belley wrote:
I think that I’ll need a bit more explanation here. The infinite recursion 
occurs while traversing the instantiations of the class template definition and 
I do want to traverse these instantiations. That’s the whole point of my 
proposed change.

Yes, I understood that.  My point is that you're visiting the instantiations 
regardless of whether the current template declaration you're visiting is a 
redeclaration or not.  This creates two problems:  first, you end up visiting 
the instantiations multiple times if the template is redeclared; and second, if 
the template is redeclared within itself (which can only be done with friend 
declarations), you end up visiting it recursively, which blows up the stack.  
The solution is to only visit implicit instantiations when you visit a pattern 
definition.

 template <class T> class A;  // <- don't visit any instantiations here
 class B { template <class T> friend class A; };  // <- or here
 template <class T> class A { ... }; // <- okay to visit implicit 
instantiations here

By the way, here’s one more bit of information.  The problem does not occur 
when the template is explicitly instantiated:

Yes, because your implementation of TraverseImplicitClassInstantiations ignores 
explicit instantiations.  So when you visit the explicit instantiation, you 
visit its friend decl, whereupon you visit all the implicit instantiations, 
which (as long as there are none) doesn't cause an infinite recursion because 
you ignore the explicit instantiation.


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 ?



Also, can you explain why you're not visiting the written type of explicit 
specializations when your flag is set?  That doesn't seem very general.


Miscomprehension of the Clang AST from my side...


John.
_______________________________________________
cfe-commits mailing list
[email protected]<mailto:[email protected]>
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits


Thanks for being patient. I am new to the Clang AST, so I am learning as I go.
Benoit


Benoit Belley
Sr Principal Developer
M&E-Product Development Group

Autodesk Canada Inc.
10 Rue Duke
Montreal, Quebec  H3C 2L7
Canada

Direct 514 954-7154



[cid:[email protected]]


<<inline: image002.gif>>

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to