Message ID | 20181002171447.10765-1-natechancellor@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [RESEND] drbd: avoid clang warning about pointless switch statement | expand |
On Tue, Oct 02, 2018 at 10:14:48AM -0700, Nathan Chancellor wrote: > From: Arnd Bergmann <arnd@arndb.de> > > The drbd code causes warnings that we cannot easily disable when building with clang: > > In file included from drivers/block/drbd/drbd_debugfs.c:10: > In file included from drivers/block/drbd/drbd_int.h:48: > In file included from include/linux/drbd_genl_api.h:53: > In file included from include/linux/genl_magic_struct.h:237: > include/linux/drbd_genl.h:300:1: warning: no case matching constant switch condition '0' > > There is nothing wrong with the code, and adding 'default:' labels > in the right place is enough to let clang shut up about the warning. Actually, I think I'd prefer a "case 0:" instead of the "default:", because that would assert that we don't use a 0 for op or field numbers. As at least some people seem to care, I suggest we bundle up this and the other clang warning you just resent the patch for with whatever else we may come up with for the next merge window and send a pull request to Jens then. In case we forget, please send a friendly reminder. Thanks, Lars
On Thu, Oct 04, 2018 at 09:18:54PM +0200, Lars Ellenberg wrote: > On Tue, Oct 02, 2018 at 10:14:48AM -0700, Nathan Chancellor wrote: > > From: Arnd Bergmann <arnd@arndb.de> > > > > The drbd code causes warnings that we cannot easily disable when building with clang: > > > > In file included from drivers/block/drbd/drbd_debugfs.c:10: > > In file included from drivers/block/drbd/drbd_int.h:48: > > In file included from include/linux/drbd_genl_api.h:53: > > In file included from include/linux/genl_magic_struct.h:237: > > include/linux/drbd_genl.h:300:1: warning: no case matching constant switch condition '0' > > > > There is nothing wrong with the code, and adding 'default:' labels > > in the right place is enough to let clang shut up about the warning. > > Actually, I think I'd prefer a "case 0:" instead of the "default:", > because that would assert that we don't use a 0 for op or field numbers. > > As at least some people seem to care, I suggest we bundle up > this and the other clang warning you just resent the patch for > with whatever else we may come up with for the next merge window > and send a pull request to Jens then. > In case we forget, please send a friendly reminder. > > Thanks, > > Lars > Hi Lars, I will go ahead and test that change shortly and send it over for review. Thanks for the quick reply! Nathan
diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h index 5972e4969197..c11f42179c63 100644 --- a/include/linux/genl_magic_struct.h +++ b/include/linux/genl_magic_struct.h @@ -191,6 +191,7 @@ static inline void ct_assert_unique_operations(void) { switch (0) { #include GENL_MAGIC_INCLUDE_FILE + default: ; } } @@ -209,6 +210,7 @@ static inline void ct_assert_unique_top_level_attributes(void) { switch (0) { #include GENL_MAGIC_INCLUDE_FILE + default: ; } } @@ -219,6 +221,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void) \ { \ switch (0) { \ s_fields \ + default: \ ; \ } \ }