All of lore.kernel.org
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 01/13] doc/coding-style: Update 'enum as switch variable' section
Date: Mon, 08 Dec 2014 14:25:43 +0100	[thread overview]
Message-ID: <3276600.cJOmr3QuCF@leonov> (raw)
In-Reply-To: <1417541318-24259-1-git-send-email-szymon.janc@tieto.com>

On Tuesday 02 of December 2014 18:28:26 Szymon Janc wrote:
> 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;
>  }

Pushed.

-- 
BR
Szymon Janc

      parent reply	other threads:[~2014-12-08 13:25 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` Szymon Janc [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3276600.cJOmr3QuCF@leonov \
    --to=szymon.janc@tieto.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.