Enum with Constant Expression Instead of Constant Value
Created originally on Bitbucket by Anonymous
The CFFI cannot parse enums like this:
enum { VALUE = 1 + 2, };
The C99 standard says this is a valid constant-expression which the compiler should be able to constant-fold at compile-time. However, when I run it through CFFI I see:
cffi.FFIError: :594: unsupported expression: expected a simple numeric constant
Relevant backtrace:
File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/api.py", line 112, in cdef self._cdef(csource, override=override, packed=packed, pack=pack) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/api.py", line 126, in _cdef self._parser.parse(csource, override=override, **options) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 347, in parse self._internal_parse(csource) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 387, in _internal_parse decl.type, name=decl.name, partial_length_ok=True) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 629, in _get_type_and_quals tp = self._get_struct_union_enum_type('enum', type, name) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 738, in _get_struct_union_enum_type tp = self._build_enum_type(explicit_name, type.values) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 885, in _build_enum_type nextenumvalue = self._parse_constant(enum.value) File "/Users/anon/anaconda2/envs/py36/lib/python3.7/site-packages/cffi/cparser.py", line 872, in _parse_constant "simple numeric constant" % exprnode.coord.line) cffi.FFIError: :594: unsupported expression: expected a simple numeric constant