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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 26b373b..ea03932 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -334,6 +334,24 @@ set(HAVE_ASSERTIONS ${ASSERTIONS})
# Compiler option evaluation
if(USE_GCC OR USE_CLANG)
+ # Check for -Wall first, so later things can override pieces of it.
+ check_c_compiler_flag(-Wall HAVE_GCC_WALL)
+ if(HAVE_GCC_WALL)
+ list(APPEND EXTRA_CFLAGS "-Wall")
+ if(HAIKU)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
+ endif()
+ endif()
+
+ check_c_compiler_flag(-Wdeclaration-after-statement HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
+ if(HAVE_GCC_WDECLARATION_AFTER_STATEMENT)
+ check_c_compiler_flag(-Werror=declaration-after-statement HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
+ if(HAVE_GCC_WERROR_DECLARATION_AFTER_STATEMENT)
+ list(APPEND EXTRA_CFLAGS "-Werror=declaration-after-statement")
+ endif()
+ list(APPEND EXTRA_CFLAGS "-Wdeclaration-after-statement")
+ endif()
+
if(DEPENDENCY_TRACKING)
check_c_source_compiles("
#if !defined(__GNUC__) || __GNUC__ < 3
@@ -375,13 +393,6 @@ if(USE_GCC OR USE_CLANG)
endif()
set(CMAKE_REQUIRED_FLAGS ${ORIG_CMAKE_REQUIRED_FLAGS})
- check_c_compiler_flag(-Wall HAVE_GCC_WALL)
- if(HAVE_GCC_WALL)
- list(APPEND EXTRA_CFLAGS "-Wall")
- if(HAIKU)
- set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-multichar")
- endif()
- endif()
check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW)
if(HAVE_GCC_WSHADOW)
list(APPEND EXTRA_CFLAGS "-Wshadow")
diff --git a/configure b/configure
index a41f025..e0296b4 100755
--- a/configure
+++ b/configure
@@ -18650,6 +18650,43 @@ $as_echo "$have_gcc_preferred_stack_boundary" >&6; }
fi
}
+CheckDeclarationAfterStatement()
+{
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wdeclaration-after-statement option" >&5
+$as_echo_n "checking for GCC -Wdeclaration-after-statement option... " >&6; }
+ have_gcc_declaration_after_statement=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+
+ int x = 0;
+
+int
+main ()
+{
+
+
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+
+ have_gcc_declaration_after_statement=yes
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_gcc_declaration_after_statement" >&5
+$as_echo "$have_gcc_declaration_after_statement" >&6; }
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_declaration_after_statement = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
+ fi
+}
+
CheckWarnAll()
{
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for GCC -Wall option" >&5
@@ -22894,6 +22931,8 @@ fi
}
+CheckWarnAll
+
case "$host" in
*-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
case "$host" in
@@ -22962,6 +23001,7 @@ case "$host" in
*-*-minix*) ARCH=minix ;;
esac
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -23392,6 +23432,7 @@ $as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
ARCH=ios
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -23461,6 +23502,7 @@ $as_echo "#define SDL_FILESYSTEM_HAIKU 1" >>confdefs.h
EXTRA_CFLAGS="$EXTRA_CFLAGS -DTARGET_API_MAC_OSX"
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -23581,6 +23623,7 @@ $as_echo "#define SDL_AUDIO_DRIVER_EMSCRIPTEN 1" >>confdefs.h
fi
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -23630,8 +23673,6 @@ $as_echo "#define SDL_TIMER_UNIX 1" >>confdefs.h
;;
esac
-CheckWarnAll
-
# Verify that we have all the platform specific files we need
if test x$have_joystick != xyes; then
diff --git a/configure.in b/configure.in
index f585d01..f5fd22d 100644
--- a/configure.in
+++ b/configure.in
@@ -1124,6 +1124,30 @@ CheckStackBoundary()
fi
}
+dnl See if GCC's -Wdeclaration-after-statement is supported.
+dnl This lets us catch things that would fail on a C89 compiler when using
+dnl a modern GCC.
+CheckDeclarationAfterStatement()
+{
+ AC_MSG_CHECKING(for GCC -Wdeclaration-after-statement option)
+ have_gcc_declaration_after_statement=no
+
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$save_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
+ AC_TRY_COMPILE([
+ int x = 0;
+ ],[
+ ],[
+ have_gcc_declaration_after_statement=yes
+ ])
+ AC_MSG_RESULT($have_gcc_declaration_after_statement)
+ CFLAGS="$save_CFLAGS"
+
+ if test x$have_gcc_declaration_after_statement = xyes; then
+ EXTRA_CFLAGS="$EXTRA_CFLAGS -Wdeclaration-after-statement -Werror=declaration-after-statement"
+ fi
+}
+
dnl See if GCC's -Wall is supported.
CheckWarnAll()
{
@@ -2801,6 +2825,9 @@ AC_HELP_STRING([--enable-rpath], [use an rpath when linking SDL [[default=yes]]]
, enable_rpath=yes)
}
+dnl Do this on all platforms, before everything else (other things might want to override it).
+CheckWarnAll
+
dnl Set up the configuration based on the host platform!
case "$host" in
*-*-linux*|*-*-uclinux*|*-*-gnu*|*-*-k*bsd*-gnu|*-*-bsdi*|*-*-freebsd*|*-*-dragonfly*|*-*-netbsd*|*-*-openbsd*|*-*-sysv5*|*-*-solaris*|*-*-hpux*|*-*-aix*|*-*-minix*)
@@ -2870,6 +2897,7 @@ case "$host" in
*-*-minix*) ARCH=minix ;;
esac
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -3196,6 +3224,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
ARCH=ios
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -3265,6 +3294,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
EXTRA_CFLAGS="$EXTRA_CFLAGS -DTARGET_API_MAC_OSX"
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -3366,6 +3396,7 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
fi
CheckVisibilityHidden
+ CheckDeclarationAfterStatement
CheckDummyVideo
CheckDiskAudio
CheckDummyAudio
@@ -3407,9 +3438,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
;;
esac
-dnl Do this on all platforms, after everything else.
-CheckWarnAll
-
# Verify that we have all the platform specific files we need
if test x$have_joystick != xyes; then