Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/bindings/python/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,8 @@ def enum_value(self):
underlying_type = self.type
if underlying_type.kind == TypeKind.ENUM:
underlying_type = underlying_type.get_declaration().enum_type
if underlying_type.kind == TypeKind.ELABORATED:
underlying_type = underlying_type.get_canonical()
if underlying_type.kind in (
TypeKind.CHAR_U,
TypeKind.UCHAR,
Expand Down
19 changes: 19 additions & 0 deletions clang/bindings/python/tests/cindex/test_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,25 @@ def test_enum_values_cpp(self):
self.assertEqual(ham.kind, CursorKind.ENUM_CONSTANT_DECL)
self.assertEqual(ham.enum_value, 0x10000000000)

def test_enum_values_on_elaborated_type(self):
tu = get_tu(
"using myUType = unsigned char; enum TEST : myUType { 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)

def test_annotation_attribute(self):
tu = get_tu(
'int foo (void) __attribute__ ((annotate("here be annotation attribute")));'
Expand Down
Loading