build: disable -Wimplicit-fallthrough warning with clang

Seems clang 10 got support for -Wimplicit-fallthrough, but does
not honor the code comments to suppress the warning. What a
disaster.

Try to detect it.

See-also: https://github.com/ClangBuiltLinux/linux/issues/   #636
See-also: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e2079e93f562c7f7a030eb7642017ee5eabaaa10
This commit is contained in:
Thomas Haller 2020-02-21 13:22:23 +01:00
parent ffa098edae
commit 86dfc4b099
2 changed files with 42 additions and 2 deletions

View file

@ -70,7 +70,6 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
-Wfloat-equal \
-Wformat-nonliteral \
-Wformat-security \
-Wimplicit-fallthrough \
-Wimplicit-function-declaration \
-Winit-self \
-Wlogical-op \
@ -137,6 +136,26 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
[G_DEFINE_TYPE (NMObject, nm_object, G_TYPE_OBJECT)]
)
dnl clang started supporting -Wimplicit-fallthrough, but it does not
dnl honor the code comments to suppress the warning. Disable the
dnl warning with clang.
dnl
NM_COMPILER_WARNING([$1], [implicit-fallthrough],
[int foo(int a);
int foo(int a) {
int r = 0;
switch (a) {
case 1:
r++;
/* fall-through */
case 2:
r++;
break;
}
return r;
}]
)
eval "AS_TR_SH([$1])='$CFLAGS_MORE_WARNINGS $$1'"
else
AC_MSG_RESULT(no)

View file

@ -179,7 +179,6 @@ if nm_debug
'-Wfloat-equal',
'-Wformat-nonliteral',
'-Wformat-security',
'-Wimplicit-fallthrough',
'-Wimplicit-function-declaration',
'-Winit-self',
'-Wlogical-op',
@ -211,6 +210,28 @@ if nm_debug
'-Wunknown-attributes',
'-fno-strict-aliasing',
])
if cc.has_argument('-Wimplicit-fallthrough')
if cc.compiles('''
int main(int argc, char **argv) {
int r = 0;
switch (argc) {
case 0:
r++;
/* fall-through */
case 1:
r++;
break;
}
return r;
}
''',
args: '-Werror=implicit-fallthrough',
name: '-Werror=implicit-fallthrough')
common_flags += '-Wimplicit-fallthrough'
endif
endif
endif
add_project_arguments(common_flags, language: 'c')