<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Behavior change of clang_getCanonicalType when cursor is on C++11 auto-declaration"
href="http://llvm.org/bugs/show_bug.cgi?id=18669">18669</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Behavior change of clang_getCanonicalType when cursor is on C++11 auto-declaration
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>libclang
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>kfunk@kde.org
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=11977" name="attach_11977" title="Standalone parser based on libclang, dumping AST">attachment 11977</a> <a href="attachment.cgi?id=11977&action=edit" title="Standalone parser based on libclang, dumping AST">[details]</a></span>
Standalone parser based on libclang, dumping AST
We're having some problems getting the deduced type for C++11 auto-declarations
out of libclang using clang_getCanonicalType.
Example:
echo "auto i = 1;" > test.cpp
Using just clang to print the type gives us:
$ clang -cc1 -std=c++11 -ast-dump test.cpp
(...)
`-VarDecl 0x1c2e5b0 <test.cpp:1:1, col:10> i 'int':'int'
`-IntegerLiteral 0x1c2e608 <col:10> 'int' 5
=> 'auto' is deduced to 'int' => Okay
Now, with just depending on libclang, this gets confusing.
In LLVM-3.2 apparently clang_getCanonicalType on the cursor pointing to 'i'
actually returned CXType_Int, whereas in any future version this returns
CXType_Unexposed => No way to get the deduced type any more.
I've attached some sample code that you can try out in order to reproduce the
bug.
Compile & run with:
$ clang parser.c -I/usr/include/clang-c -l clang -o parser
$ ./parser -std=c++11 test.cpp
For LLVM-3.2, I get:
test.cpp:1:6 (5, 0-10) kind: VarDecl type: int display name: i usr: (...)
test.cpp:1:10 (9, 9-10) kind: IntegerLiteral type: int
=> Type is resolved as 'int' => Okay
For any other version >LLVM-3.3:
test.cpp:1:6 (5, 0-10) kind: VarDecl type: auto display name: i usr: (...)
test.cpp:1:10 (9, 9-10) kind: IntegerLiteral type: int
=> Type is resolved as 'auto'
Maybe this behavior changed due to the following commit:
<a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130211/074246.html">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20130211/074246.html</a>
Can someone clarify if the change was intended, or if this is a bug and should
be fixed?</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>