Open
Description
In libclang python bindings: if enum type is specified from alias that points to unsigned type, then the function Cursor::enum_value may return incorrect value for values that are above the middle of the type range.
Example:
using my_u_type = unsigned char;
enum A: my_u_type {
x = 0xff
};
The return of the Cursor::enum_value
is -1
.
Test case to reproduce the problem (can be added to clang/bindings/python/tests/cindex/test_cursor.py
to TestCursor
class):
def test_enum_values_on_elaborated_type(self):
tu = get_tu(
"using my_u_type = unsigned char; enum TEST : my_u_type { SPAM = 1, HAM = 0xff;", lang="cpp"
)
enum = get_cursor(tu, "TEST")
self.assertIsNotNone(enum)
self.assertEqual(enum.kind, CursorKind.ENUM_DECL)
enum_constants = list(enum.get_children())
self.assertEqual(len(enum_constants), 2)
spam, ham = enum_constants
self.assertEqual(spam.kind, CursorKind.ENUM_CONSTANT_DECL)
self.assertEqual(spam.enum_value, 1)
self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
self.assertEqual(ham.enum_value, 255)