[cfe-dev] Unique Identifier for template functions?

Douglas Gregor dgregor at apple.com
Fri Aug 10 14:11:37 PDT 2012


On Aug 10, 2012, at 11:13 AM, Michael Lehn <michael.lehn at uni-ulm.de> wrote:

> Hi,
> 
> 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).
> 
> Any idea how I could get a unique identifies for a cursor when traversing
> such code?

This is a bug in libclang; it should generate different USRs for the two 'dummy' functions. Please file a bug at http://llvm.org/bugs/ !

	- Doug
> 
> Thanks,
> 
> Michael
> 
> 
> 
> //------snip-----------------------------------------
> 
> // some traits
> template <bool b, typename T>
> struct RestrictTo
> {};
> 
> template <typename T>
> struct RestrictTo<true, T>
> {
>    typedef T Type;
> };
> 
> template <typename T1, typename T2>
> struct IsSame
> {
>    static const bool value = false;
> };
> 
> template <typename T>
> struct IsSame<T,T>
> {
>    static const bool value = true;
> };
> 
> // variant1
> template <typename T>
> typename RestrictTo<IsSame<T,int>::value, void>::Type
> dummy(const T &)
> {
> // ...
> }
> 
> // variant2
> template <typename T>
> typename RestrictTo<!IsSame<T,int>::value, void>::Type
> dummy(const T &)
> {
> // ...
> }
> 
> //------snap-----------------------------------------
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev




More information about the cfe-dev mailing list