From 0b8875c183754435c0dbc625d2cecbb9814fbbe1 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sun, 24 Jun 2018 15:58:09 -0700 Subject: [PATCH] parse-datetime.y: avoid spurious GCC 9 warning * lib/parse-datetime.y (parse_datetime2): Save RELATIVE_TIME_0 into a function local prior to the first "goto fail". The prior use would evoke this: parse-datetime.y: In function 'parse_datetime2': parse-datetime.y:1791:19: error: jump skips variable initialization \ [-Werror=jump-misses-init] parse-datetime.y:2385:2: note: label 'fail' defined here parse-datetime.y:188:43: note: '({anonymous})' declared here parse-datetime.y:1841:12: note: in expansion of macro 'RELATIVE_TIME_0' --- ChangeLog | 11 +++++++++++ lib/parse-datetime.y | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 1a7110935c..ad10fbc35a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2018-06-24 Jim Meyering + parse-datetime.y: avoid spurious GCC 9 warning + * lib/parse-datetime.y (parse_datetime2): Save RELATIVE_TIME_0 into + a function local prior to the first "goto fail". The prior use would + evoke this: + parse-datetime.y: In function 'parse_datetime2': + parse-datetime.y:1791:19: error: jump skips variable initialization \ + [-Werror=jump-misses-init] + parse-datetime.y:2385:2: note: label 'fail' defined here + parse-datetime.y:188:43: note: '({anonymous})' declared here + parse-datetime.y:1841:12: note: in expansion of macro 'RELATIVE_TIME_0' + canon-host.c: avoid spurious GCC 9 warning * lib/canon-host.c: Suppress GCC9's -Wsuggest-attribute=malloc. diff --git a/lib/parse-datetime.y b/lib/parse-datetime.y index f14bb31dc5..3d8666a4df 100644 --- a/lib/parse-datetime.y +++ b/lib/parse-datetime.y @@ -1766,6 +1766,11 @@ parse_datetime2 (struct timespec *result, char const *p, timezone_t tz = tzdefault; + /* Store a local copy prior to first "goto". Without this, a prior use + below of RELATIVE_TIME_0 on the RHS might translate to an assignment- + to-temporary, which would trigger a -Wjump-misses-init warning. */ + static const relative_time rel_time_0 = RELATIVE_TIME_0; + if (strncmp (p, "TZ=\"", 4) == 0) { char const *tzbase = p + 4; @@ -1838,7 +1843,7 @@ parse_datetime2 (struct timespec *result, char const *p, tm.tm_isdst = tmp.tm_isdst; pc.meridian = MER24; - pc.rel = RELATIVE_TIME_0; + pc.rel = rel_time_0; pc.timespec_seen = false; pc.rels_seen = false; pc.dates_seen = 0; -- 2.39.5