[cfe-dev] Unique Identifier for template functions?

Michael Lehn michael.lehn at uni-ulm.de
Fri Aug 10 12:49:03 PDT 2012


Am 10.08.2012 um 21:20 schrieb John McCall:

> On Aug 10, 2012, at 11:13 AM, Michael Lehn wrote:
>> when parsing some C++ code with libclang, is there a way to get a unique
>> identifier for a template function?
>> 
>> For most cases "clang_getCursorUSR" is exactly doing what I need.  However,
>> when using some common trait tricks a mangled C++ name is no longer unique.
>> E.g. the code snippet below defines two variants of function "dummy" and both
>> have the same mangled name (but the trait makes sure that only one of them
>> can get instantiated).
> 
> Is this "mangling" in the sense of the USR mangling?  They certainly don't
> have the same ABI mangling.

Maybe I did not get your point.  But what are you comparing when you're
saying "They don't have the same ABI mangling"?

Only one version of function "dummy" gets instantiated for a given choice
of the template parameter.  So sure, the symbols in the object files are
finally unique, e.g.

	dummy(1);    // instantiate variant1 with T=int
	dummy(1.2);  // instantiate variant2 with T=double

Also, the USR mangling creates unique names when the template parameter gets
specified.

However, the name created by "clang_getCursorUSR" is the same for both "dummy"
variants if the template parameter is not specified.

Regards,

Michael



More information about the cfe-dev mailing list