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

Comply with -Wconversion strict gcc setting #8062

Closed
greenrobot opened this issue Aug 9, 2023 · 2 comments
Closed

Comply with -Wconversion strict gcc setting #8062

greenrobot opened this issue Aug 9, 2023 · 2 comments
Labels

Comments

@greenrobot
Copy link
Contributor

greenrobot commented Aug 9, 2023

Disclaimer why this matters: (very) strict compiler settings are often required in mission critical projects.

"Regression" introduced in aeba096 adds a new strict compiler violation in gcc.

flatbuffers/flatbuffers/flatbuffer_builder.h:48:23: error: conversion from 'long unsigned int' to 'flatbuffers::voffset_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
   48 |   return fixed_fields + field_id * sizeof(voffset_t);
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Causing code is still present in today's master branch:

// Converts a Field ID to a virtual table offset.
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
  // Should correspond to what EndTable() below builds up.
  const voffset_t fixed_fields =
      2 * sizeof(voffset_t);  // Vtable size and Object Size.
  return fixed_fields + field_id * sizeof(voffset_t);
}

greenrobot added a commit to objectbox/flatbuffers that referenced this issue Aug 10, 2023
Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts verify the conversion.
greenrobot added a commit to objectbox/flatbuffers that referenced this issue Aug 10, 2023
Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
greenrobot added a commit to objectbox/flatbuffers that referenced this issue Sep 29, 2023
Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
dbaileychess pushed a commit that referenced this issue Sep 29, 2023
Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
candysonya pushed a commit to candysonya/flatbuffers that referenced this issue Jan 8, 2024
…oogle#8065)

Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
Copy link
Contributor

This issue is stale because it has been open 6 months with no activity. Please comment or label not-stale, or this will be closed in 14 days.

@github-actions github-actions bot added the stale label Feb 14, 2024
@greenrobot
Copy link
Contributor Author

This was already merged via #8065

jochenparm pushed a commit to jochenparm/flatbuffers that referenced this issue Oct 29, 2024
…oogle#8065)

Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this issue Oct 29, 2024
…oogle#8065)

Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion.
Also, add asserts to verify the conversions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant