Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast offset to size_t to avoid c++11-narrowing warning #92

Merged
merged 1 commit into from
Jun 29, 2024

Conversation

triallax
Copy link
Contributor

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

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>(                      )
@arigo
Copy link
Contributor

arigo commented Jun 29, 2024

Thanks. The additional cast looks harmless and if it helps some compilers, then let's go for it.

@arigo arigo enabled auto-merge (squash) June 29, 2024 14:18
@arigo arigo merged commit 2ac63f8 into python-cffi:main Jun 29, 2024
11 checks passed
@triallax triallax deleted the offset-size_t branch June 29, 2024 14:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants