Skip to content

Commit 6aaded5

Browse files
bbolligitster
authored andcommitted
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]: git-for-windows#1735 [1]: https://groups.google.com/forum/#!topic/comp.lang.c.moderated/bmiF2xMz51U Fixes git-for-windows#1735 Reported-By: Karen Huang (via GitHub) Signed-off-by: Beat Bolli <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63e2a0f commit 6aaded5

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

builtin/config.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ static int show_origin;
6767
{ OPTION_CALLBACK, (s), (l), (v), NULL, (h), PARSE_OPT_NOARG | \
6868
PARSE_OPT_NONEG, option_parse_type, (i) }
6969

70-
static struct option builtin_config_options[];
70+
static NORETURN void usage_builtin_config(void);
7171

7272
static int option_parse_type(const struct option *opt, const char *arg,
7373
int unset)
@@ -111,8 +111,7 @@ static int option_parse_type(const struct option *opt, const char *arg,
111111
* --type=int'.
112112
*/
113113
error("only one type at a time.");
114-
usage_with_options(builtin_config_usage,
115-
builtin_config_options);
114+
usage_builtin_config();
116115
}
117116
*to_type = new_type;
118117

@@ -157,11 +156,16 @@ static struct option builtin_config_options[] = {
157156
OPT_END(),
158157
};
159158

159+
static NORETURN void usage_builtin_config(void)
160+
{
161+
usage_with_options(builtin_config_usage, builtin_config_options);
162+
}
163+
160164
static void check_argc(int argc, int min, int max) {
161165
if (argc >= min && argc <= max)
162166
return;
163167
error("wrong number of arguments");
164-
usage_with_options(builtin_config_usage, builtin_config_options);
168+
usage_builtin_config();
165169
}
166170

167171
static void show_config_origin(struct strbuf *buf)
@@ -596,7 +600,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
596600
if (use_global_config + use_system_config + use_local_config +
597601
!!given_config_source.file + !!given_config_source.blob > 1) {
598602
error("only one config file at a time.");
599-
usage_with_options(builtin_config_usage, builtin_config_options);
603+
usage_builtin_config();
600604
}
601605

602606
if (use_local_config && nongit)
@@ -657,38 +661,37 @@ int cmd_config(int argc, const char **argv, const char *prefix)
657661

658662
if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) {
659663
error("--get-color and variable type are incoherent");
660-
usage_with_options(builtin_config_usage, builtin_config_options);
664+
usage_builtin_config();
661665
}
662666

663667
if (HAS_MULTI_BITS(actions)) {
664668
error("only one action at a time.");
665-
usage_with_options(builtin_config_usage, builtin_config_options);
669+
usage_builtin_config();
666670
}
667671
if (actions == 0)
668672
switch (argc) {
669673
case 1: actions = ACTION_GET; break;
670674
case 2: actions = ACTION_SET; break;
671675
case 3: actions = ACTION_SET_ALL; break;
672676
default:
673-
usage_with_options(builtin_config_usage, builtin_config_options);
677+
usage_builtin_config();
674678
}
675679
if (omit_values &&
676680
!(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) {
677681
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();
679683
}
680684

681685
if (show_origin && !(actions &
682686
(ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) {
683687
error("--show-origin is only applicable to --get, --get-all, "
684688
"--get-regexp, and --list.");
685-
usage_with_options(builtin_config_usage, builtin_config_options);
689+
usage_builtin_config();
686690
}
687691

688692
if (default_value && !(actions & ACTION_GET)) {
689693
error("--default is only applicable to --get");
690-
usage_with_options(builtin_config_usage,
691-
builtin_config_options);
694+
usage_builtin_config();
692695
}
693696

694697
if (actions & PAGING_ACTIONS)

0 commit comments

Comments
 (0)