[llvm-bugs] [Bug 25775] New: Wrong referenced cursor kind of (variable) argument to user defined index operator

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Dec 8 06:55:51 PST 2015


https://llvm.org/bugs/show_bug.cgi?id=25775

            Bug ID: 25775
           Summary: Wrong referenced cursor kind of (variable) argument to
                    user defined index operator
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: libclang
          Assignee: unassignedclangbugs at nondot.org
          Reporter: nikolai.kosjar at theqtcompany.com
                CC: klimek at google.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

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    }

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151208/24f94b1b/attachment.html>


More information about the llvm-bugs mailing list