diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-01 19:35:08 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2018-05-01 19:35:08 -0400 |
commit | 41c912cad15955b5f9270ef3688a44e91d410d3d (patch) | |
tree | 829397c0ab0c3fdd1863b3ddc9cd9caffc5a3729 /src/backend/utils/adt/timestamp.c | |
parent | 1667148a4dd98cea28b8b53d57dbc1eece1b0b5c (diff) | |
download | postgresql-41c912cad15955b5f9270ef3688a44e91d410d3d.tar.gz postgresql-41c912cad15955b5f9270ef3688a44e91d410d3d.zip |
Clean up warnings from -Wimplicit-fallthrough.
Recent gcc can warn about switch-case fall throughs that are not
explicitly labeled as intentional. This seems like a good thing,
so clean up the warnings exposed thereby by labeling all such
cases with comments that gcc will recognize.
In files that already had one or more suitable comments, I generally
matched the existing style of those. Otherwise I went with
/* FALLTHROUGH */, which is one of the spellings approved at the
more-restrictive-than-default level -Wimplicit-fallthrough=4.
(At the default level you can also spell it /* FALL ?THRU */,
and it's not picky about case. What you can't do is include
additional text in the same comment, so some existing comments
containing versions of this aren't good enough.)
Testing with gcc 8.0.1 (Fedora 28's current version), I found that
I also had to put explicit "break"s after elog(ERROR) or ereport(ERROR);
apparently, for this purpose gcc doesn't recognize that those don't
return. That seems like possibly a gcc bug, but it's fine because
in most places we did that anyway; so this amounts to a visit from the
style police.
Discussion: https://postgr.es/m/15083.1525207729@sss.pgh.pa.us
Diffstat (limited to 'src/backend/utils/adt/timestamp.c')
-rw-r--r-- | src/backend/utils/adt/timestamp.c | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c index 103f91ae624..265b1db7f60 100644 --- a/src/backend/utils/adt/timestamp.c +++ b/src/backend/utils/adt/timestamp.c @@ -3830,12 +3830,14 @@ timestamp_trunc(PG_FUNCTION_ARGS) tm->tm_year = ((tm->tm_year + 999) / 1000) * 1000 - 999; else tm->tm_year = -((999 - (tm->tm_year - 1)) / 1000) * 1000 + 1; + /* FALL THRU */ case DTK_CENTURY: /* see comments in timestamptz_trunc */ if (tm->tm_year > 0) tm->tm_year = ((tm->tm_year + 99) / 100) * 100 - 99; else tm->tm_year = -((99 - (tm->tm_year - 1)) / 100) * 100 + 1; + /* FALL THRU */ case DTK_DECADE: /* see comments in timestamptz_trunc */ if (val != DTK_MILLENNIUM && val != DTK_CENTURY) @@ -3845,18 +3847,25 @@ timestamp_trunc(PG_FUNCTION_ARGS) else tm->tm_year = -((8 - (tm->tm_year - 1)) / 10) * 10; } + /* FALL THRU */ case DTK_YEAR: tm->tm_mon = 1; + /* FALL THRU */ case DTK_QUARTER: tm->tm_mon = (3 * ((tm->tm_mon - 1) / 3)) + 1; + /* FALL THRU */ case DTK_MONTH: tm->tm_mday = 1; + /* FALL THRU */ case DTK_DAY: tm->tm_hour = 0; + /* FALL THRU */ case DTK_HOUR: tm->tm_min = 0; + /* FALL THRU */ case DTK_MINUTE: tm->tm_sec = 0; + /* FALL THRU */ case DTK_SECOND: fsec = 0; break; @@ -4072,28 +4081,36 @@ interval_trunc(PG_FUNCTION_ARGS) { switch (val) { - /* fall through */ case DTK_MILLENNIUM: /* caution: C division may have negative remainder */ tm->tm_year = (tm->tm_year / 1000) * 1000; + /* FALL THRU */ case DTK_CENTURY: /* caution: C division may have negative remainder */ tm->tm_year = (tm->tm_year / 100) * 100; + /* FALL THRU */ case DTK_DECADE: /* caution: C division may have negative remainder */ tm->tm_year = (tm->tm_year / 10) * 10; + /* FALL THRU */ case DTK_YEAR: tm->tm_mon = 0; + /* FALL THRU */ case DTK_QUARTER: tm->tm_mon = 3 * (tm->tm_mon / 3); + /* FALL THRU */ case DTK_MONTH: tm->tm_mday = 0; + /* FALL THRU */ case DTK_DAY: tm->tm_hour = 0; + /* FALL THRU */ case DTK_HOUR: tm->tm_min = 0; + /* FALL THRU */ case DTK_MINUTE: tm->tm_sec = 0; + /* FALL THRU */ case DTK_SECOND: fsec = 0; break; |