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

Daniel Jasper djasper at google.com
Thu Apr 19 05:40:56 PDT 2012


Please find a new version of the patch attached. This also fixes the same
problem in nested function templates and includes corresponding tests. I am
still not sure whether this is just a workaround for an underlying problem:
Shouldn't the Decl fulfill isThisDeclarationADefinition()?

Kind regards,
Daniel

On Thu, Apr 12, 2012 at 10:32 PM, Daniel Jasper <djasper at google.com> wrote:

> 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/20120419/d3142da8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mypatchfile.patch
Type: application/octet-stream
Size: 2412 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120419/d3142da8/attachment.obj>


More information about the cfe-commits mailing list