Template parameter matcher?

I’m looking for a matcher for variables whose type is a template parameter. For example:

T tVal; // Match tVal
int func(T tParam); // Match tParam
int i = func(tVal); // Match tVal

Our coding standards require the variable to have a ‘t’ at the start of the variable name.
Looking at the matcher reference, I didn’t see anything obvious. Can anyone point me the right direction?

Many thanks,

The declarations of tVal and tParam can be matched by
The use of tVal can be matched by


Thanks Richard! This works great! One more question - assuming I have a templated class CClass, how would I match tVal for:
void myFunc(CClass* tVal) ?

It depends exactly what you’re looking for. If you don’t care what CClass is, and want to match any pointer to X<…, T, …>, then something like:


might be what you’re looking for. If you want to match a T anywhere in the variable’s type, then maybe something like:

m varDecl(hasType(qualType(hasDescendant(qualType(templateTypeParmType())))))

is what you want. https://godbolt.org/z/QhGN5d