Try to build with GCC's -Wdeclaration-after-statement.
authorRyan C. Gordon <icculus@icculus.org>
Mon, 04 Jan 2016 22:58:38 -0500
changeset 100098c6b05b0a27e
parent 10008 fb4e35d0d523
child 10010 cc07869515b2
Try to build with GCC's -Wdeclaration-after-statement.

This will help catch things that'll cause issues on C89 compilers before we
send them on to fail on Buildbot.
CMakeLists.txt
configure
configure.in
     1.1 --- a/CMakeLists.txt	Mon Jan 04 22:00:04 2016 -0500
     1.2 +++ b/CMakeLists.txt	Mon Jan 04 22:58:38 2016 -0500
     1.3 @@ -334,6 +334,24 @@
     1.4  
     1.5  # Compiler option evaluation
     1.6  if(USE_GCC OR USE_CLANG)
     1.7 +  # Check for -Wall first, so later things can override pieces of it.
     1.8 +  check_c_compiler_flag(-Wall HAVE_GCC_WALL)
     1.9 +  if(HAVE_GCC_WALL)
    1.10 +    list(APPEND EXTRA_CFLAGS "-Wall")
    1.11 +    if(HAIKU)
    1.12 +      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
    1.13 +    endif()
    1.14 +  endif()
    1.15 +
    1.16 +  check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
    1.17 +  if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
    1.18 +    check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
    1.19 +    if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
    1.20 +      list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
    1.21 +    endif()
    1.22 +    list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
    1.23 +  endif()
    1.24 +
    1.25    if(DEPENDENCY_TRACKING)
    1.26      check_c_source_compiles("
    1.27          #if !defined(__GNUC__) || __GNUC__ < 3
    1.28 @@ -375,13 +393,6 @@
    1.29    endif()
    1.30    set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
    1.31  
    1.32 -  check_c_compiler_flag(-Wall HAVE_GCC_WALL)
    1.33 -  if(HAVE_GCC_WALL)
    1.34 -    list(APPEND EXTRA_CFLAGS "-Wall")
    1.35 -    if(HAIKU)
    1.36 -      set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
    1.37 -    endif()
    1.38 -  endif()
    1.39    check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
    1.40    if(HAVE_GCC_WSHADOW)
    1.41      list(APPEND EXTRA_CFLAGS "-Wshadow")
     2.1 --- a/configure	Mon Jan 04 22:00:04 2016 -0500
     2.2 +++ b/configure	Mon Jan 04 22:58:38 2016 -0500
     2.3 @@ -18650,6 +18650,43 @@
     2.4      fi
     2.5  }
     2.6  
     2.7 +CheckDeclarationAfterStatement()
     2.8 +{
     2.9 +    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wdeclaration-after-statement option" >&5
    2.10 +$as_echo_n "checking for GCC -Wdeclaration-after-statement option... " >&6; }
    2.11 +    have_gcc_declaration_after_statement=no
    2.12 +
    2.13 +    save_CFLAGS="$CFLAGS"
    2.14 +    CFLAGS="$save_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
    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_declaration_after_statement=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_declaration_after_statement" >&5
    2.36 +$as_echo "$have_gcc_declaration_after_statement" >&6; }
    2.37 +    CFLAGS="$save_CFLAGS"
    2.38 +
    2.39 +    if test x$have_gcc_declaration_after_statement = xyes; then
    2.40 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
    2.41 +    fi
    2.42 +}
    2.43 +
    2.44  CheckWarnAll()
    2.45  {
    2.46      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wall option" >&5
    2.47 @@ -22894,6 +22931,8 @@
    2.48  
    2.49  }
    2.50  
    2.51 +CheckWarnAll
    2.52 +
    2.53  case "$host" in
    2.54      *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
    2.55          case "$host" in
    2.56 @@ -22962,6 +23001,7 @@
    2.57              *-*-minix*)         ARCH=minix ;;
    2.58          esac
    2.59          CheckVisibilityHidden
    2.60 +        CheckDeclarationAfterStatement
    2.61          CheckDummyVideo
    2.62          CheckDiskAudio
    2.63          CheckDummyAudio
    2.64 @@ -23392,6 +23432,7 @@
    2.65          ARCH=ios
    2.66  
    2.67          CheckVisibilityHidden
    2.68 +        CheckDeclarationAfterStatement
    2.69          CheckDummyVideo
    2.70          CheckDiskAudio
    2.71          CheckDummyAudio
    2.72 @@ -23461,6 +23502,7 @@
    2.73          EXTRA_CFLAGS="$EXTRA_CFLAGS -DTARGET_API_MAC_OSX"
    2.74  
    2.75          CheckVisibilityHidden
    2.76 +        CheckDeclarationAfterStatement
    2.77          CheckDummyVideo
    2.78          CheckDiskAudio
    2.79          CheckDummyAudio
    2.80 @@ -23581,6 +23623,7 @@
    2.81          fi
    2.82  
    2.83          CheckVisibilityHidden
    2.84 +        CheckDeclarationAfterStatement
    2.85          CheckDummyVideo
    2.86          CheckDiskAudio
    2.87          CheckDummyAudio
    2.88 @@ -23630,8 +23673,6 @@
    2.89          ;;
    2.90  esac
    2.91  
    2.92 -CheckWarnAll
    2.93 -
    2.94  # Verify that we have all the platform specific files we need
    2.95  
    2.96  if test x$have_joystick != xyes; then
     3.1 --- a/configure.in	Mon Jan 04 22:00:04 2016 -0500
     3.2 +++ b/configure.in	Mon Jan 04 22:58:38 2016 -0500
     3.3 @@ -1124,6 +1124,30 @@
     3.4      fi
     3.5  }
     3.6  
     3.7 +dnl See if GCC's -Wdeclaration-after-statement is supported.
     3.8 +dnl  This lets us catch things that would fail on a C89 compiler when using
     3.9 +dnl  a modern GCC.
    3.10 +CheckDeclarationAfterStatement()
    3.11 +{
    3.12 +    AC_MSG_CHECKING(for GCC -Wdeclaration-after-statement option)
    3.13 +    have_gcc_declaration_after_statement=no
    3.14 +
    3.15 +    save_CFLAGS="$CFLAGS"
    3.16 +    CFLAGS="$save_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
    3.17 +    AC_TRY_COMPILE([
    3.18 +    int x = 0;
    3.19 +    ],[
    3.20 +    ],[
    3.21 +    have_gcc_declaration_after_statement=yes
    3.22 +    ])
    3.23 +    AC_MSG_RESULT($have_gcc_declaration_after_statement)
    3.24 +    CFLAGS="$save_CFLAGS"
    3.25 +
    3.26 +    if test x$have_gcc_declaration_after_statement = xyes; then
    3.27 +        EXTRA_CFLAGS="$EXTRA_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
    3.28 +    fi
    3.29 +}
    3.30 +
    3.31  dnl See if GCC's -Wall is supported.
    3.32  CheckWarnAll()
    3.33  {
    3.34 @@ -2801,6 +2825,9 @@
    3.35                    , enable_rpath=yes)
    3.36  }
    3.37  
    3.38 +dnl Do this on all platforms, before everything else (other things might want to override it).
    3.39 +CheckWarnAll
    3.40 +
    3.41  dnl Set up the configuration based on the host platform!
    3.42  case "$host" in
    3.43      *-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
    3.44 @@ -2870,6 +2897,7 @@
    3.45              *-*-minix*)         ARCH=minix ;;
    3.46          esac
    3.47          CheckVisibilityHidden
    3.48 +        CheckDeclarationAfterStatement
    3.49          CheckDummyVideo
    3.50          CheckDiskAudio
    3.51          CheckDummyAudio
    3.52 @@ -3196,6 +3224,7 @@
    3.53          ARCH=ios
    3.54  
    3.55          CheckVisibilityHidden
    3.56 +        CheckDeclarationAfterStatement
    3.57          CheckDummyVideo
    3.58          CheckDiskAudio
    3.59          CheckDummyAudio
    3.60 @@ -3265,6 +3294,7 @@
    3.61          EXTRA_CFLAGS="$EXTRA_CFLAGS -DTARGET_API_MAC_OSX"
    3.62  
    3.63          CheckVisibilityHidden
    3.64 +        CheckDeclarationAfterStatement
    3.65          CheckDummyVideo
    3.66          CheckDiskAudio
    3.67          CheckDummyAudio
    3.68 @@ -3366,6 +3396,7 @@
    3.69          fi
    3.70  
    3.71          CheckVisibilityHidden
    3.72 +        CheckDeclarationAfterStatement
    3.73          CheckDummyVideo
    3.74          CheckDiskAudio
    3.75          CheckDummyAudio
    3.76 @@ -3407,9 +3438,6 @@
    3.77          ;;
    3.78  esac
    3.79  
    3.80 -dnl Do this on all platforms, after everything else.
    3.81 -CheckWarnAll
    3.82 -
    3.83  # Verify that we have all the platform specific files we need
    3.84  
    3.85  if test x$have_joystick != xyes; then