[cfe-dev] Issues with clang_Cursor_getSpellingNameRange not reporting the correct range

Kevin Funk kfunk at kde.org
Mon Aug 4 08:49:05 PDT 2014


Hey,

Context: We're using libclang as our C++ parser backend in KDevelop.

We're having some difficulties in finding the correct range for some 
identifiers using libclang. Example:

% cat test.cpp                                                                                                        
struct Foo
{
    void operator++() {}
};

% c-index-test -cursor-at=test.cpp:3:10 test.cpp                                                                
3:10 CXXMethod=operator++:3:10 (Definition) Extent=[3:5 - 3:25] 
Spelling=operator++ ([3:10 - 3:18])
Completion string: {ResultType void}{TypedText operator++}{LeftParen (}
{RightParen )}

Here, the range is obviously wrong: [3:10 - 3:18] only points to 'operator', 
not 'operator++'. This is the fault of clang_Cursor_getSpellingNameRange.
This happens for a C++ destructor declaration (only '~' is in the range), and 
all operator overloads (only 'operator' in the range).

I guess that this is a bug, and not intended, and that 
clang_Cursor_getSpellingNameRange just needs special-casing for C.kind == 
CXCursor_CXXMethod and friends. Am I right in that assumption and a patch 
would be accepted?

Cheers

-- 
Kevin Funk | kfunk at kde.org | http://kfunk.org



More information about the cfe-dev mailing list