Partial fix for bug 2556 - add compilation flag -Wshadow
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jun 2014 11:02:56 -0700
changeset 8910c23ffe72934c
parent 8909 a894224dc538
child 8912 5dfda9d3ccbd
Partial fix for bug 2556 - add compilation flag -Wshadow

I added -Wshadow and then turned it off again because of massive variable shadowing in the blit macros.

Feel free to go through that code and fix these if you want. Just uncomment CheckWarnShadow in configure.in if you want to try this.
CMakeLists.txt
configure
configure.in
src/events/SDL_events.c
src/events/SDL_gesture.c
     1.1 --- a/CMakeLists.txt	Sun Jun 22 10:05:59 2014 -0700
     1.2 +++ b/CMakeLists.txt	Sun Jun 22 11:02:56 2014 -0700
     1.3 @@ -334,6 +334,7 @@
     1.4        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
     1.5      endif()
     1.6    endif()
     1.7 +  #check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
     1.8  endif()
     1.9  
    1.10  if(ASSEMBLY)
     2.1 --- a/configure	Sun Jun 22 10:05:59 2014 -0700
     2.2 +++ b/configure	Sun Jun 22 11:02:56 2014 -0700
     2.3 @@ -18684,6 +18684,43 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +CheckWarnShadow()
     2.8 +{
     2.9 +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wshadow option" >&5
    2.10 +$as_echo_n "checking for GCC -Wshadow option... " >&6; }
    2.11 +    have_gcc_Wshadow=no
    2.12 +
    2.13 +    save_CFLAGS="$CFLAGS"
    2.14 +    CFLAGS="$save_CFLAGS -Wshadow"
    2.15 +    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
    2.16 +/* end confdefs.h.  */
    2.17 +
    2.18 +    int x = 0;
    2.19 +
    2.20 +int
    2.21 +main ()
    2.22 +{
    2.23 +
    2.24 +
    2.25 +  ;
    2.26 +  return 0;
    2.27 +}
    2.28 +_ACEOF
    2.29 +if ac_fn_c_try_compile "$LINENO"; then :
    2.30 +
    2.31 +    have_gcc_Wshadow=yes
    2.32 +
    2.33 +fi
    2.34 +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
    2.35 +    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_Wshadow" >&5
    2.36 +$as_echo "$have_gcc_Wshadow" >&6; }
    2.37 +    CFLAGS="$save_CFLAGS"
    2.38 +
    2.39 +    if test x$have_gcc_Wshadow = xyes; then
    2.40 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -Wshadow"
    2.41 +    fi
    2.42 +}
    2.43 +
    2.44  CheckWayland()
    2.45  {
    2.46      # Check whether --enable-video-wayland was given.
    2.47 @@ -23337,6 +23374,7 @@
    2.48  esac
    2.49  
    2.50  CheckWarnAll
    2.51 +#CheckWarnShadow
    2.52  
    2.53  # Verify that we have all the platform specific files we need
    2.54  
     3.1 --- a/configure.in	Sun Jun 22 10:05:59 2014 -0700
     3.2 +++ b/configure.in	Sun Jun 22 11:02:56 2014 -0700
     3.3 @@ -1159,6 +1159,28 @@
     3.4      fi
     3.5  }
     3.6  
     3.7 +dnl See if GCC's -Wshadow is supported.
     3.8 +CheckWarnShadow()
     3.9 +{
    3.10 +    AC_MSG_CHECKING(for GCC -Wshadow option)
    3.11 +    have_gcc_Wshadow=no
    3.12 +
    3.13 +    save_CFLAGS="$CFLAGS"
    3.14 +    CFLAGS="$save_CFLAGS -Wshadow"
    3.15 +    AC_TRY_COMPILE([
    3.16 +    int x = 0;
    3.17 +    ],[
    3.18 +    ],[
    3.19 +    have_gcc_Wshadow=yes
    3.20 +    ])
    3.21 +    AC_MSG_RESULT($have_gcc_Wshadow)
    3.22 +    CFLAGS="$save_CFLAGS"
    3.23 +
    3.24 +    if test x$have_gcc_Wshadow = xyes; then
    3.25 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -Wshadow"
    3.26 +    fi
    3.27 +}
    3.28 +
    3.29  dnl Check for Wayland
    3.30  CheckWayland()
    3.31  {
    3.32 @@ -3216,6 +3238,7 @@
    3.33  
    3.34  dnl Do this on all platforms, after everything else.
    3.35  CheckWarnAll
    3.36 +#CheckWarnShadow
    3.37  
    3.38  # Verify that we have all the platform specific files we need
    3.39  
     4.1 --- a/src/events/SDL_events.c	Sun Jun 22 10:05:59 2014 -0700
     4.2 +++ b/src/events/SDL_events.c	Sun Jun 22 11:02:56 2014 -0700
     4.3 @@ -302,7 +302,6 @@
     4.4                             For now we'll guarantee it's valid at least until
     4.5                             the next call to SDL_PeepEvents()
     4.6                           */
     4.7 -                        SDL_SysWMEntry *wmmsg;
     4.8                          if (SDL_EventQ.wmmsg_free) {
     4.9                              wmmsg = SDL_EventQ.wmmsg_free;
    4.10                              SDL_EventQ.wmmsg_free = wmmsg->next;
     5.1 --- a/src/events/SDL_gesture.c	Sun Jun 22 10:05:59 2014 -0700
     5.2 +++ b/src/events/SDL_gesture.c	Sun Jun 22 11:02:56 2014 -0700
     5.3 @@ -473,7 +473,6 @@
     5.4  void SDL_GestureProcessEvent(SDL_Event* event)
     5.5  {
     5.6      float x,y;
     5.7 -    SDL_FloatPoint path[DOLLARNPOINTS];
     5.8      int index;
     5.9      int i;
    5.10      float pathDx, pathDy;
    5.11 @@ -497,6 +496,8 @@
    5.12  
    5.13          /* Finger Up */
    5.14          if (event->type == SDL_FINGERUP) {
    5.15 +            SDL_FloatPoint path[DOLLARNPOINTS];
    5.16 +
    5.17              inTouch->numDownFingers--;
    5.18  
    5.19  #ifdef ENABLE_DOLLAR