Menu

#31 Fixing some GCC compiler warnings

open
nobody
None
2015-06-28
2015-04-20
Marshall
No

I've tried to get rid of some warnings that appeared when building with gcc and "-O2 -Wall".
maybe you can use some of that. Not sure if you like all of it though.

-Warray-bounds:
https://github.com/darealshinji/aleph-one/commit/9267bb7c1efe6d3868bbeed4b0a68c84ba947188

-Wsequence-point:
https://github.com/darealshinji/aleph-one/commit/295c26b52584d5348e06f46f6acceeb532c25039

-Wnarrowing:
https://github.com/darealshinji/aleph-one/commit/24ed5cfac81b13602eadcb7d46bc0d691c79d547

-Wswitch:
https://github.com/darealshinji/aleph-one/commit/fb25db2d0b367427774a164dd3fb28d466de2447

-Wmaybe-uninitialized:
https://github.com/darealshinji/aleph-one/commit/9f5f82bafb46b4e533b7532bb398aefac02e8014
https://github.com/darealshinji/aleph-one/commit/f48480273f84efc2ae0ccfb36da9f1a612d8530e

-Wunused-*:
https://github.com/darealshinji/aleph-one/commit/fea42e5f9df095654b0f50d72bac3b12c2857a03

-Wparenthesis:
https://github.com/darealshinji/aleph-one/commit/3dc7550732b29f074c27e50d58a01e004be763f8

I've stopped -Wstrict-aliasing warnings by disabling strict-aliasing optimisations:
-fno-strict-aliasing

I've disable -Wsign-compare and -Wreorder warnings.

The remainging warnings are -Wdelete-non-virtual-dtor:

sdl_fonts.cpp: In function 'sdl_font_info* load_sdl_font(const TextSpec&)':
sdl_fonts.cpp:230:12: warning: deleting object of polymorphic class type 'sdl_font_info' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
  delete info;
         ^
sdl_fonts.cpp: In member function 'virtual void sdl_font_info::_unload()':
sdl_fonts.cpp:443:12: warning: deleting object of polymorphic class type 'sdl_font_info' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
  delete this; // !
         ^
sdl_fonts.cpp: In member function 'virtual void ttf_font_info::_unload()':
sdl_fonts.cpp:471:9: warning: deleting object of polymorphic class type 'ttf_font_info' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
  delete this;
         ^

Discussion

  • Marshall

    Marshall - 2015-04-22

    Some of the above changes are causing problems for me (probably the maybe-uninitialized stuff). Safe changes that don't break anything are attached as patches.

     
  • Marshall

    Marshall - 2015-04-24

    I've eliminated all -Wunused-variable and -Wunused-but-set-variable warnings and everything works fine for me.
    These are the compiler flags I set in configure.ac:

    AS_IF([test "x$CFLAGS" = "x"], [CFLAGS="-g -O2"])
    AS_IF([test "x$CXXFLAGS" = "x"], [CXXFLAGS="-g -O2"])
    CXXFLAGS="-Wall -Wno-sign-compare -Wno-maybe-uninitialized -Wno-narrowing -Wno-reorder -fno-strict-aliasing ${CXXFLAGS}"
    CFLAGS="-Wall -Wno-sign-compare -Wno-maybe-uninitialized ${CFLAGS}"
    
     
  • Jeremiah Morris

    Jeremiah Morris - 2015-06-28

    Thank you for submitting these! As you've seen, most of the warnings you identified are addressed now in trunk. I greatly appreciate your dedication, and hope you will continue to have fun hacking on Aleph One and sending in patches. :D

    In the spirit of encouragement and improvement, please take this bit of advice: don't be so hasty to silence compiler warnings that you wind up hiding underlying problems in the code. Some of the flagged spots in Aleph One had inadequate error checking or other issues, and the warning did its job in calling attention to poor-quality code, but the patches failed to address the deeper causes. Sometimes, half a fix isn't better than none.

     
  • Marshall

    Marshall - 2015-06-28

    Still learning, but I'll try my best. ;-)
    Thanks for the advice.

     

Log in to post a comment.