]> git.ipfire.org Git - thirdparty/elfutils.git/commitdiff
build: Check for -Wimplicit-fallthrough=5 separately
authorTimm Bäder <tbaeder@redhat.com>
Wed, 17 Feb 2021 09:27:06 +0000 (10:27 +0100)
committerMark Wielaard <mark@klomp.org>
Mon, 1 Mar 2021 22:46:20 +0000 (23:46 +0100)
GCC accepts the =5, which means it doesn't try to parse any comments
and only accepts the fallthrough attribute in code. Clang does not ever
parse any comments and always wants the fallthrough attribute anyway.
Clang also doesn't accept the =n parameter for -Wimplicit-fallthrough.

Test for =5 separately and use it if supported and fall back to just
-Wimplicit-fallthrough otherwise.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
config/eu.am
configure.ac

index 6c3c444f143abc3f0e512d7ac818302ce1cd2d47..e109ffd3b4554147d651b57583084332c1837db8 100644 (file)
@@ -64,8 +64,12 @@ endif
 if HAVE_IMPLICIT_FALLTHROUGH_WARNING
 # Use strict fallthrough. Only __attribute__((fallthrough)) will prevent the
 # warning
+if HAVE_IMPLICIT_FALLTHROUGH_5_WARNING
 IMPLICIT_FALLTHROUGH_WARNING=-Wimplicit-fallthrough=5
 else
+IMPLICIT_FALLTHROUGH_WARNING=-Wimplicit-fallthrough
+endif
+else
 IMPLICIT_FALLTHROUGH_WARNING=
 endif
 
index d345495dcb1579d36a5f8aaca6a0a54fa04d6eb8..e56aeb6a7d34585e9ba550aa4c2d8c0ef62b04b2 100644 (file)
@@ -519,6 +519,18 @@ CFLAGS="$old_CFLAGS"])
 AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_WARNING,
               [test "x$ac_cv_implicit_fallthrough" != "xno"])
 
+# Check whether the compiler additionally accepts -Wimplicit-fallthrough=5
+# GCC accepts this and 5 means "don't parse any fallthrough comments and
+# only accept the fallthrough attribute"
+AC_CACHE_CHECK([whether the compiler accepts -Wimplicit-fallthrough=5], ac_cv_implicit_fallthrough_5, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Wimplicit-fallthrough=5 -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([])],
+                 ac_cv_implicit_fallthrough_5=yes, ac_cv_implicit_fallthrough_5=no)
+CFLAGS="$old_CFLAGS"])
+AM_CONDITIONAL(HAVE_IMPLICIT_FALLTHROUGH_5_WARNING,
+              [test "x$ac_cv_implicit_fallthrough_5" != "xno"])
+
 # Assume the fallthrough attribute is supported if -Wimplict-fallthrough is supported
 if test "$ac_cv_implicit_fallthrough" = "yes"; then
        AC_DEFINE([HAVE_FALLTHROUGH], [1],