Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1571746 > unrolled thread

[PATCH] drbd: avoid clang warning about pointless switch statement

Started byArnd Bergmann <arnd@arndb.de>
First post2017-02-01 18:00 +0100
Last post2017-02-06 14:50 +0100
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] drbd: avoid clang warning about pointless switch statement Arnd Bergmann <arnd@arndb.de> - 2017-02-01 18:00 +0100
    Re: [PATCH] drbd: avoid clang warning about pointless switch  statement Lars Ellenberg <lars.ellenberg@linbit.com> - 2017-02-06 14:50 +0100

#1571746 — [PATCH] drbd: avoid clang warning about pointless switch statement

FromArnd Bergmann <arnd@arndb.de>
Date2017-02-01 18:00 +0100
Subject[PATCH] drbd: avoid clang warning about pointless switch statement
Message-ID<t66qe-8ov-25@gated-at.bofh.it>
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.

Fixes: ec2c35ac1ea2 ("drbd: prepare the transition from connector to genetlink")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/genl_magic_struct.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h
index 6270a56e5edc..c6fbafb834f1 100644
--- a/include/linux/genl_magic_struct.h
+++ b/include/linux/genl_magic_struct.h
@@ -190,6 +190,7 @@ static inline void ct_assert_unique_operations(void)
 {
 	switch (0) {
 #include GENL_MAGIC_INCLUDE_FILE
+	default:
 		;
 	}
 }
@@ -208,6 +209,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
 {
 	switch (0) {
 #include GENL_MAGIC_INCLUDE_FILE
+	default:
 		;
 	}
 }
@@ -218,6 +220,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void)	\
 {									\
 	switch (0) {							\
 		s_fields						\
+		default:						\
 			;						\
 	}								\
 }
-- 
2.9.0

[toc] | [next] | [standalone]


#1574759 — Re: [PATCH] drbd: avoid clang warning about pointless switch statement

FromLars Ellenberg <lars.ellenberg@linbit.com>
Date2017-02-06 14:50 +0100
SubjectRe: [PATCH] drbd: avoid clang warning about pointless switch statement
Message-ID<t7RQ8-5AW-67@gated-at.bofh.it>
In reply to#1571746
Ack.

Ok, not exactly "pintless", it's a valid compile time assert for uniq ids,
basically a BUILD_BUG_ON(duplicate-ids). But adding a default clause
there does not hurt.

Thanks,
    Lars


On Wed, Feb 01, 2017 at 05:55:02PM +0100, Arnd Bergmann wrote:
> 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.
> 
> Fixes: ec2c35ac1ea2 ("drbd: prepare the transition from connector to genetlink")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/genl_magic_struct.h | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/include/linux/genl_magic_struct.h b/include/linux/genl_magic_struct.h
> index 6270a56e5edc..c6fbafb834f1 100644
> --- a/include/linux/genl_magic_struct.h
> +++ b/include/linux/genl_magic_struct.h
> @@ -190,6 +190,7 @@ static inline void ct_assert_unique_operations(void)
>  {
>  	switch (0) {
>  #include GENL_MAGIC_INCLUDE_FILE
> +	default:
>  		;
>  	}
>  }
> @@ -208,6 +209,7 @@ static inline void ct_assert_unique_top_level_attributes(void)
>  {
>  	switch (0) {
>  #include GENL_MAGIC_INCLUDE_FILE
> +	default:
>  		;
>  	}
>  }
> @@ -218,6 +220,7 @@ static inline void ct_assert_unique_ ## s_name ## _attributes(void)	\
>  {									\
>  	switch (0) {							\
>  		s_fields						\
> +		default:						\
>  			;						\
>  	}								\
>  }
> -- 
> 2.9.0

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web