{"thread":{"id":"44447","subject":"[PATCH] sequencer: shut up clang warning","startedAt":"2016-11-09T13:57:02Z","lastAt":"2016-11-09T22:28:34Z","messageCount":3,"participants":["Johannes Schindelin","Jeff King","Jakub Narębski"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"305632","messageId":"efbba4b32515fed7096c1c81dbe97eedd44083b0.1478699713.git.johannes.schindelin@gmx.de","threadId":"44447","inReplyTo":null,"subject":"[PATCH] sequencer: shut up clang warning","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2016-11-09T13:56:25Z","receivedAt":"2016-11-09T13:57:02Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"When comparing a value of type `enum todo_command` with a value that is\noutside the defined enum constants, clang greets the developer with this\nwarning:\n\n\tcomparison of constant 2 with expression of type\n\t'const enum todo_command' is always true\n\nWhile this is arguably true *iff* the value was never cast from a\nfree-form int, we should keep the cautious code in place.\n\nTo shut up clang, we simply introduce an otherwise pointless enum constant\nand compare against that.\n\nNoticed by Torsten Bögershausen.\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n---\nPublished-As: https://github.com/dscho/git/releases/tag/enum-warning-v1\nFetch-It-Via: git fetch https://github.com/dscho/git enum-warning-v1\n\n\tPeff, if you would like me to include more of your commit message,\n\tplease let me know.\n\n\tI will adjust the sequencer-i patches to keep the TODO_INVALID\n\tconstant.\n\n sequencer.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex 5fd75f3..f80e9c0 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -619,7 +619,8 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)\n \n enum todo_command {\n \tTODO_PICK = 0,\n-\tTODO_REVERT\n+\tTODO_REVERT,\n+\tTODO_INVALID\n };\n \n static const char *todo_command_strings[] = {\n@@ -629,7 +630,7 @@ static const char *todo_command_strings[] = {\n \n static const char *command_to_string(const enum todo_command command)\n {\n-\tif (command < ARRAY_SIZE(todo_command_strings))\n+\tif (command < TODO_INVALID)\n \t\treturn todo_command_strings[command];\n \tdie(\"Unknown command: %d\", command);\n }\n\nbase-commit: be5a750939c212bc0781ffa04fabcfd2b2bd744e\n-- \n2.10.1.583.g721a9e0"},{"id":"305636","messageId":"20161109153733.iauja57zikyb2awv@sigill.intra.peff.net","threadId":"44447","inReplyTo":"efbba4b32515fed7096c1c81dbe97eedd44083b0.1478699713.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] sequencer: shut up clang warning","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2016-11-09T15:37:33Z","receivedAt":"2016-11-09T15:37:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Nov 09, 2016 at 02:56:25PM +0100, Johannes Schindelin wrote:\n\n> When comparing a value of type `enum todo_command` with a value that is\n> outside the defined enum constants, clang greets the developer with this\n> warning:\n> \n> \tcomparison of constant 2 with expression of type\n> \t'const enum todo_command' is always true\n> \n> While this is arguably true *iff* the value was never cast from a\n> free-form int, we should keep the cautious code in place.\n> \n> To shut up clang, we simply introduce an otherwise pointless enum constant\n> and compare against that.\n\nThis does silence the warning.\n\nI slightly prefer mine because:\n\n  1. It does not carry an implicit requirement that TODO_INVALID remain\n     the final enum value.\n\n  2. It also protects the range check against a negative enum value.\n\nBut this is code that is getting changed later by you anyway, and I do\nnot care that strongly.\n\n-Peff\n"},{"id":"305649","messageId":"11e953de-956d-d4eb-8117-ebbfc410676b@gmail.com","threadId":"44447","inReplyTo":"efbba4b32515fed7096c1c81dbe97eedd44083b0.1478699713.git.johannes.schindelin@gmx.de","subject":"Re: [PATCH] sequencer: shut up clang warning","fromName":"Jakub Narębski","fromEmail":"jnareb@gmail.com","sentAt":"2016-11-09T22:28:24Z","receivedAt":"2016-11-09T22:28:34Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"W dniu 09.11.2016 o 14:56, Johannes Schindelin pisze:\n\n> When comparing a value of type `enum todo_command` with a value that is\n> outside the defined enum constants, clang greets the developer with this\n> warning:\n> \n> \tcomparison of constant 2 with expression of type\n> \t'const enum todo_command' is always true\n> \n> While this is arguably true *iff* the value was never cast from a\n> free-form int, we should keep the cautious code in place.\n> \n> To shut up clang, we simply introduce an otherwise pointless enum constant\n> and compare against that.\n> \n> Noticed by Torsten Bögershausen.\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> ---\n\n>  sequencer.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/sequencer.c b/sequencer.c\n> index 5fd75f3..f80e9c0 100644\n> --- a/sequencer.c\n> +++ b/sequencer.c\n> @@ -619,7 +619,8 @@ static int allow_empty(struct replay_opts *opts, struct commit *commit)\n>  \n>  enum todo_command {\n>  \tTODO_PICK = 0,\n> -\tTODO_REVERT\n> +\tTODO_REVERT,\n> +\tTODO_INVALID\n>  };\n\nWhy not name it TODO_N, or N_TODO, or something like that?\n\n-- \nJakub Narębski\n\n"}]}