[cfe-commits] Fix for RecursiveASTMatcher not traversing nested template instatiations

Daniel Jasper djasper at google.com
Thu Apr 12 13:32:47 PDT 2012


Hi all,

we have noticed that the RecursiveASTMatcher does not seem to traverse
nested template instantiations as in this code segment:

template <typename Rhs> struct Outer {
  template <typename Lhs> struct Inner {
    void Compare() {
      Lhs y;
      y.x();
    }
  };
};
struct A { void x(); };
int main() {
  (new Outer<A>::Inner<A>())->Compare();
}

Here, the templates Outer and Inner are instantiated with type A, but the
Inner-instantiation is not traversed even if the RecursiveASTMatcher's
subclass implements shouldVisitTemplateInstantiations() to return true. The
reason is, that isThisDeclarationADefinition() does (erroneously?) return
false for this instantiation. The attached patch works around this. As far
as I can tell, isThisDeclarationADefinition() is checked in order to
prevent forward-declared templates to be traversed multiple times. However,
if this template is instantiated from a member template, this cannot happen.

Kind regards,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120412/8eff7c7e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mypatchfile.patch
Type: application/octet-stream
Size: 654 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120412/8eff7c7e/attachment.obj>


More information about the cfe-commits mailing list