Matcher with expressions


Now that I have updated my clang version, I have been testing the matcher you suggested me to find invocations to a constructor method of a parent class:

constructExpr(hasDeclaration(methodDecl(ofClass(recordDecl().bind(“constructedType”)))), hasAncestor(methodDecl(ofClass(recordDecl(isDerivedFrom(equalsBoundNode(“constructedType”))))))).bind(“constructExpr”)

However, it seems that the “hasAncestor” is not functioning as expected. If I test only:


the matcher finds every CXXConstructorExpr in the code, so the problem is in the hasAncestor(). I have tested as well with hasParent(), but it didn’t work neither. By the way, what’s the difference between hasAncestor and hasParent?

In addition, what I’m looking for exactly are these cases marked in bold, but not the one marked in red:

class A1{
A1(int a) {…}


class A2{
A2() {…}
A2(int a) {…}
A2(int a, int b) {…}


class B: public A1, public A2{
B (): A1(4) { A2(3,3); A2(3); }
void b() { A1 a1(3); }

I’ve been analyzing these cases and I can’t understand why A2(3,3) is a CXXBindTemporaryBindExpr while A2(3); is a CXXFunctionalCastExpr with a CXXConstructExprinside. All this is pretty confusing…and I would like to be sure that I’m binding all the possible cases…

Thanks in advance,


El día 27 sep 2013 12:13, Manuel Klimek escribió: