Get the specialized class name and function name

Hey guys,

I am new to clang and I am trying to get the specialized name of template classes and functions. For example, the std::map container is an STL class with template parameters. map<string, int> should be expanded as something similar to std::map<std::__cxx11::basic_string<char, std::char_traits, std::allocator >, int>. I have written a simple clang tool to get the function name and the class name of functions, here is a piece of code:

map<string, set> func_set;

DeclarationMatcher methodMatcher = cxxMethodDecl().bind(“methods”);

class MethodPrinter : public MatchFinder::MatchCallback {
public :
virtual void run(const MatchFinder::MatchResult &Result) {
if (const CXXMethodDecl *md = Result.Nodes.getNodeAsclang::CXXMethodDecl(“methods”)) {
string f_name = md->getNameAsString();
string c_name = md->getParent()->getNameAsString();

if (auto tsd = dyn_cast(md->getParent()))
c_name = tsd->getNameAsString();


This piece of code is getting me started, but not quite there. The getNameAsString() method just gives a very simple name, without the template parameters specialized. I am wondering if there is a way to do that.

Any help is appreciated!


I don’t know the specific way off-hand, but my usual approach to finding such APIs would be to run clang on a source file that produces a warning/error/diagnostic with the name you want - then running that under a debugger to see how it is getting that name