diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index 3ceccd983f..9adc1f14c3 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -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) diff --git a/meson.build b/meson.build index a5ea1d10fd..68a0c92f69 100644 --- a/meson.build +++ b/meson.build @@ -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')