dvidelabs / flatcc

FlatBuffers Compiler and Library in C for C
Apache License 2.0
631 stars 180 forks source link

mingw compiler warnings #239

Closed le91688 closed 1 year ago

le91688 commented 1 year ago

There are multiple compiler warnings when building flatbuffers with mingw

there are a multitude of warnings generated, but here is a concatenated log output below

flatbuffers/flatbuffers_common_builder.h: In function 'flatbuffers_int16_array_copy_from_pe':
flatbuffers/flatbuffers_common_builder.h:341:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  341 |   for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); return p; }\
      |   ^~~
flatbuffers/flatbuffers_common_builder.h:360:1: note: in expansion of macro '__flatbuffers_define_fixed_array_primitives'
  360 | __ ## NS ## define_fixed_array_primitives(NS, N, T)\
      | ^~
flatbuffers/flatbuffers_common_builder.h:675:1: note: in expansion of macro '__flatbuffers_build_scalar'
  675 | __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int16, int16_t)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
flatbuffers/flatbuffers_common_builder.h:341:62: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  341 |   for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); return p; }\
      |                                                              ^~~~~~
flatbuffers/flatbuffers_common_builder.h:360:1: note: in expansion of macro '__flatbuffers_define_fixed_array_primitives'
  360 | __ ## NS ## define_fixed_array_primitives(NS, N, T)\
      | ^~
/flatbuffers/flatbuffers_common_builder.h:675:1: note: in expansion of macro '__flatbuffers_build_scalar'
  675 | __flatbuffers_build_scalar(flatbuffers_, flatbuffers_int16, int16_t)
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~
flatbuffers/flatbuffers_common_builder.h:340:69: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  340 | { size_t i; if (NS ## is_native_pe()) memcpy(p, p2, n * sizeof(T)); else\
      |                                                                     ^~~~~
  341 |   for (i = 0; i < n; ++i) N ## _copy_from_pe(&p[i], &p2[i]); return p; }\
mikkelfj commented 1 year ago

Hi @le91688, thanks for reporting.

This is solidly in the won't fix category - except I'd accept a PR to the CMakeList.txt file to silence the warning.

The warning is benign: -Wmisleading-indentation but it is targetting generated code that is very dense and mostly macro expanded. There is no formatting in this code and it is generally not for human consumption, or, as noted in the documentation, the generated code can be passed through clang format or similar if and when the generated code is of interest (mostly combined with filtering out function prototypes to list all generated functions).

Now, if you do find one off ill-formatted and/or misleading formatting in other areas of the code, I'd be happy to fix those.

I'm not sure what warnings you are using, but I suspect you are using GCC with MinGW. If you are using -Wpedantic, that should be disabled because flatcc officially does not support pedantic warnings on GCC because it breaks too many things. Clang still builds with pedantic warnings.

Hope this helps.