Using -Wno-error where only -Wno-implicit-fallthrough was meant was deemed
to coarse, so this patch attempts to add a configure check for this warnign
and only use -Wno-implicit-fallthrough when appropriate.

Bootstrapped on x86_64-linux and ppc64-linux, ok for trunk?

2016-09-27  Marek Polacek  <pola...@redhat.com>

        * Makefile.in (insn-attrtab.o-warn, insn-dfatab.o-warn,
        insn-latencytab.o-warn, insn-output.o-warn, insn-emit.o-warn): Use
        @W_NO_IMPLICIT_FALLTHROUGH@ instead of -Wno-error.
        * configure.ac: Add check for -Wimplicit-fallthrough.
        * configure: Regenerate.

diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index ff12908..5871a47 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -218,11 +218,11 @@ libgcov-merge-tool.o-warn = -Wno-error
 gimple-match.o-warn = -Wno-unused
 generic-match.o-warn = -Wno-unused
 dfp.o-warn = -Wno-strict-aliasing
-insn-attrtab.o-warn = -Wno-error
-insn-dfatab.o-warn = -Wno-error
-insn-latencytab.o-warn = -Wno-error
-insn-output.o-warn = -Wno-error
-insn-emit.o-warn = -Wno-error
+insn-attrtab.o-warn = @W_NO_IMPLICIT_FALLTHROUGH@
+insn-dfatab.o-warn = @W_NO_IMPLICIT_FALLTHROUGH@
+insn-latencytab.o-warn = @W_NO_IMPLICIT_FALLTHROUGH@
+insn-output.o-warn = @W_NO_IMPLICIT_FALLTHROUGH@
+insn-emit.o-warn = @W_NO_IMPLICIT_FALLTHROUGH@
 
 # All warnings have to be shut off in stage1 if the compiler used then
 # isn't gcc; configure determines that.  WARN_CFLAGS will be either
diff --git a/gcc/configure b/gcc/configure
index 96eba9e..459f513 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -789,6 +789,7 @@ valgrind_path
 TREECHECKING
 nocommon_flag
 noexception_flags
+W_NO_IMPLICIT_FALLTHROUGH
 warn_cxxflags
 warn_cflags
 c_strict_warn
@@ -7006,6 +7007,34 @@ fi
 
 
 
+# Check whether -Wimplicit-fallthrough works.
+W_NO_IMPLICIT_FALLTHROUGH=
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for -Wimplicit-fallthrough 
option" >&5
+$as_echo_n "checking for -Wimplicit-fallthrough option... " >&6; }
+if test "${gcc_cv_implicit_fallthrough+set}" = set; then :
+  $as_echo_n "(cached) " >&6
+else
+  saved_CXXFLAGS="$CXXFLAGS"
+   CXXFLAGS="$CXXFLAGS -Wimplicit-fallthrough"
+   cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+int main(void) {return 0;}
+_ACEOF
+if ac_fn_cxx_try_compile "$LINENO"; then :
+  gcc_cv_implicit_fallthrough=yes
+else
+  gcc_cv_implicit_fallthrough=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+   CXXFLAGS="$saved_CXXFLAGS"
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_implicit_fallthrough" 
>&5
+$as_echo "$gcc_cv_implicit_fallthrough" >&6; }
+if test "$gcc_cv_implicit_fallthrough" = "yes"; then
+  W_NO_IMPLICIT_FALLTHROUGH="-Wno-implicit-fallthrough"
+fi
+
+
 # Disable exceptions and RTTI if building with g++
 ac_ext=c
 ac_cpp='$CPP $CPPFLAGS'
@@ -18476,7 +18505,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18479 "configure"
+#line 18508 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -18582,7 +18611,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 18585 "configure"
+#line 18614 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
diff --git a/gcc/configure.ac b/gcc/configure.ac
index 534f22e..b72e52a 100644
--- a/gcc/configure.ac
+++ b/gcc/configure.ac
@@ -503,6 +503,21 @@ fi
 AC_SUBST(warn_cflags)
 AC_SUBST(warn_cxxflags)
 
+# Check whether -Wimplicit-fallthrough works.
+W_NO_IMPLICIT_FALLTHROUGH=
+AC_CACHE_CHECK([for -Wimplicit-fallthrough option],
+  [gcc_cv_implicit_fallthrough],
+  [saved_CXXFLAGS="$CXXFLAGS"
+   CXXFLAGS="$CXXFLAGS -Wimplicit-fallthrough"
+   AC_COMPILE_IFELSE([int main(void) {return 0;}],
+     [gcc_cv_implicit_fallthrough=yes],
+     [gcc_cv_implicit_fallthrough=no])
+   CXXFLAGS="$saved_CXXFLAGS"])
+if test "$gcc_cv_implicit_fallthrough" = "yes"; then
+  W_NO_IMPLICIT_FALLTHROUGH="-Wno-implicit-fallthrough"
+fi
+AC_SUBST([W_NO_IMPLICIT_FALLTHROUGH])
+
 # Disable exceptions and RTTI if building with g++
 ACX_PROG_CC_WARNING_OPTS(
        m4_quote(m4_do([-fno-exceptions -fno-rtti 
-fasynchronous-unwind-tables])),

        Marek

Reply via email to