Matcher for templated variable

I’m looking to create AST matchers for variables that are templated. For example, in the code:

template class Class // template <(class or typename or int/float/etc) T>

void Func(T* Param) // 1) match Param
Param = nullptr; // 2) match Param

T* Var = nullptr; // 3) match Var

int main()
Class MyClass;
float FloatVal;
MyClass.Var = &FloatVal; // 4) match Var

Ideally, I’d like one matcher to find each of the 4 matches, but I suspect I need individual matchers for each of them. For the first match above I have varDecl(hasType(templateTypeParmType())), but I haven’t had luck with clang-query in finding the other 3. Any help would be much appreciated!


Hey Robert,

I can highely recommend, it has support for clang-query as additional tool when you select clang as the compiler as well as AST output.


There you get all the possible matchers you can combine. You can check out clang-tidy code for checks do something similar and get inspiration on how to combine matchers, too!