Thread (1 message) 1 message, 1 author, 2021-09-29

Re: [PATCH 04/10] parse-options.c: use exhaustive "case" arms for "enum parse_opt_type"

From: Junio C Hamano <hidden>
Date: 2021-09-29 15:14:27

Ævar Arnfjörð Bjarmason [off-list ref] writes:
I think listing the remaining enum arms is a small price to pay for
having that all moved to compile-time.
I can sympathize with that point of view, since I used to think the
same way, but I am not yet convinced.  An example like this from
your postimage, which doubles the size of a switch statement with
empty case arms, demonstrates that it is not a "small" price.

Admittedly, the original switch statement is particularly bad,
though ;-)

 		switch (opts->type) {
 		case OPTION_STRING:
 		case OPTION_FILENAME:
 		case OPTION_INTEGER:
 		case OPTION_MAGNITUDE:
 		case OPTION_CALLBACK:
 		case OPTION_BIT:
 		case OPTION_NEGBIT:
 		case OPTION_COUNTUP:
 		case OPTION_SET_INT:
 			has_unset_form = 1;
 			break;
-		default:
+		/* special types */
+		case OPTION_END:
+		case OPTION_GROUP:
+		case OPTION_NUMBER:
+		case OPTION_ALIAS:
+		/* options with no arguments */
+		case OPTION_BITOP:
+		/* options with arguments (usually) */
+		case OPTION_LOWLEVEL_CALLBACK:
 			break;
 		}
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help