Re: [PATCH] sequencer: shut up clang warning
- From
Jeff King <peff@peff.net>
- Date
- Nov 9, 2016, 15:37 UTC
- Message-ID
- <20161109153733.iauja57zikyb2awv@sigill.intra.peff.net>
- In-Reply-To
- <efbba4b32515fed7096c1c81dbe97eedd44083b0.1478699713.git.johannes.schindelin@gmx.de>
On Wed, Nov 09, 2016 at 02:56:25PM +0100, Johannes Schindelin wrote:
Show 12 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.
This does silence the warning.
I slightly prefer mine because:
1. It does not carry an implicit requirement that TODO_INVALID remain
the final enum value.2. It also protects the range check against a negative enum value.
But this is code that is getting changed later by you anyway, and I do not care that strongly.
-Peff