All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 01/13] doc/coding-style: Update 'enum as switch variable' section
@ 2014-12-02 17:28 Szymon Janc
  2014-12-02 17:28 ` [PATCH 02/13] profiles: List all enum values in switch Szymon Janc
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: Szymon Janc @ 2014-12-02 17:28 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc

Since GCC has option (-Wswitch-enum) that ensure all enum values are
handled inside switch it is no longer necessary to forbit default in
such case.
---
 doc/coding-style.txt | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/doc/coding-style.txt b/doc/coding-style.txt
index 59df64a..b3fbd2e 100644
--- a/doc/coding-style.txt
+++ b/doc/coding-style.txt
@@ -175,10 +175,11 @@ enum animal_type {
 M10: Enum as switch variable
 ============================
 
-If the variable of a switch is an enum, you must not include a default in
-switch body. The reason for this is: If later on you modify the enum by adding
-a new type, and forget to change the switch accordingly, the compiler will
-complain the new added type hasn't been handled.
+If the variable of a switch is an enum, you must include all values in
+switch body even if providing default. This is enforced by compiler option
+enabling extra warning in such case. The reason for this is to ensure that if
+later on enum is modified and one forget to change the switch accordingly, the
+compiler will complain the new added type hasn't been handled.
 
 Example:
 
@@ -190,7 +191,7 @@ enum animal_type {
 
 enum animal_type t;
 
-switch (t) {
+switch (t) { // OK
 case ANIMAL_TYPE_FOUR_LEGS:
 	...
 	break;
@@ -200,7 +201,18 @@ case ANIMAL_TYPE_EIGHT_LEGS:
 case ANIMAL_TYPE_TWO_LEGS:
 	...
 	break;
-default:  // wrong
+default:
+	break;
+}
+
+switch (t) { // Wrong
+case ANIMAL_TYPE_FOUR_LEGS:
+	...
+	break;
+case ANIMAL_TYPE_TWO_LEGS:
+	...
+	break;
+default:
 	break;
 }
 
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2014-12-08 13:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-02 17:28 [PATCH 01/13] doc/coding-style: Update 'enum as switch variable' section Szymon Janc
2014-12-02 17:28 ` [PATCH 02/13] profiles: List all enum values in switch Szymon Janc
2014-12-02 17:28 ` [PATCH 03/13] lib: " Szymon Janc
2014-12-02 17:28 ` [PATCH 04/13] btio: " Szymon Janc
2014-12-02 17:28 ` [PATCH 05/13] attrib: " Szymon Janc
2014-12-02 17:28 ` [PATCH 06/13] core: " Szymon Janc
2014-12-02 17:28 ` [PATCH 07/13] gobex: " Szymon Janc
2014-12-02 17:28 ` [PATCH 08/13] obexd: " Szymon Janc
2014-12-02 17:28 ` [PATCH 09/13] shared: " Szymon Janc
2014-12-02 17:28 ` [PATCH 10/13] android: " Szymon Janc
2014-12-02 17:28 ` [PATCH 11/13] unit: " Szymon Janc
2014-12-02 17:28 ` [PATCH 12/13] tools: " Szymon Janc
2014-12-02 17:28 ` [PATCH 13/13] build: Enable -Wswitch-enum in maintainer mode Szymon Janc
2014-12-08 13:25 ` [PATCH 01/13] doc/coding-style: Update 'enum as switch variable' section Szymon Janc

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.