[cfe-dev] API for auto type deduction in libclang

Jacob Carlborg doob at me.com
Wed Jan 29 03:57:51 PST 2014


On 2014-01-29 11:29, Milian Wolff wrote:

> No, it does not work. Have you tried the example that Kevin linked to?
>
> wget -O clang-standalone-parser.c "http://quickgit.kde.org/?p=kdev-clang.git&a=blob&h=dbad9e8942cc5e20fd005677fc32a5a0b54977ae&f=tests%2Fclang-standalone-parser.c&o=plain"
> clang clang-standalone-parser.c -I/usr/include/clang-c -l clang -o clang-
> standalone-parser
>
> echo "auto i = 1;" > test.cpp
> ./clang-standalone-parser --std=c++11 test.cpp
>
> Gives me:
>
> test.cpp:1:6 (5, 0-10) kind: VarDecl type: auto display name: i usr: c:@i
> definition
>    test.cpp:1:10 (9, 9-10) kind: IntegerLiteral type: int

I get this using libclang 3.3 on OS X:

test.cpp:1:6 (5, 0-10) kind: VarDecl type: int display name: i usr: c:@i 
definition
   test.cpp:1:10 (9, 9-10) kind: IntegerLiteral type: int

> If I add something like this to the standalone example:
>
> printString("type.kind", clang_getTypeKindSpelling(type.kind));
>
> I see: "type.kind: Unexposed" - your assertion fails.

Of course I forgot to use "clang_getCanonicalType". Here's the same 
example updated to use "clang_getCanonicalType" and a switch statement 
on "type.kind" that I tried to explain:

http://pastebin.com/xMPn7kS6

-- 
/Jacob Carlborg




More information about the cfe-dev mailing list