<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/108766>108766</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            libclang python binging returns incorrect enum value
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          fursov
      </td>
    </tr>
</table>

<pre>
    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)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVdFyqzYQ_RrxshMPCIPNAw-OHU_vtNftTNxnRqAF1AqJSsKN_74jYcd2etPemwdiVnvOnj27ALNWdAqxJNkzyXYRm1yvTdlOxupTVGt-Lr8okKJuJFMdjGfXawW1UFyozpJ0A6IFVNMA7jwiCAt2xEa0Ajm0Rg_ApGAWXM8cjFooZ8FpmFSoygOI0C24HpW_QDupxgmtYOsVGJJuSLrx_NWJyQlhYGcw6CajQKhGG4ONg_mo1W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