[cfe-dev] clang-c: missing TypeRef cursor for pointer-to-member uses

Milian Wolff mail at milianw.de
Tue May 19 15:31:49 PDT 2015


Hey all,

while working on KDevelop's clang-c based language plugin, I've hit two issues 
with the following code snippet:
~~~~~~~~~~~~
struct Bar { int member; };
void ptrToMember(int Bar::* ptr);
~~~~~~~~~~~~

With "clang -Xclang -ast-dump -fsyntax-only test.cpp" I get:
~~~~~~~~~~~
TranslationUnitDecl 0x2b83d20 <<invalid sloc>> <invalid sloc>
|-TypedefDecl 0x2b84260 <<invalid sloc>> <invalid sloc> implicit __int128_t 
'__int128'
|-TypedefDecl 0x2b842c0 <<invalid sloc>> <invalid sloc> implicit __uint128_t 
'unsigned __int128'
|-TypedefDecl 0x2b84680 <<invalid sloc>> <invalid sloc> implicit 
__builtin_va_list '__va_list_tag [1]'
|-CXXRecordDecl 0x2b846d0 <test.cpp:1:1, col:26> col:8 struct Bar definition
| |-CXXRecordDecl 0x2b847e0 <col:1, col:8> col:8 implicit struct Bar
| `-FieldDecl 0x2b84880 <col:14, col:18> col:18 member 'int'
`-FunctionDecl 0x2bca8c0 <line:2:1, col:33> col:6 ptrToMember 'void (int 
struct Bar::*)'
  `-ParmVarDecl 0x2b84960 <col:18, col:29> col:29 ptr 'int struct Bar::*'
~~~~~~~~~~~

and with our clang-c debug visitor:
~~~~~~~~~~~
StructDecl (2) | type: "Bar" (105) | display: "Bar" | loc: test.cpp@[(1,1),
(1,27)] | isDecl
  FieldDecl (6) | type: "int" (17) | display: "member" | loc: 
test.cpp@[(1,14),(1,24)] | isDecl
FunctionDecl (8) | type: "void (int Bar::*)" (111) | display: "ptrToMember(int 
Bar::*)" | loc: test.cpp@[(2,1),(2,34)] | isDecl
  ParmDecl (10) | type: "int Bar::*" (117) | display: "ptr" | loc: 
test.cpp@[(2,18),(2,33)] | isDecl
~~~~~~~~~~~

Note that in both cases, there is no TypeRef cursor for the type of ptr, i.e. 
for the Bar in "int Bar::*". Any suggestions on how to fix this? Or is this 
deliberate? How can I get notified about the use of Bar here?

I.e. when you change the code to
~~~~~~~~~~~~
struct Bar { int member; };
void ptrToMember(Bar* ptr);
~~~~~~~~~~~~

you'll get something like

~~~~~~~~~~~~
StructDecl (2) | type: "Bar" (105) | display: "Bar" | loc: test.cpp@[(1,1),
(1,27)] | isDecl
  FieldDecl (6) | type: "int" (17) | display: "member" | loc: 
test.cpp@[(1,14),(1,24)] | isDecl
FunctionDecl (8) | type: "void (Bar *)" (111) | display: "ptrToMember(Bar *)" 
| loc: test.cpp@[(2,1),(2,27)] | isDecl
  ParmDecl (10) | type: "Bar *" (101) | display: "ptr" | loc: 
test.cpp@[(2,18),(2,26)] | isDecl
    TypeRef (43) | type: "Bar" (105) | display: "struct Bar" | loc: 
test.cpp@[(2,18),(2,21)] | isUse
~~~~~~~~~~~~

Here, everything is as expected.

Thanks, any input or ideas for workarounds are appreciated.

-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150520/10dc5d31/attachment.sig>


More information about the cfe-dev mailing list