[cfe-users] Matcher for templated variable

Robert Ankeney via cfe-users cfe-users at lists.llvm.org
Sun Aug 8 15:37:30 PDT 2021


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

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

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

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

int main()
{
   Class<float> 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!

Thanks,
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20210808/e5fa72e0/attachment.html>


More information about the cfe-users mailing list