[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Use -Wimplicit-fallthrough only with GCC >= 7
From: |
Bruno Haible |
Subject: |
Re: [PATCH] Use -Wimplicit-fallthrough only with GCC >= 7 |
Date: |
Wed, 05 Jan 2022 20:08:03 +0100 |
Hi José,
> The -Wimplicit-fallthrough switch was introduced in GCC 7.
>
> Older version of GCC (like 3 and 4) do not complain when they get passed
> an invalid -WFOO option
It depends on the option:
$ gcc-version 3.1 -Wimplicit-fallthrough -S /tmp/empty.c
$ gcc-version 3.2.2 -Wimplicit-fallthrough -S /tmp/empty.c
$ gcc-version 3.3.6 -Wimplicit-fallthrough -S /tmp/empty.c
$ gcc-version 3.4.4 -Wimplicit-fallthrough -S /tmp/empty.c
$ gcc-version 4.0.4 -Wimplicit-fallthrough -S /tmp/empty.c
cc1: error: unrecognized command line option "-Wimplicit-fallthrough"
$ gcc-version 4.1.2 -Wimplicit-fallthrough -S /tmp/empty.c
cc1: error: unrecognized command line option "-Wimplicit-fallthrough"
$ gcc-version 3.1 -Wimplicit-fallthrough -S /tmp/empty.c
$ gcc-version 3.1 -Wimplicit-bullshit -S /tmp/empty.c
$ gcc-version 3.1 -Wimplicit- -S /tmp/empty.c
$ gcc-version 3.1 -Wimplicit -S /tmp/empty.c
$ gcc-version 3.1 -Wimplici -S /tmp/empty.c
cc1: unrecognized option `-Wimplici'
> , but GCC 6 bails out like this:
>
> gcc: error: unrecognized command line option '-Wimplicit-fallthrough';
> did you mean '-Wno-fallthrough'?
>
> diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
> index 179aac7aa1..62741f830f 100644
> --- a/m4/gnulib-common.m4
> +++ b/m4/gnulib-common.m4
> @@ -896,7 +896,7 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
> dnl -Wno-conversion >= 3 >= 3.9
> dnl -Wno-float-conversion >= 4.9 >= 3.9
> dnl -Wno-float-equal >= 3 >= 3.9
> - dnl -Wimplicit-fallthrough >= 3 >= 3.9
> + dnl -Wimplicit-fallthrough >= 7 >= 3.9
> dnl -Wno-pedantic >= 4.8 >= 3.9
> dnl -Wno-sign-compare >= 3 >= 3.9
> dnl -Wno-sign-conversion >= 4.3 >= 3.9
> @@ -911,12 +911,14 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
> -Wno-cast-qual
> -Wno-conversion
> -Wno-float-equal
> - -Wimplicit-fallthrough
> -Wno-sign-compare
> -Wno-undef
> -Wno-unused-function
> -Wno-unused-parameter
> #endif
> + #if __GNUC__ => 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
> + -Wimplicit-fallthrough
> + #endif
> #if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ +
> (__clang_minor__ >= 9) > 3)
> -Wno-float-conversion
> #endif
Thanks. I applied your patch, with the obligatory typo fix.
Bruno
2022-01-05 Bruno Haible <bruno@clisp.org>
Fix last commit.
Based on a patch by José E. Marchesi <jemarch@gnu.org>, reported in
<https://lists.gnu.org/archive/html/bug-gnulib/2022-01/msg00036.html>.
* m4/gnulib-common.m4 (gl_CC_GNULIB_WARNINGS): Don't enable
-Wimplicit-fallthrough for GCC < 7.
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 179aac7aa1..afe0836083 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -896,7 +896,7 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
dnl -Wno-conversion >= 3 >= 3.9
dnl -Wno-float-conversion >= 4.9 >= 3.9
dnl -Wno-float-equal >= 3 >= 3.9
- dnl -Wimplicit-fallthrough >= 3 >= 3.9
+ dnl -Wimplicit-fallthrough >= 7 >= 3.9
dnl -Wno-pedantic >= 4.8 >= 3.9
dnl -Wno-sign-compare >= 3 >= 3.9
dnl -Wno-sign-conversion >= 4.3 >= 3.9
@@ -911,7 +911,6 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
-Wno-cast-qual
-Wno-conversion
-Wno-float-equal
- -Wimplicit-fallthrough
-Wno-sign-compare
-Wno-undef
-Wno-unused-function
@@ -920,6 +919,9 @@ AC_DEFUN([gl_CC_GNULIB_WARNINGS],
#if __GNUC__ + (__GNUC_MINOR__ >= 9) > 4 || (__clang_major__ +
(__clang_minor__ >= 9) > 3)
-Wno-float-conversion
#endif
+ #if __GNUC__ >= 7 || (__clang_major__ + (__clang_minor__ >= 9) > 3)
+ -Wimplicit-fallthrough
+ #endif
#if __GNUC__ + (__GNUC_MINOR__ >= 8) > 4 || (__clang_major__ +
(__clang_minor__ >= 9) > 3)
-Wno-pedantic
#endif