git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sequencer: shut up clang warning

From
Jakub Narębski <jnareb@gmail.com>
Date
Nov 9, 2016, 22:28 UTC
Message-ID
<11e953de-956d-d4eb-8117-ebbfc410676b@gmail.com>
In-Reply-To
<efbba4b32515fed7096c1c81dbe97eedd44083b0.1478699713.git.johannes.schindelin@gmx.de>
W dniu 09.11.2016 o 14:56, Johannes Schindelin pisze:
Show 17 quoted lines
> When comparing a value of type `enum todo_command` with a value that is
> outside the defined enum constants, clang greets the developer with this
> warning:
> 
> 	comparison of constant 2 with expression of type
> 	'const enum todo_command' is always true
> 
> While this is arguably true *iff* the value was never cast from a
> free-form int, we should keep the cautious code in place.
> 
> To shut up clang, we simply introduce an otherwise pointless enum constant
> and compare against that.
> 
> Noticed by Torsten Bögershausen.
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
Show 15 quoted lines
>  sequencer.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/sequencer.c b/sequencer.c
> index 5fd75f3..f80e9c0 100644
> --- a/sequencer.c
> +++ b/sequencer.c
> @@ -619,7 +619,8 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)
>  
>  enum todo_command {
>  	TODO_PICK = 0,
> -	TODO_REVERT
> +	TODO_REVERT,
> +	TODO_INVALID
>  };
Why not name it TODO_N, or N_TODO, or something like that?
-- 
Jakub Narębski
Previous: Jeff King
Message 3 of 3 in “sequencer: shut up clang warning”
  1. sequencer: shut up clang warningJohannes Schindelin, Nov 9, 2016
  2. Jeff KingNov 9, 2016
  3. Jakub NarębskiNov 9, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.