The matcher is
auto param_bind = parmVarDecl(hasAncestor(functionDecl()));
auto member_param_bind = memberExpr(hasDescendant(declRefExpr(to(param_bind))));
finder->addmatcher(member_param_bind, this);
I am trying to write a matcher for matching a function’s parameter that calls its member function, and the matcher works well for the below code
class Demo {
int val = 0;
public:
int getValue() const { return val; }
};
void f(Demo& d) {
d.getValue();
}
but the matcher will crash on
#include <utility>
using namespace std;
template <typename Callable>
class Foo {
public:
Foo(Callable call) : callee(call) {}
Foo& operator=(const Foo& other) = delete;
Foo(Foo const&) = delete;
Foo(Foo&& other) : callee(std::move(other.callee)){};
private:
Callable callee;
};
template <typename Callable>
Foo<Callable> createScopeExitGuard(Callable callable) {
return Foo<Callable>(callable);
}
int main() {
int x = 17;
auto lam = [x] { ; };
createScopeExitGuard([x] { ; });
return 0;
}
it gives me
Tried to match orphan node:
ParmVarDecl 0x6103e68 <test1.cc:23:24, <invalid sloc>> col:24 used 'const (lambda at test1.cc:23:24) &'
Parent map should be complete!
UNREACHABLE executed at llvm-project/clang/lib/ASTMatchers/ASTMatchFinder.cpp:1210!
Aborted (core dumped)
If I substitute the lambda with lam
variable for createScopeExitGuard()
or remove the delete from copy constructor/assignment, the yielding will disappear.
Does anyone know how to fix this, and why the sloc on AST for the ParmVarDecl
is invalid?
The clang version is
clang version 15.0.4