Skip to content

Commit

Permalink
Cast offset to size_t to avoid c++11-narrowing warning (#92)
Browse files Browse the repository at this point in the history
e.g. with clang 18 on chimera linux:

_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: error: non-constant-expression cannot be narrowed from type 'long' to 'size_t' (aka 'unsigned long') in initializer list [-Wc++11-narrowing]
  583 |   { "a", ((char *)&((foo_t)4096)->a) - (char *)4096,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_CFFI_test_verify_anonymous_struct_with_star_typedef.cpp:583:10: note: insert an explicit cast to silence this issue
  583 |   { "a", ((char *)&((foo_t)4096)->a) - (char *)4096,
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |          static_cast<size_t>(                      )
  • Loading branch information
triallax authored Jun 29, 2024
1 parent 612940b commit 2ac63f8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/cffi/recompiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ def _struct_ctx(self, tp, cname, approxname, named_ptr=None):
if cname is None or fbitsize >= 0:
offset = '(size_t)-1'
elif named_ptr is not None:
offset = '((char *)&((%s)4096)->%s) - (char *)4096' % (
offset = '(size_t)(((char *)&((%s)4096)->%s) - (char *)4096)' % (
named_ptr.name, fldname)
else:
offset = 'offsetof(%s, %s)' % (tp.get_c_name(''), fldname)
Expand Down

0 comments on commit 2ac63f8

Please sign in to comment.