From a35ce03b4c5d98eca1dc97a7380cc7d8d7c1d03a Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 6 Apr 2020 06:49:45 -0700 Subject: warning cleanup: GNU C++ initializer warnings. This is the eight and final round of an effort to enable GCC's -Wextra option. The C++ compiler, with -Wextra, doesn't like C's universal struct initializer { 0 }, individually complaining about all the remaining members not being initialized. What works in C++ is the { } initializer. Conditional definition to the rescue. * lib.h (all_zero_init): New macro which expands to { } under C++, and { 0 } under C. * lib.c (make_time_impl, epoch_tm, time_string_meth, time_parse_meth): Use all_zero_init. * parser.c (prime_parser): Likewise. * socket.c (sock_mark_connected): Likewise. * sysif.c (fcntl_wrap): Likewise. * termios.c (encode_speeds, decode_speeds): Likewise. * configure (diag_flags): Add -Wextra. --- configure | 2 +- lib.c | 8 ++++---- lib.h | 6 ++++++ parser.c | 2 +- socket.c | 2 +- sysif.c | 2 +- termios.c | 4 ++-- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/configure b/configure index 250cb772..a2000b51 100755 --- a/configure +++ b/configure @@ -134,7 +134,7 @@ yacc_is_newer_bison= nm='$(cross)$(tool_prefix)nm' opt_flags='-O2 -fno-stack-protector' lang_flags='-ansi -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200112 -D_GNU_SOURCE' -diag_flags='-Wall -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=strict-prototypes' +diag_flags='-Wall -Wextra -Werror=implicit-function-declaration -Werror=missing-prototypes -Werror=strict-prototypes' debug_flags=-g debug_only_flags=-DTXR_DEBUG debug_also= diff --git a/lib.c b/lib.c index 6fae0008..871c1131 100644 --- a/lib.c +++ b/lib.c @@ -12437,7 +12437,7 @@ static val make_time_impl(time_t (*pmktime)(struct tm *), val hour, val minute, val second, val isdst) { - struct tm local = { 0 }; + struct tm local = all_zero_init; time_t time; time_fields_to_tm(&local, year, month, day, @@ -12458,7 +12458,7 @@ val make_time(val year, val month, val day, static struct tm epoch_tm(void) { - struct tm ep = { 0 }; + struct tm ep = all_zero_init; ep.tm_year = 70; ep.tm_mday = 1; return ep; @@ -12560,7 +12560,7 @@ static val time_meth(val utc_p, val time_struct) static val time_string_meth(val time_struct, val format) { - struct tm tms = { 0 }; + struct tm tms = all_zero_init; time_struct_to_tm(&tms, time_struct, t); char buffer[512] = ""; char *fmt = utf8_dup_to(c_str(format)); @@ -12577,7 +12577,7 @@ static val time_string_meth(val time_struct, val format) static val time_parse_meth(val time_struct, val format, val string) { - struct tm tms = { 0 }; + struct tm tms = all_zero_init; time_struct_to_tm(&tms, time_struct, nil); val ret = nil; diff --git a/lib.h b/lib.h index b4e2554f..f039568f 100644 --- a/lib.h +++ b/lib.h @@ -1298,3 +1298,9 @@ loc list_collect_revappend(loc ptail, val obj); #define static_forward(decl) static decl #define static_def(def) static def #endif + +#ifdef __cplusplus +#define all_zero_init { } +#else +#define all_zero_init { 0 } +#endif diff --git a/parser.c b/parser.c index c6699988..992e9719 100644 --- a/parser.c +++ b/parser.c @@ -206,7 +206,7 @@ val parser_set_lineno(val self, val stream, val lineno) void prime_parser(parser_t *p, val name, enum prime_parser prim) { - struct yy_token sec_tok = { 0 }; + struct yy_token sec_tok = all_zero_init; switch (prim) { case prime_lisp: diff --git a/socket.c b/socket.c index 25477de4..35ef7220 100644 --- a/socket.c +++ b/socket.c @@ -819,7 +819,7 @@ static val sock_mark_connected(val sock) if (sfd) { val family = sock_family(sock); - struct sockaddr_storage sa = { 0 }; + struct sockaddr_storage sa = all_zero_init; socklen_t salen = sizeof sa; (void) getpeername(c_num(sfd), coerce(struct sockaddr *, &sa), &salen); diff --git a/sysif.c b/sysif.c index a3b3ff91..6b646d9c 100644 --- a/sysif.c +++ b/sysif.c @@ -889,7 +889,7 @@ static val fcntl_wrap(val fd_in, val cmd_in, val arg_in) if (missingp(arg_in)) { errno = EINVAL; } else { - struct flock fl = { 0 }; + struct flock fl = all_zero_init; flock_pack(self, arg_in, &fl); res = fcntl(fd, cmd, &fl); if (cmd == F_GETLK) diff --git a/termios.c b/termios.c index 6179f2b5..5d7b26b0 100644 --- a/termios.c +++ b/termios.c @@ -337,7 +337,7 @@ static val tcflow_wrap(val action, val stream) static val encode_speeds(val termios) { - struct termios tio = { 0 }; + struct termios tio = all_zero_init; tio.c_iflag = c_num(slot(termios, iflag_s)); tio.c_cflag = c_num(slot(termios, cflag_s)); @@ -351,7 +351,7 @@ static val encode_speeds(val termios) static val decode_speeds(val termios) { - struct termios tio = { 0 }; + struct termios tio = all_zero_init; tio.c_cflag = c_num(slot(termios, cflag_s)); tio.c_iflag = c_num(slot(termios, iflag_s)); -- cgit v1.2.3