<html>
<head>
<base href="https://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 --- - Wrong referenced cursor kind of (variable) argument to user defined index operator"
href="https://llvm.org/bugs/show_bug.cgi?id=25775">25775</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong referenced cursor kind of (variable) argument to user defined index operator
</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>nikolai.kosjar@theqtcompany.com
</td>
</tr>
<tr>
<th>CC</th>
<td>klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Reproducible with libclang 3.6.2 and current 3.8.
Source code exposing the problem:
/tmp % cat -n testSource.cpp
1 struct Foo {
2 Foo &operator[](int key);
3 };
4
5 void failsHere()
6 {
7 const int index = 3;
8 Foo foo;
9 foo[index]; // Ops, referenced cursor for "index" is of kind
CXCursor_CXXMethod.
10 }
11
12 void worksAsExpectedHere()
13 {
14 const int index = 3;
15 int foo[100];
16 foo[index]; // OK, referenced cursor for "index" is of kind
CXCursor_VarDecl.
17 }
Verify with the following test program (pass path to testSource.cpp):
1 #include <clang-c/Index.h>
2
3 #include <cassert>
4 #include <cstdlib>
5 #include <cstdio>
6 #include <vector>
7
8 int main(int argc, char *argv[])
9 {
10 if (argc != 2) {
11 fprintf(stderr, "Usage: $0 <file>\n");
12 return 0;
13 }
14 const char *filePath = argv[1];
15
16 // Construct parse arguments
17 std::vector<const char *> arguments;
18 arguments.push_back(filePath);
19
20 // Parse
21 CXIndex index = clang_createIndex(0, /*displayDiagnostics*/ 1);
22 const unsigned tuOptions = CXTranslationUnit_PrecompiledPreamble;
23 CXTranslationUnit tu = clang_parseTranslationUnit(index,
24 NULL,
25
arguments.data(),
26
arguments.size(),
27 NULL,
28 0,
29 tuOptions);
30
31 // Tokenize
32 const auto line = 9; // Check with line 16 for reference.
33 const auto columnStart = 9;
34 const auto columnEnd = 13;
35 const auto file = clang_getFile(tu, filePath);
36 const auto rangeStart = clang_getLocation(tu, file, line,
columnStart);
37 const auto rangeEnd = clang_getLocation(tu, file, line,
columnEnd);
38 const auto range = clang_getRange(rangeStart, rangeEnd);
39
40 CXToken *cxTokens = 0;
41 unsigned cxTokensCount = 0;
42 clang_tokenize(tu, range, &cxTokens, &cxTokensCount);
43
44 // Annotate tokens
45 std::vector<CXCursor> cxCursors;
46 cxCursors.resize(cxTokensCount);
47 clang_annotateTokens(tu, cxTokens, cxTokensCount,
cxCursors.data());
48
49 // Check referenced cursor argument to user defined index
operator
50 const auto indexCursor = cxCursors.front();
51 const auto referencedIndexCursor =
clang_getCursorReferenced(indexCursor);
52 const auto referencedIndexCursorKind =
clang_getCursorKind(referencedIndexCursor);
53 assert(referencedIndexCursorKind == CXCursor_VarDecl);
54
55 return 0;
56 }</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>