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

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Sun Oct 28 14:03:19 PDT 2018


On Sun, Oct 28, 2018 at 1:55 PM Tarcísio Fischer <
tarcisio.fischer.cco at gmail.com> wrote:

> 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)
> :( 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<T>" 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


>
> Em sáb, 27 de out de 2018 às 14:31, David Blaikie <dblaikie at gmail.com>
> escreveu:
>
>> 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.
>>
>> On Fri, Oct 26, 2018 at 2:17 PM Tarcísio Fischer via cfe-dev <
>> cfe-dev at lists.llvm.org> wrote:
>>
>>> 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)
>>>
>>> ****************************************************************************************************
>>> t.cpp (TypeKind.INVALID)
>>>  example() (TypeKind.FUNCTIONPROTO)
>>>    (TypeKind.INVALID)
>>>     (TypeKind.INVALID)
>>> _______________________________________________
>>> cfe-dev mailing list
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20181028/a0a323e6/attachment.html>


More information about the cfe-dev mailing list