[PATCH] Expr::IgnoreImpCasts should also ignore CXXConstructorCalls for implicit copy constructor calls

Jochen Eisinger eisinger at google.com
Thu May 2 08:08:51 PDT 2013


  So here's a bit more background what I try to achieve:

  I want to match the following return statement



    `A<V> func() {
      X x;
      B<W> b;
      return x.meth(b);
    }`



  Here are the classes:



    `template<class T> struct A {
      template<class S> A(A<S>);
      A();
    };
    template<class T> struct B : public A {
    };

    struct V {};
    struct W : public V {};

    struct X {
      template<class T> B<T> meth(A<T>);
    };`



  That's my matcher:



    `returnStmt(
      ignoringParenImpCasts(
        has(memberCallExpr(
          on(hasType(recordDecl(hasName("X")))),
          callee(methodDecl(hasName("meth")))))))`



  however, ignoringParenImpCasts doesn't work in above example, as there are three CXXConstructCalls in between:



    `ReturnStmt
    `-CXXConstructExpr 'A<V>':'class A<class V>' 'void (const class A<class V> &) throw()' elidable
      `-MaterializeTemporaryExpr 'const class A<class V>' lvalue
        `-ImplicitCastExpr 'const class A<class V>' <NoOp>
          `-ImplicitCastExpr 'A<V>':'class A<class V>' <ConstructorConversion>
            `-CXXConstructExpr 'A<V>':'class A<class V>' 'void (A<class W>)'
              `-CXXConstructExpr 'A<class W>':'class A<class W>' 'void (const class A<class W> &) throw()'
                `-MaterializeTemporaryExpr 'const class A<class W>' lvalue
                  `-ImplicitCastExpr 'const class A<class W>' <NoOp>
                    `-ImplicitCastExpr 'class A<class W>' <DerivedToBase (A)>
                      `-CXXMemberCallExpr 'B<class W>':'class B<class W>'
                        |-MemberExpr '<bound member function type>' .meth
                        | `-DeclRefExpr 'X':'class X' lvalue Var 'x' 'X':'class X'
                        `-...`



  Since the number of CXXConstructExpr depends on what types exactly are used, matching all possible combinations is a bit tedious.

  Anyway, IgnoreImplicit() doesn't seem to achieve this.

http://llvm-reviews.chandlerc.com/D720



More information about the cfe-commits mailing list