libclang: clang_getCursorDefinition doesn't work correctly for template class methods not defined within the class

Hi:

clang_getCursorDefinition()
works fine for non-template
classes, but not for methods of
template classes where the
definition is not in the class, e.g.,

01 template <typename T>
02 class X
03 {
04 public:
05 void f (void);
06 };
07
08 template <typename T>
09 void X<T>::f (void) {}
10
11 void g (void)
12 {
13 X x;
14 x.f();
15 }

If I call clang_getCursorDefinition() on
the cursor for X::f on line 14, it
will give me a cursor for the
declaration on line 5 not the
definition on line 9.

Is this expected or is it a bug?

I have svn revision 161180.

thanks...
don

Hi:

clang_getCursorDefinition()
works fine for non-template
classes, but not for methods of
template classes where the
definition is not in the class, e.g.,

01 template <typename T>
02 class X
03 {
04 public:
05 void f (void);
06 };
07
08 template <typename T>
09 void X<T>::f (void) {}
10
11 void g (void)
12 {
13 X x;
14 x.f();
15 }

If I call clang_getCursorDefinition() on
the cursor for X::f on line 14, it
will give me a cursor for the
declaration on line 5 not the
definition on line 9.

Is this expected or is it a bug?

I found a workaround that might help locate the bug:

replace the call to
  clang_getCursorDefintion(c)
with
  clang_getCursorDefinition(clang_getCursor(tu,clang_getCursorLocation(clang_getCursorDefinition(c))));

This seems to work in all cases.

hth...
don