Issue with cindex parsing on python: Can't parse function that returns a std::vector<std::vector<int>>

Hello. I’m new with the clang python bindings (https://github.com/llvm-mirror/clang/tree/master/bindings/python), and I’m mostly basing my tests on the test examples on https://github.com/llvm-mirror/clang/tree/master/bindings/python/tests/cindex . Feel free to suggest any better documentation.

For the following example, I’d expect the two results to be similar, but the first one isn’t getting any data about the function example. Does anyone know why?

https://pastebin.com/TF3RLibt

Results on my machine:

t.cpp (TypeKind.INVALID)

Are you parsing as C++98 (the default, I think? That code is invalid C++98/C++03, I think (because the “>>” is interpreted as a right shift operator, not the end of two template argument lists). In C++11 and above, it should do the right thing.

Hi, David. Thanks for the response!

As far as I understand, since I’m using -std=c++11 option, it SHOULD be right. Anyway, I tried your suggestion, and it did not work (Same problem) :frowning: I’ll leave the link here just for reference: https://pastebin.com/jvQev5eb

Good news is… After trying a bit more, I managed to make the code work. Turns out it as a missing #include <vector>. I don’t know why the first example works, (Now I believe none of them should work). Here’s the working example: https://pastebin.com/Setuw9cF

Does anyone knows why the first example was working, even with the missing include?

Hi, David. Thanks for the response!

As far as I understand, since I’m using -std=c++11 option, it SHOULD be right. Anyway, I tried your suggestion, and it did not work (Same problem) :frowning: I’ll leave the link here just for reference: https://pastebin.com/jvQev5eb

Ah, right - sorry, didn’t spot that you were already specifying -std=c++11

Good news is… After trying a bit more, I managed to make the code work. Turns out it as a missing #include <vector>. I don’t know why the first example works, (Now I believe none of them should work). Here’s the working example: https://pastebin.com/Setuw9cF

Does anyone knows why the first example was working, even with the missing include?

Yep - C++ is a context sensitive language, without seeing the declaration of std::vector as a template, the compiler has to parse “std::vector” as “(std::vector < T) >” - which fails once it’s apparent that T is a type, not a variable that can be less-than (<) compared, etc… - so things go off the rails pretty quickly.

  • Dave