[cfe-dev] libclang: clang_getCursorDefinition doesn't work correctly for template class methods not defined within the class

don hinton hintonda at gmail.com
Sun Aug 12 10:48:00 PDT 2012



On Aug 11, 2012, at 17:35, don hinton <hintonda at gmail.com> wrote:

> 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

> I have svn revision 161180.
> 
> thanks...
> don
> 




More information about the cfe-dev mailing list