[cfe-dev] Matching function calls in template class
David Come via cfe-dev
cfe-dev at lists.llvm.org
Wed Nov 23 08:02:14 PST 2016
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.
More information about the cfe-dev
mailing list