builtin/config: work around an unsized array forward declaration

As reported here[0], Microsoft Visual Studio 2017.2 and "gcc -pedantic" don't understand the forward declaration of an unsized static array. They insist on an array size: d:\git\src\builtin\config.c(70,46): error C2133: 'builtin_config_options': unknown size The thread [1] explains that this is due to the single-pass nature of old compilers. To work around this error, introduce the forward-declared function usage_builtin_config() instead that uses the array builtin_config_options only after it has been defined. Also use this function in all other places where usage_with_options() is called with the same arguments. [0]: https://github.com/git-for-windows/git/issues/1735 [1]: https://groups.google.com/forum/#!topic/comp.lang.c.moderated/bmiF2xMz51U Fixes https://github.com/git-for-windows/git/issues/1735 Reported-By: Karen Huang (via GitHub) Signed-off-by: Beat Bolli <dev+git@drbeat.li> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Beat Bolli committed Jul 5, 2018 at 20:34 UTC 6aaded550915eab144bbe42af9b91de703ba39e0
1 file changed +15 -12
builtin/config.c
+15 -12
@@ -67,7 +67,7 @@ static int show_origin;
67 { OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
68 PARSE_OPT_NONEG, option_parse_type, (i) }
69
70 -static struct option builtin_config_options[];
70 +static NORETURN void usage_builtin_config(void);
71
72 static int option_parse_type(const struct option *opt, const char *arg,
73 int unset)
@@ -111,8 +111,7 @@ static int option_parse_type(const struct option *opt, const char *arg,
111 * --type=int'.
112 */
113 error("only one type at a time.");
114 - usage_with_options(builtin_config_usage,
115 - builtin_config_options);
114 + usage_builtin_config();
115 }
116 *to_type = new_type;
117
@@ -157,11 +156,16 @@ static struct option builtin_config_options[] = {
156 OPT_END(),
157 };
158
159 +static NORETURN void usage_builtin_config(void)
160 +{
161 + usage_with_options(builtin_config_usage, builtin_config_options);
162 +}
163 +
164 static void check_argc(int argc, int min, int max) {
165 if (argc >= min && argc <= max)
166 return;
167 error("wrong number of arguments");
164 - usage_with_options(builtin_config_usage, builtin_config_options);
168 + usage_builtin_config();
169 }
170
171 static void show_config_origin(struct strbuf *buf)
@@ -596,7 +600,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
600 if (use_global_config + use_system_config + use_local_config +
601 !!given_config_source.file + !!given_config_source.blob > 1) {
602 error("only one config file at a time.");
599 - usage_with_options(builtin_config_usage, builtin_config_options);
603 + usage_builtin_config();
604 }
605
606 if (use_local_config && nongit)
@@ -657,12 +661,12 @@ int cmd_config(int argc, const char **argv, const char *prefix)
661
662 if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) {
663 error("--get-color and variable type are incoherent");
660 - usage_with_options(builtin_config_usage, builtin_config_options);
664 + usage_builtin_config();
665 }
666
667 if (HAS_MULTI_BITS(actions)) {
668 error("only one action at a time.");
665 - usage_with_options(builtin_config_usage, builtin_config_options);
669 + usage_builtin_config();
670 }
671 if (actions == 0)
672 switch (argc) {
@@ -670,25 +674,24 @@ int cmd_config(int argc, const char **argv, const char *prefix)
674 case 2: actions = ACTION_SET; break;
675 case 3: actions = ACTION_SET_ALL; break;
676 default:
673 - usage_with_options(builtin_config_usage, builtin_config_options);
677 + usage_builtin_config();
678 }
679 if (omit_values &&
680 !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) {
681 error("--name-only is only applicable to --list or --get-regexp");
678 - usage_with_options(builtin_config_usage, builtin_config_options);
682 + usage_builtin_config();
683 }
684
685 if (show_origin && !(actions &
686 (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) {
687 error("--show-origin is only applicable to --get, --get-all, "
688 "--get-regexp, and --list.");
685 - usage_with_options(builtin_config_usage, builtin_config_options);
689 + usage_builtin_config();
690 }
691
692 if (default_value && !(actions & ACTION_GET)) {
693 error("--default is only applicable to --get");
690 - usage_with_options(builtin_config_usage,
691 - builtin_config_options);
694 + usage_builtin_config();
695 }
696
697 if (actions & PAGING_ACTIONS)