[cfe-dev] problem with template class inheritance and cursor api

Anders Bakken agbakken at gmail.com
Fri Jan 18 00:38:48 PST 2013


Hi

I'm writing a clang-based c++/c indexer
(https://github.com/Andersbakken/rtags/) and I am having a problem
with the following construct:

// -----------------
template <typename T>
class A
{
public:
    int size() const { return 1; }
};

template <typename T>
class B : public A<T>
{
public:
    bool isEmpty() const { return A<T>::size(); }
};

// -----------------

There seems to be way to get from this cursor(s) for the call to
A<T>::size() to the actual function (A<T>::size).

I provide functionality to jump to target cursor and this one has been
me causing me some problems.

With the attached example I get the following output:

main.cpp:2:7 (28, 0-76) kind: ClassTemplate display name: A<T> usr:
c:@CT>1#T at A definition
  main.cpp:1:20 (19, 10-20) kind: TemplateTypeParameter display name:
T usr: c:main.cpp at 10 definition
  main.cpp:4:1 (32, 32-39) kind: CXXAccessSpecifier usr: c: definition
  main.cpp:5:9 (48, 44-74) kind: CXXMethod display name: size() usr:
c:@CT>1#T at A@F at size#1 definition
    main.cpp:5:22 (61, 61-74) kind: CompoundStmt
      main.cpp:5:24 (63, 63-71) kind: ReturnStmt
        main.cpp:5:31 (70, 70-71) kind: IntegerLiteral
main.cpp:9:7 (107, 79-184) kind: ClassTemplate display name: B<T> usr:
c:@CT>1#T at B definition
  main.cpp:8:20 (98, 89-99) kind: TemplateTypeParameter display name:
T usr: c:main.cpp at 89 definition
  main.cpp:9:18 (118, 111-122) kind: C++ base class specifier display
name: A<T>
  -> main.cpp:2:7 (28, 0-76) kind: ClassTemplate display name: A<T>
usr: c:@CT>1#T at A definition
    main.cpp:9:18 (118, 118-119) kind: TemplateRef display name: A
    -> main.cpp:2:7 (28, 0-76) kind: ClassTemplate display name: A<T>
usr: c:@CT>1#T at A definition
    main.cpp:9:20 (120, 120-121) kind: TypeRef display name: T
    -> main.cpp:8:20 (98, 89-99) kind: TemplateTypeParameter display
name: T usr: c:main.cpp at 89 definition
  main.cpp:11:1 (125, 125-132) kind: CXXAccessSpecifier usr: c: definition
  main.cpp:12:10 (142, 137-182) kind: CXXMethod display name:
isEmpty() usr: c:@CT>1#T at B@F at isEmpty#1 definition
    main.cpp:12:26 (158, 158-182) kind: CompoundStmt
      main.cpp:12:28 (160, 160-179) kind: ReturnStmt
        main.cpp:12:35 (167, 167-179) kind: CallExpr
          main.cpp:12:35 (167, 167-177) kind: MemberRefExpr
            main.cpp:12:35 (167, 167-168) kind: TemplateRef display name: A
            -> main.cpp:2:7 (28, 0-76) kind: ClassTemplate display
name: A<T> usr: c:@CT>1#T at A definition
            main.cpp:12:37 (169, 169-170) kind: TypeRef display name: T
            -> main.cpp:8:20 (98, 89-99) kind: TemplateTypeParameter
display name: T usr: c:main.cpp at 89 definition

I've tried out all the APIs I could find to look up the connection but
I have been unsuccessful and had to resort to hacks to make it work.
Is there way to do this? Is it a bug?

Help would be greatly appreciated.

I really am very grateful for your excellent work on this project that
allows me to bring my emacs c++ experience into the 21st century :-)

regards

Anders
-------------- next part --------------
A non-text attachment was scrubbed...
Name: clangtest.c
Type: text/x-csrc
Size: 3512 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130118/94e394ce/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.cpp
Type: text/x-c++src
Size: 186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130118/94e394ce/attachment.cpp>


More information about the cfe-dev mailing list