>From b1e2512f1ad88d88e1654cb0d78860f32bc76549 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Tue, 26 Apr 2011 10:30:05 +0100 Subject: [PATCH] maint: enable -Wmissing-field-initializers * configure.ac: Enable -Wmissing-field-initializers for src/ but leave disabled for lib/. * src/system.h: Enable the static variable hack only for non gcc compilers and versions of gcc older than 4.7. Starting with that version, the warning is no longer issued for variables initialized with a single zero value. Rename DECLARE_ZEROED_AGGREGATE to the more concise and accurate DECLARE_ZEROED_AUTO. * src/ls.c: Use the renamed macro. * src/pathchk.c: Likewise. * src/shred.c: Likewise. * src/stty.c: Likewise. * src/wc.c: Likewise. --- configure.ac | 6 +++++- src/ls.c | 2 +- src/pathchk.c | 2 +- src/shred.c | 2 +- src/stty.c | 4 ++-- src/system.h | 9 +++++---- src/wc.c | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index 6407bea..41d0442 100644 --- a/configure.ac +++ b/configure.ac @@ -96,7 +96,6 @@ if test "$gl_gcc_warnings" = yes; then for w in $ws; do gl_WARN_ADD([$w]) done - gl_WARN_ADD([-Wno-missing-field-initializers]) # We need this one gl_WARN_ADD([-Wno-sign-compare]) # Too many warnings for now gl_WARN_ADD([-Wno-unused-parameter]) # Too many warnings for now @@ -122,6 +121,11 @@ if test "$gl_gcc_warnings" = yes; then nw="$nw -Wmissing-prototypes" nw="$nw -Wold-style-definition" gl_MANYWARN_COMPLEMENT([GNULIB_WARN_CFLAGS], [$WARN_CFLAGS], [$nw]) + + # Disable this warning too, as gnulib + # doesn't use DECLARE_ZEROED_AUTO from system.h + gl_WARN_ADD([-Wno-missing-field-initializers], [GNULIB_WARN_CFLAGS]) + AC_SUBST([GNULIB_WARN_CFLAGS]) # For gnulib-tests, the set is slightly smaller still. diff --git a/src/ls.c b/src/ls.c index a7ea8c2..49192d1 100644 --- a/src/ls.c +++ b/src/ls.c @@ -3891,7 +3891,7 @@ quote_name (FILE *out, const char *name, struct quoting_options const *options, reach its end, replacing each non-printable multibyte character with a single question mark. */ { - DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate); + DECLARE_ZEROED_AUTO (mbstate_t, mbstate); do { wchar_t wc; diff --git a/src/pathchk.c b/src/pathchk.c index f0f99dd..c721058 100644 --- a/src/pathchk.c +++ b/src/pathchk.c @@ -196,7 +196,7 @@ portable_chars_only (char const *file, size_t filelen) if (*invalid) { - DECLARE_ZEROED_AGGREGATE (mbstate_t, mbstate); + DECLARE_ZEROED_AUTO (mbstate_t, mbstate); size_t charlen = mbrlen (invalid, filelen - validlen, &mbstate); error (0, 0, _("nonportable character %s in file name %s"), diff --git a/src/shred.c b/src/shred.c index 10425a3..5906cdb 100644 --- a/src/shred.c +++ b/src/shred.c @@ -1098,7 +1098,7 @@ int main (int argc, char **argv) { bool ok = true; - DECLARE_ZEROED_AGGREGATE (struct Options, flags); + DECLARE_ZEROED_AUTO (struct Options, flags); char **file; int n_files; int c; diff --git a/src/stty.c b/src/stty.c index 674a19a..9080114 100644 --- a/src/stty.c +++ b/src/stty.c @@ -730,7 +730,7 @@ main (int argc, char **argv) { /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure. */ - DECLARE_ZEROED_AGGREGATE (struct termios, mode); + DECLARE_ZEROED_AUTO (struct termios, mode); enum output_type output_type; int optc; @@ -1003,7 +1003,7 @@ main (int argc, char **argv) { /* Initialize to all zeroes so there is no risk memcmp will report a spurious difference in an uninitialized portion of the structure. */ - DECLARE_ZEROED_AGGREGATE (struct termios, new_mode); + DECLARE_ZEROED_AUTO (struct termios, new_mode); if (tcsetattr (STDIN_FILENO, TCSADRAIN, &mode)) error (EXIT_FAILURE, errno, "%s", device_name); diff --git a/src/system.h b/src/system.h index 1c351bd..65890ac 100644 --- a/src/system.h +++ b/src/system.h @@ -469,14 +469,15 @@ enum /* With -Dlint, avoid warnings from gcc about code like mbstate_t m = {0,}; by wasting space on a static variable of the same type, that is thus - guaranteed to be initialized to 0, and use that on the RHS. */ + guaranteed to be initialized to 0, and use that on the RHS. + This issue was fixed in gcc 4.7. */ #define DZA_CONCAT0(x,y) x ## y #define DZA_CONCAT(x,y) DZA_CONCAT0 (x, y) -#ifdef lint -# define DECLARE_ZEROED_AGGREGATE(Type, Var) \ +#if defined lint && (__GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)) +# define DECLARE_ZEROED_AUTO(Type, Var) \ static Type DZA_CONCAT (s0_, __LINE__); Type Var = DZA_CONCAT (s0_, __LINE__) #else -# define DECLARE_ZEROED_AGGREGATE(Type, Var) \ +# define DECLARE_ZEROED_AUTO(Type, Var) \ Type Var = { 0, } #endif diff --git a/src/wc.c b/src/wc.c index 0399214..5f9c7e5 100644 --- a/src/wc.c +++ b/src/wc.c @@ -285,7 +285,7 @@ wc (int fd, char const *file_x, struct fstatus *fstatus) { bool in_word = false; uintmax_t linepos = 0; - DECLARE_ZEROED_AGGREGATE (mbstate_t, state); + DECLARE_ZEROED_AUTO (mbstate_t, state); bool in_shift = false; # if SUPPORT_OLD_MBRTOWC /* Back-up the state before each multibyte character conversion and -- 1.7.4