mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 19:18:00 +02:00
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:
parent
ffa098edae
commit
86dfc4b099
2 changed files with 42 additions and 2 deletions
|
|
@ -70,7 +70,6 @@ if test "$GCC" = "yes" -a "$set_more_warnings" != "no"; then
|
||||||
-Wfloat-equal \
|
-Wfloat-equal \
|
||||||
-Wformat-nonliteral \
|
-Wformat-nonliteral \
|
||||||
-Wformat-security \
|
-Wformat-security \
|
||||||
-Wimplicit-fallthrough \
|
|
||||||
-Wimplicit-function-declaration \
|
-Wimplicit-function-declaration \
|
||||||
-Winit-self \
|
-Winit-self \
|
||||||
-Wlogical-op \
|
-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)]
|
[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'"
|
eval "AS_TR_SH([$1])='$CFLAGS_MORE_WARNINGS $$1'"
|
||||||
else
|
else
|
||||||
AC_MSG_RESULT(no)
|
AC_MSG_RESULT(no)
|
||||||
|
|
|
||||||
23
meson.build
23
meson.build
|
|
@ -179,7 +179,6 @@ if nm_debug
|
||||||
'-Wfloat-equal',
|
'-Wfloat-equal',
|
||||||
'-Wformat-nonliteral',
|
'-Wformat-nonliteral',
|
||||||
'-Wformat-security',
|
'-Wformat-security',
|
||||||
'-Wimplicit-fallthrough',
|
|
||||||
'-Wimplicit-function-declaration',
|
'-Wimplicit-function-declaration',
|
||||||
'-Winit-self',
|
'-Winit-self',
|
||||||
'-Wlogical-op',
|
'-Wlogical-op',
|
||||||
|
|
@ -211,6 +210,28 @@ if nm_debug
|
||||||
'-Wunknown-attributes',
|
'-Wunknown-attributes',
|
||||||
'-fno-strict-aliasing',
|
'-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
|
endif
|
||||||
|
|
||||||
add_project_arguments(common_flags, language: 'c')
|
add_project_arguments(common_flags, language: 'c')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue