<div dir="ltr">On Tue, Sep 17, 2013 at 7:56 AM, Joshua Naismith <span dir="ltr"><<a href="mailto:fakju666@o2.pl" target="_blank">fakju666@o2.pl</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I have this example code:<br>
<br>
>>>>>>>>>>>>>>>>>><br>
template <class T><br>
class D {<br>
  public:<br>
    static void f(int c) {int b = c;}<br>
};<br>
int main(){ D<char>::f(0); }<br>
<<<<<<<<<<<<<<<<<<<br>
<br>
and a clang plugin using RecursiveASTVisitor:<br>
<br>
>>>>>>>>>>>>>>>>>><br>
class TestConsumer : public ASTConsumer, public RecursiveASTVisitor<TestConsumer> {<br>
public:<br>
  virtual void HandleTranslationUnit(ASTContext &ctx) { TraverseDecl(ctx.getTranslationUnitDecl()); }<br>
  bool shouldVisitTemplateInstantiations() const { return true; }<br>
  std::string QName(const NamedDecl *d) {<br>
    std::string s;<br>
    llvm::raw_string_ostream os(s);<br>
    d->getNameForDiagnostic(os, d->getASTContext().getPrintingPolicy(), true);<br>
    os.flush();<br>
    if (d->getDeclContext()->isFunctionOrMethod())<br>
      s.insert(0, QName(dyn_cast<NamedDecl>(d->getDeclContext())) + "::");<br>
    return s;<br>
  }<br>
  bool VisitDecl(Decl *d) {<br>
    std::cout << "\n" << d->getDeclKindName() << " decl: " << d << "\n";<br>
    const NamedDecl *nd = dyn_cast<NamedDecl>(d);<br>
    if (nd)<br>
      std::cout << "Qualified name: " << QName(nd) << "\n";<br>
    return true;<br>
  }<br>
  bool VisitDeclRefExpr(DeclRefExpr *e) {<br>
    std::cout << "\nReferenced decl: " << QName(e->getDecl()) << " - " << e->getDecl() << "\n";<br>
    return true;<br>
  }<br>
};<br>
<<<<<<<<<<<<<<<<<<<br>
<br>
Note that shouldVisitTemplateInstantiations() is set to return true. The issue is that the ParmVarDecl for D<char>::f::c is never visited, while the one for D::f::c is visited twice. As a result, VisitDeclRefExpr visits an expression whose Decl is never visited and I can't bind it :-(<br>

<br>
Since D<char>::f::c is present in ast-dump output as a distinct ParmVarDecl node, I guess it should be visited. To do it in a non-hacky and generic way, I guess I need to fix some Traverse* method in RecursiveASTVisitor.h, but I'm a bit clueless as to what goes wrong. I've checked TraverseFunctionHelper and its parameter handling, but can't find anything wrong at a glance. Halp, plz? Any tips appreciated, I'm a rookie.<br>
</blockquote><div><br></div><div>Which version of clang are you using? I thought this was fixed recently...</div><div><br></div><div>Cheers,</div><div>/Manuel</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
</blockquote></div><br></div></div>