SourceLocation information from TemplateArgument

Hi,
I’m trying to write a tool that recurses into TemplateArguments and rewrites specific arguments. However, I’m having trouble getting SourceLocation information out of the TemplateArgument objects.

Once I have a TemplateArgument, if the TemplateArgument::getKind() returns TemplateArgument::Type, I can get a Type * for the argument, but from there I’m having trouble getting the SourceLocation information. It seems that generally you need a Decl object to get SourceLocations.

Any tips or strategies would be appreciated. Thanks!

Yes, if you had a Decl and now only have a Type, then you have discarded source location information.

Similarly, if you had a FunctionTemplateDecl for example and now only have a TemplateArgument, you have discarded source location information.

You probably need to use the TypeLoc information to process the template arguments if there is any complexity to them.

If you are using AST Matchers, then you will find this useful:

http://ec2-18-191-7-3.us-east-2.compute.amazonaws.com:10240/z/CoEAk-

Even if you are not using AST Matchers, it helps you to explore the AST and see what source locations can be retrieved.

Thanks,

Stephen.