Indexing of templated functions

I have been attempting to create a mapping of type references in a current project, and I keep running into a snag for various template functions. I’m hoping somebody here has some insight.

I am using libclang, and gathering references using the indexEntityReference callback from clang_indexTranslationUnit. I frequently hit an entity reference where the referenced entity is an entity that is produced by a template argument. Unfortunately, every reference I can find to the parent entity suggests that it is not a separate entity from the actual template function. This is making it impossible to determine where the actual reference should come from.

For example, in the code below, I will get an index entity reference where the parent entity is the same template function, for both calls to the function. I would like to know that the reference is actually at the location where the template function was called.

Is there any way to distinguish an entity reference in the template function? I assumed they would be completely different entities, but I would settle for anything. I can’t even seem to get the template parameters for that function, which would also work for my purpose.


enum TestEnum
{
	TestEnum_A,
	TestEnum_B,
	TestEnum_C,
	TestEnum_D
};

enum TestEnum2
{
	TestEnum2_A,
	TestEnum2_B,
	TestEnum2_C,
	TestEnum2_D
};

TestEnum operator&(TestEnum a, TestEnum b)
{
	return (TestEnum)((static_cast<int>(a) & static_cast<int>(b)));
}

TestEnum2 operator&(TestEnum2 a, TestEnum2 b)
{
	return (TestEnum2)((static_cast<int>(a) & static_cast<int>(b)));
}

template <typename T>
T TestTemplate(const T& Element1, const T& Element2)
{
	return Element1 & Element2;  // Entity reference will always point here.  I can't find any way to distinguish this location for TestTemplate<TestEnum> and TestTemplate<TestEnum2>
}

void Test()
{
	TestTemplate<TestEnum>(TestEnum_A, TestEnum_B);  // I actually want to know that that reference happened here.  Knowing it is TestEnum is not enough, because I want the reference to the overloaded operator&
	TestTemplate<TestEnum2>(TestEnum2_A, TestEnum2_B);
}

Thank you for any insights you can provide.