2
0
mirror of https://github.com/sudo-project/sudo.git synced 2025-08-31 14:25:15 +00:00

Add -Wimplicit-fallthrough to --enable-warnings if available.

Note that clang 10 has support for -Wimplicit-fallthrough in C code
but doesn't recognize lint-style FALLTHROUGH comments like gcc does
so we can't use it.
This commit is contained in:
Todd C. Miller
2020-06-20 13:51:02 -06:00
parent 23b1ee2f45
commit 5e9346d4e9
2 changed files with 65 additions and 0 deletions

36
configure vendored
View File

@@ -27682,6 +27682,42 @@ _ACEOF
if test -n "$GCC"; then
if test X"$enable_warnings" = X"yes" -o X"$with_devel" = X"yes"; then
CFLAGS="${CFLAGS} -Wall -Wsign-compare -Wpointer-arith"
_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wimplicit-fallthrough -Werror"
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler acceptd -Wimplicit-fallthrough" >&5
$as_echo_n "checking whether C compiler acceptd -Wimplicit-fallthrough... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
int main(int argc, char *argv[])
{
int num = argc + 1;
switch (num) {
case 1:
num = 0;
/* FALLTHROUGH */
case 0:
num++;
}
return num;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
CFLAGS="$_CFLAGS -Wimplicit-fallthrough"
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
CFLAGS="$_CFLAGS"
fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
if test X"$enable_werror" = X"yes"; then
CFLAGS="${CFLAGS} -Werror"

View File

@@ -4547,6 +4547,35 @@ dnl
if test -n "$GCC"; then
if test X"$enable_warnings" = X"yes" -o X"$with_devel" = X"yes"; then
CFLAGS="${CFLAGS} -Wall -Wsign-compare -Wpointer-arith"
dnl
dnl Check whether -Wimplicit-fallthrough is available and
dnl recognizes /* FALLTHROUGH */ comments. Clang 10 requires
dnl the "fallthrough" attribute which we don't use.
dnl
_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wimplicit-fallthrough -Werror"
AC_MSG_CHECKING([whether C compiler acceptd -Wimplicit-fallthrough])
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
int main(int argc, char *argv[])
{
int num = argc + 1;
switch (num) {
case 1:
num = 0;
/* FALLTHROUGH */
case 0:
num++;
}
return num;
}
]])], [
AC_MSG_RESULT([yes])
CFLAGS="$_CFLAGS -Wimplicit-fallthrough"
], [
AC_MSG_RESULT([no])
CFLAGS="$_CFLAGS"
])
fi
if test X"$enable_werror" = X"yes"; then
CFLAGS="${CFLAGS} -Werror"