dvidelabs / flatcc

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

GCC 11 compiler fails to build due to -pedantic and fallthrough #227

Closed le91688 closed 2 years ago

le91688 commented 2 years ago

the following build command fails

cmake -DFLATCC_INSTALL=on -DFLATCC_RTONLY=on -DCMAKE_BUILD_TYPE=Release && make install

+ make install                                                                                                                                                                                
[ 14%] Building C object src/runtime/CMakeFiles/flatccrt.dir/builder.c.o                                                                                                                      
[ 28%] Building C object src/runtime/CMakeFiles/flatccrt.dir/emitter.c.o                                                                                                                      
[ 42%] Building C object src/runtime/CMakeFiles/flatccrt.dir/refmap.c.o                                                                                                                       
[ 57%] Building C object src/runtime/CMakeFiles/flatccrt.dir/verifier.c.o                                                                                                                     
[ 71%] Building C object src/runtime/CMakeFiles/flatccrt.dir/json_parser.c.o                                                                                                                  
In file included from /usr/src/flatcc/include/flatcc/flatcc_flatbuffers.h:27,                                                                                                                 
                 from /usr/src/flatcc/include/flatcc/flatcc_builder.h:68,                                                                                                                     
                 from /usr/src/flatcc/include/flatcc/flatcc_json_parser.h:19,                                                                                                                 
                 from /usr/src/flatcc/src/runtime/json_parser.c:2:                                                                                                                            
/usr/src/flatcc/include/flatcc/flatcc_json_parser.h: In function 'flatcc_json_parser_symbol_part_ext':                                                                                        
/usr/src/flatcc/include/flatcc/portable/pattributes.h:61:33: error: ISO C does not support '[[]]' attributes before C2X [-Werror=pedantic]                                                    
   61 | # define pattribute_fallthrough [[__fallthrough__]]
le91688 commented 2 years ago

was looking through cmakelists and its not apparent if theres any way to disable -pendantic , but the readme says that -pendantic is not supported for newer compilers

The GCC --pedantic compiler option is not supported as of GCC-8+ because it forces non-portable code changes and because it tends to break the code base with each new GCC release.
mikkelfj commented 2 years ago

Yeah it looks like -pedantic is enabled for recent GCC - I'm not sure if it sneaked in, or what happened, but things seem to have been building.

It is in part these endless issues with perfectly valid fallthrough that made pedantic not worthwhile. In this case there is a perfectly valid check for the [[__fallthrough__]] attribute before using it.

Feel free to provide a patch disabling -pendantic on GCC 8+.

mikkelfj commented 2 years ago

Note that clang is usually sensible and that pendantic warnings are useful, but when GCC is constantly breaking code and forces code to be non-portable to silence warnings, then it stops being productive.

le91688 commented 2 years ago

would it make sense to disable -pedantic with -DFLATCC_PORTABLE perhaps?

my particular issue is with clang , and gcc has been working fine

mikkelfj commented 2 years ago

Se my PR comment. Just because your problem is in portable does not mean it can (or should be) used to fix issues with GCC versions. Next time it may be a fully C11 compliant project with up to spec glibc (if such a thing ever exists), but GCC decides that you have to write "I really mean to return from inside a while statement" in a comment. That is unrelated to portable.

mikkelfj commented 2 years ago

OK, based on a PR discussion it has become clear that clang raises the error and not GCC. We cannot afford to remove pendantic from clang so a fix is need in pattributes.h, likely by checking the C version.

https://github.com/dvidelabs/flatcc/blob/07ae7dca8118f9ab6d900a7d4797881cab708ba6/include/flatcc/portable/pattributes.h#L46-L66

Either the detection of PORTABLE_HAS_C_ATTRIBUTE or #if PORTABLE_HAS_C_ATTRIBUTE(__fallthrough__) but it is a bit strange since clang says it is OK then complains anyway.

mikkelfj commented 2 years ago

A quick fix might be to flag-D PORTABLE_EXPOSE_ATTRIBUTES=0.

le91688 commented 2 years ago

So an update @mikkelfj !

It appears I got some wires crossed in my logs. My issue was in fact GCC 11 . I have multiple targets being built, and GCC 10 was fine, but GCC 11 threw this error (as you mentioned earlier) . I can go ahead and implement the pedantic disable for GCC over a specified version as you had mentioned and that should do the trick.

My apologies for wasting your time hunting down a clang issue :/

mikkelfj commented 2 years ago

Fixed in #228