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

Kevin Funk krf at gmx.de
Wed Jan 29 04:47:41 PST 2014


Am Mittwoch, 29. Januar 2014, 12:57:51 schrieb Jacob Carlborg:
> 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=dbad9e8942cc5e20fd005
> > 677fc32a5a0b54977ae&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

I just tested this against multiple versions on my Linux (64bit) system:

For both llvm-3.3, llvm-3.4 (Ubuntu packages) and llvm-trunk (self-compiled) I 
get an endless recursion in getTypeSpelling, because it always returns 
CXType_Unexposed. => segmentation fault (core dumped)

Surprisingly, for llvm-3.2 (Ubuntu package) your code works, and I can 
reproduce the output you get! Interesting.

So now I'm really confused: You say your example works for you on llvm-3.3, 
but I cannot confirm that. What's going on here? :/
Should I file a bug report about that behavioral change?

Greets

-- 
Kevin Funk



More information about the cfe-dev mailing list