[cfe-dev] Matching function calls in template class

Manuel Klimek via cfe-dev cfe-dev at lists.llvm.org
Thu Nov 24 01:08:30 PST 2016


On Wed, Nov 23, 2016 at 4:02 PM David Come via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> 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


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.


> nor does
> cxxMemberCallExpr(memberExpr(member(functionDecl(hasName("lock")))))
>
>
> Any idea how to match function calls in template classes ?

Thanks
>
>
> David.
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20161124/c88260a6/attachment.html>


More information about the cfe-dev mailing list