[cfe-dev] Unique Identifier for template functions?

John McCall rjmccall at apple.com
Fri Aug 10 14:21:35 PDT 2012


On Aug 10, 2012, at 12:49 PM, Michael Lehn wrote:
> 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"?

The ABI mangling uses the dependent signature of a function template, not
the substituted type.  In your case, yes, this is technically unnecessary because
the templates happen to perfectly divide the world, so the template arguments
unambiguously dictate the template used.  In general, that is not the case, and
you can easily have two templates with the same name that both pass SFINAE
for a particular set of template arguments and instantiate to having the same
type.  For a particular call, they could be disambiguated by using explicit template
arguments, by function template partial ordering, or even by only one of them
being declared in any given translation unit.

What is likely going on for you is just a bug.  The USR mangling — which is
totally different from the ABI mangling — should be including the return type
of a function template.

John.



More information about the cfe-dev mailing list