Matching function calls in template class

Hello,

Consider the following snippet :

struct R {
   void unlock() {}
   void lock() {}
};
template <class T> struct S : R {
   void A(){};
   void g() {
     lock();
     unlock();
   }
   void B() { A(); }
};

struct T {
   void lock() {}
   void h() { lock(); }
};

To my big surprise, the following matcher matches only in h

cxxMemberCallExpr(callee(functionDecl(hasName("lock"))))

A closer look at S AST shows the following in S

  >-CXXMethodDecl 0x2dbeb98 <line:29:1, col:26> col:6 g 'void (void)'
  > └-CompoundStmt 0x2dbee40 <col:9, col:26>
  > >-CallExpr 0x2dbeda0 <col:10, col:15> '<dependent type>'
  > > └-MemberExpr 0x2dbed68 <col:10> '<bound member function type>'

->lock 0x2dbe540

  > > └-CXXThisExpr 0x2dbed50 <col:10> 's<T> *' this

memberExpr(member(functionDecl(hasName("lock")))) matches the member expressions themselves (in h and g), but

callExpr(memberExpr(member(functionDecl(hasName("lock"))))) matches nothing nor does cxxMemberCallExpr(memberExpr(member(functionDecl(hasName("lock")))))

Any idea how to match function calls in template classes ?

Thanks

David.

Hello,

Consider the following snippet :

struct R {
void unlock() {}
void lock() {}
};
template struct S : R {
void A(){};
void g() {
lock();
unlock();
}
void B() { A(); }
};

struct T {
void lock() {}
void h() { lock(); }
};

To my big surprise, the following matcher matches only in h

cxxMemberCallExpr(callee(functionDecl(hasName(“lock”))))

A closer look at S AST shows the following in S

-CXXMethodDecl 0x2dbeb98 <line:29:1, col:26> col:6 g ‘void (void)’
└-CompoundStmt 0x2dbee40 <col:9, col:26>

-CallExpr 0x2dbeda0 <col:10, col:15> ‘’
└-MemberExpr 0x2dbed68 col:10 ‘’
->lock 0x2dbe540
└-CXXThisExpr 0x2dbed50 col:10 ‘s *’ this

memberExpr(member(functionDecl(hasName(“lock”)))) matches the member
expressions themselves (in h and g), but

callExpr(memberExpr(member(functionDecl(hasName(“lock”))))) matches
nothing

callExpr(has(memberExpr())) matches

callExpr(memberExpr()) would mean that the call expr is-a member expr, which is not true.

Generally, inner matchers will match on the same node.
decl(decl(decl().bind(“i”))).bind(“j”) will bind the same node to i and j.