dvidelabs / flatcc

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

Misleading indentation errors on gcc 11.x #183

Closed gmolina-a2e closed 3 years ago

gmolina-a2e commented 3 years ago

Had to suppress that warning to be able to compile.

gmolina-a2e commented 3 years ago

This does the trick: if (NOT (GCC_VERSION VERSION_LESS 11.0))

Disable warning on misleading indentation it become more aggressive in 11.0

           set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-misleading-indentation")
  endif()
mikkelfj commented 3 years ago

Where do you get indentation errors? If it it is localized, perhaps we can fix at source level, otherwise I'm happy to add you suggestion. I presume this is for the main CMake file.

gmolina-a2e commented 3 years ago

If am not mistaken all errors are in this file: flatbuffers_common_builder.h I tried an auto formatter (clang-format) with little success. And yeah this is for the main CMake file.

mikkelfj commented 3 years ago

OK, my patience with GCC warnings is limited so I'll disable.

mikkelfj commented 3 years ago

Should be fixed on master, please check. Wonder why this isn't part of pedantic that should already have been disabled on recent GCC.

gmolina-a2e commented 3 years ago

It is, thanks. I will close this issue.

mikkelfj commented 3 years ago

I see, pedantic is still on for GCC, next time I'm going to remove pedantic for GCC.

amery commented 11 months ago

as the problem is still present, what about including #pragma GCC diagnostic ignored "-Wmisleading-indentation" on the generated files?

mikkelfj commented 11 months ago

@amery There is distinction between compiling the flatcc tool chain and the runtime. Notably the runtime (library and generated) can be compiled by whatever tool chain the user prefers. I guess this topic only covers the tool chain.

There is a hook for dealing with runtime warnings in the portable library. This is mostly for generic issues that prevent smooth cross platform behaviour and are therefore always enabled. Others should be dealt with in the users tool chain.

The current situation is a bit special because the warning is actually useful in the general case, but specifically for flatcc generated code, it is not helpful. Therefore we cannot or should not inject the warning at the portable layer because the portable library is not flatcc specific.

I have not fully investigated, but I think can conditionally disable the the warning in pdiagnostic.h which is included in all generated files. Then set a flag in flatcc specific include files to enable the warning in this context.

Would you be willing to look into this?

Here the warning can be added in either pwarnings or probably better pdiagnostic.h, guarded by a PDIAGNOSTIC flag:

https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/portable/pwarnings.h https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/portable/pdiagnostic.h https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/portable/pdiagnostic_push.h (and pop)

I think the PDIAGNOSTIC enabled warning could then be enabled with a define in https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/flatcc_flatbuffers.h or https://github.com/dvidelabs/flatcc/blob/master/include/flatcc/flatcc_rtconfig.h