[cfe-dev] cursor equality with templates

Robert Anderson rwa at alumni.princeton.edu
Wed Jan 4 16:08:58 PST 2012


Say I have a class, with a member declaration:

class A { void foo() {} };

and I get a cursor to it.  I then find a reference to it, say:

int main() { A a; a.foo(); }

The return value of clang_getCursorReferenced() is then "equal" to the
declaration cursor.  By looking at source, it appears that "equal" here
means that they're of the same kind, and the fields data[3] are all equal.

Things change when A is a class template, however:

template <class T>
class A { void foo() {} };

Say I have a couple references to this method, now, say:

int main() { A<int> a; a.foo(); A<double> b; b.foo(); }

Now the return values of clang_getCursorReferenced() are no longer "equal"
to the declaration cursor.  They appears to be different via the value of
CXCursor::data[0], which seems to change for each instantiation of the
template.

Is there a way to connect the reference cursors back to the member
declaration cursor?  Moreover, is there a way to do it through the python
bindings?

My goal is to find all uses of A<T>::foo(), regardless of T.

Thanks for any help.

Bob Anderson
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120104/37d2548a/attachment.html>


More information about the cfe-dev mailing list