How to determine if variable is templated?

Suppose I have some code like:

Type tVar;

How can I determine that tVar is templated from the VarDecl or a MemberExpr? I don’t see any obvious function in QualType or Type.


Guessing these sort of functions would be relevant:

I don’t understand - you’ll need to be more specific. (anything that’s “this doesn’t /always/ happen” sounds like there’s a /lot/ going on that’s not specified in your question… compilers in general and clang in particular are /very/ deterministic, so they do do the same thing every time - so if there’s some variation it’s likely because you’re looking at different things)

If you’re looking at a particular instantiation of the variable template tVar, well, once you ask for the type of that particular instantiation you’ll be looking at a concrete type and probably too late to find out anything about the template-y-ness.

But if you are actually looking at the DeclRef for the variable template instantiation, then you can get the VarDecl from that DeclRef and then you can query the VarDecl to see if it’s a template as I mentioned in the link previously - “getTemplateSpecializationKind” on the VarDecl should tell you if it’s a template at all.

At least I think that’s how you’d go about it…

  • Dave