-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Closed
Copy link
Labels
clang:as-a-librarylibclang and C++ APIlibclang and C++ API
Description
In #138103, we changed the behavior of the Cursor
class in order to prevent usage of null Cursors by throwing an error when any of its member methods is accessed. At the same time, we adjusted all known places that return cursors to convert null Cursors to None
, so that users would not encounter null Cursors. See discussion on the PR here: #138103 (comment)
It seems that we have overlooked one function that returns cursors: the TokenGroup.get_tokens
function sometimes returns null Cursors.
Reproducer:
test.cpp
struct A;
int main() {
return 0;
}
main.py
import clang.cindex as clci
clci.Config.set_library_path("/data/shared/programming/repos/llvm-project/build/lib")
tu = clci.TranslationUnit.from_source("test.cpp")
cs = list(tu.get_tokens(extent=tu.cursor.extent))
for c in cs:
if c.cursor.is_null():
print("Null cursor found")
Running main.py should find one null cursor.
get_tokens
should be adapted to convert null Cursors into None
as done everywhere else.
Originally reported here: jnikula/hawkmoth#291
Metadata
Metadata
Assignees
Labels
clang:as-a-librarylibclang and C++ APIlibclang and C++ API