[cfe-users] Template parameter matcher?

Richard Smith via cfe-users cfe-users at lists.llvm.org
Sun Jun 28 10:17:38 PDT 2020


On Fri, 26 Jun 2020 at 11:30, Robert Ankeney <rrankene at gmail.com> wrote:

> Thanks Richard! This works great! One more question - assuming I have a
> templated class CClass, how would I match tVal for:
> void myFunc(CClass<T>* 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:

varDecl(hasType(pointerType(pointee(templateSpecializationType(hasAnyTemplateArgument(refersToType(templateTypeParmType())))))))

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


> Oh, and thanks also for the godbolt link. I didn't realize you could do
> match testing there!
>
> Robert
>
>
> On Wed, Jun 24, 2020 at 10:38 AM Richard Smith <richard at metafoo.co.uk>
> wrote:
>
>> The declarations of tVal and tParam can be matched by
>>   varDecl(hasType(templateTypeParmType()))
>> The use of tVal can be matched by
>>   declRefExpr(hasDeclaration(varDecl(hasType(templateTypeParmType()))))
>>
>> https://godbolt.org/z/B3SuC3
>>
>>
>> On Tue, 23 Jun 2020 at 15:47, Robert Ankeney via cfe-users <
>> cfe-users at lists.llvm.org> wrote:
>>
>>> I'm looking for a matcher for variables whose type is a template
>>> parameter. For example:
>>>
>>> template<typename T>
>>> 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,
>>> Robert
>>>
>>> _______________________________________________
>>> cfe-users mailing list
>>> cfe-users at lists.llvm.org
>>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20200628/0ab3dba5/attachment.html>


More information about the cfe-users mailing list