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
This commit is contained in:
Tom Lane 2018-05-01 19:35:08 -04:00
parent 1667148a4d
commit 41c912cad1
28 changed files with 128 additions and 25 deletions

View File

@ -88,6 +88,7 @@ gin_btree_extract_query(FunctionCallInfo fcinfo,
case BTGreaterEqualStrategyNumber:
case BTGreaterStrategyNumber:
*ptr_partialmatch = true;
/* FALLTHROUGH */
case BTEqualStrategyNumber:
entries[0] = datum;
break;

View File

@ -97,18 +97,22 @@ verify_hash_page(bytea *raw_page, int flags)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("page is not a hash meta page")));
break;
case LH_BUCKET_PAGE | LH_OVERFLOW_PAGE:
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("page is not a hash bucket or overflow page")));
break;
case LH_OVERFLOW_PAGE:
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("page is not a hash overflow page")));
break;
default:
elog(ERROR,
"hash page of type %08x not in mask %08x",
pagetype, flags);
break;
}
}

View File

@ -466,9 +466,9 @@ hash_any(register const unsigned char *k, register int keylen)
/* fall through */
case 9:
c += ((uint32) k[8] << 24);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ka[1];
a += ka[0];
break;
@ -505,9 +505,9 @@ hash_any(register const unsigned char *k, register int keylen)
/* fall through */
case 9:
c += ((uint32) k[8] << 8);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ka[1];
a += ka[0];
break;
@ -558,57 +558,77 @@ hash_any(register const unsigned char *k, register int keylen)
/* handle the last 11 bytes */
#ifdef WORDS_BIGENDIAN
switch (len) /* all the case statements fall through */
switch (len)
{
case 11:
c += ((uint32) k[10] << 8);
/* fall through */
case 10:
c += ((uint32) k[9] << 16);
/* fall through */
case 9:
c += ((uint32) k[8] << 24);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += k[7];
/* fall through */
case 7:
b += ((uint32) k[6] << 8);
/* fall through */
case 6:
b += ((uint32) k[5] << 16);
/* fall through */
case 5:
b += ((uint32) k[4] << 24);
/* fall through */
case 4:
a += k[3];
/* fall through */
case 3:
a += ((uint32) k[2] << 8);
/* fall through */
case 2:
a += ((uint32) k[1] << 16);
/* fall through */
case 1:
a += ((uint32) k[0] << 24);
/* case 0: nothing left to add */
}
#else /* !WORDS_BIGENDIAN */
switch (len) /* all the case statements fall through */
switch (len)
{
case 11:
c += ((uint32) k[10] << 24);
/* fall through */
case 10:
c += ((uint32) k[9] << 16);
/* fall through */
case 9:
c += ((uint32) k[8] << 8);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ((uint32) k[7] << 24);
/* fall through */
case 7:
b += ((uint32) k[6] << 16);
/* fall through */
case 6:
b += ((uint32) k[5] << 8);
/* fall through */
case 5:
b += k[4];
/* fall through */
case 4:
a += ((uint32) k[3] << 24);
/* fall through */
case 3:
a += ((uint32) k[2] << 16);
/* fall through */
case 2:
a += ((uint32) k[1] << 8);
/* fall through */
case 1:
a += k[0];
/* case 0: nothing left to add */
@ -686,9 +706,9 @@ hash_any_extended(register const unsigned char *k, register int keylen,
/* fall through */
case 9:
c += ((uint32) k[8] << 24);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ka[1];
a += ka[0];
break;
@ -725,9 +745,9 @@ hash_any_extended(register const unsigned char *k, register int keylen,
/* fall through */
case 9:
c += ((uint32) k[8] << 8);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ka[1];
a += ka[0];
break;
@ -778,57 +798,77 @@ hash_any_extended(register const unsigned char *k, register int keylen,
/* handle the last 11 bytes */
#ifdef WORDS_BIGENDIAN
switch (len) /* all the case statements fall through */
switch (len)
{
case 11:
c += ((uint32) k[10] << 8);
/* fall through */
case 10:
c += ((uint32) k[9] << 16);
/* fall through */
case 9:
c += ((uint32) k[8] << 24);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += k[7];
/* fall through */
case 7:
b += ((uint32) k[6] << 8);
/* fall through */
case 6:
b += ((uint32) k[5] << 16);
/* fall through */
case 5:
b += ((uint32) k[4] << 24);
/* fall through */
case 4:
a += k[3];
/* fall through */
case 3:
a += ((uint32) k[2] << 8);
/* fall through */
case 2:
a += ((uint32) k[1] << 16);
/* fall through */
case 1:
a += ((uint32) k[0] << 24);
/* case 0: nothing left to add */
}
#else /* !WORDS_BIGENDIAN */
switch (len) /* all the case statements fall through */
switch (len)
{
case 11:
c += ((uint32) k[10] << 24);
/* fall through */
case 10:
c += ((uint32) k[9] << 16);
/* fall through */
case 9:
c += ((uint32) k[8] << 8);
/* the lowest byte of c is reserved for the length */
/* fall through */
case 8:
/* the lowest byte of c is reserved for the length */
b += ((uint32) k[7] << 24);
/* fall through */
case 7:
b += ((uint32) k[6] << 16);
/* fall through */
case 6:
b += ((uint32) k[5] << 8);
/* fall through */
case 5:
b += k[4];
/* fall through */
case 4:
a += ((uint32) k[3] << 24);
/* fall through */
case 3:
a += ((uint32) k[2] << 16);
/* fall through */
case 2:
a += ((uint32) k[1] << 8);
/* fall through */
case 1:
a += k[0];
/* case 0: nothing left to add */

View File

@ -2092,6 +2092,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("name list length must be at least %d", 3)));
/* fall through to check args length */
/* FALLTHROUGH */
case OBJECT_OPERATOR:
if (list_length(args) != 2)
ereport(ERROR,

View File

@ -1479,7 +1479,8 @@ ExplainNode(PlanState *planstate, List *ancestors,
case T_SampleScan:
show_tablesample(((SampleScan *) plan)->tablesample,
planstate, ancestors, es);
/* FALL THRU to print additional fields the same as SeqScan */
/* fall through to print additional fields the same as SeqScan */
/* FALLTHROUGH */
case T_SeqScan:
case T_ValuesScan:
case T_CteScan:

View File

@ -440,6 +440,7 @@ DefineIndex(Oid relationId,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
errmsg("cannot create index on foreign table \"%s\"",
RelationGetRelationName(rel))));
break;
default:
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),

View File

@ -3338,6 +3338,7 @@ ltrmark:;
case HeapTupleInvisible:
elog(ERROR, "attempted to lock invisible tuple");
break;
default:
ReleaseBuffer(buffer);

View File

@ -2741,6 +2741,7 @@ EvalPlanQualFetch(EState *estate, Relation relation, int lockmode,
case HeapTupleInvisible:
elog(ERROR, "attempted to lock invisible tuple");
break;
default:
ReleaseBuffer(buffer);

View File

@ -202,6 +202,7 @@ retry:
goto retry;
case HeapTupleInvisible:
elog(ERROR, "attempted to lock invisible tuple");
break;
default:
elog(ERROR, "unexpected heap_lock_tuple status: %u", res);
break;
@ -365,6 +366,7 @@ retry:
goto retry;
case HeapTupleInvisible:
elog(ERROR, "attempted to lock invisible tuple");
break;
default:
elog(ERROR, "unexpected heap_lock_tuple status: %u", res);
break;

View File

@ -256,6 +256,7 @@ lnext:
case HeapTupleInvisible:
elog(ERROR, "attempted to lock invisible tuple");
break;
default:
elog(ERROR, "unrecognized heap_lock_tuple status: %u",

View File

@ -1390,6 +1390,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate,
/* This shouldn't happen */
elog(ERROR, "attempted to lock invisible tuple");
break;
case HeapTupleSelfUpdated:
@ -1399,6 +1400,7 @@ ExecOnConflictUpdate(ModifyTableState *mtstate,
* seen this row to conflict with.
*/
elog(ERROR, "unexpected self-updated tuple");
break;
case HeapTupleUpdated:
if (IsolationUsesXactSnapshot())

View File

@ -14855,18 +14855,21 @@ RoleId: RoleSpec
errmsg("role name \"%s\" is reserved",
"public"),
parser_errposition(@1)));
break;
case ROLESPEC_SESSION_USER:
ereport(ERROR,
(errcode(ERRCODE_RESERVED_NAME),
errmsg("%s cannot be used as a role name here",
"SESSION_USER"),
parser_errposition(@1)));
break;
case ROLESPEC_CURRENT_USER:
ereport(ERROR,
(errcode(ERRCODE_RESERVED_NAME),
errmsg("%s cannot be used as a role name here",
"CURRENT_USER"),
parser_errposition(@1)));
break;
}
}
;

View File

@ -3829,12 +3829,14 @@ validateInfiniteBounds(ParseState *pstate, List *blist)
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("every bound following MAXVALUE must also be MAXVALUE"),
parser_errposition(pstate, exprLocation((Node *) prd))));
break;
case PARTITION_RANGE_DATUM_MINVALUE:
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("every bound following MINVALUE must also be MINVALUE"),
parser_errposition(pstate, exprLocation((Node *) prd))));
break;
}
}
}

View File

@ -875,6 +875,7 @@ lexescape(struct vars *v)
/* oops, doesn't look like it's a backref after all... */
v->now = save;
/* and fall through into octal number */
/* FALLTHROUGH */
case CHR('0'):
NOTE(REG_UUNPORT);
v->now--; /* put first digit back */

View File

@ -909,7 +909,8 @@ parseqatom(struct vars *v,
}
/* legal in EREs due to specification botch */
NOTE(REG_UPBOTCH);
/* fallthrough into case PLAIN */
/* fall through into case PLAIN */
/* FALLTHROUGH */
case PLAIN:
onechr(v, v->nextvalue, lp, rp);
okcolors(v->nfa, v->cm);

View File

@ -2762,7 +2762,8 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
if (!IsWaitingForLock())
return;
/* Intentional drop through to check wait for pin */
/* Intentional fall through to check wait for pin */
/* FALLTHROUGH */
case PROCSIG_RECOVERY_CONFLICT_BUFFERPIN:
@ -2775,7 +2776,8 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
MyProc->recoveryConflictPending = true;
/* Intentional drop through to error handling */
/* Intentional fall through to error handling */
/* FALLTHROUGH */
case PROCSIG_RECOVERY_CONFLICT_LOCK:
case PROCSIG_RECOVERY_CONFLICT_TABLESPACE:
@ -2819,7 +2821,8 @@ RecoveryConflictInterrupt(ProcSignalReason reason)
break;
}
/* Intentional drop through to session cancel */
/* Intentional fall through to session cancel */
/* FALLTHROUGH */
case PROCSIG_RECOVERY_CONFLICT_DATABASE:
RecoveryConflictPending = true;

View File

@ -5216,6 +5216,7 @@ get_rolespec_tuple(const RoleSpec *role)
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("role \"%s\" does not exist", "public")));
tuple = NULL; /* make compiler happy */
break;
default:
elog(ERROR, "unexpected role type %d", role->roletype);

View File

@ -3146,7 +3146,7 @@ DecodeInterval(char **field, int *ftype, int nf, int range,
* handle signed float numbers and signed year-month values.
*/
/* FALL THROUGH */
/* FALLTHROUGH */
case DTK_DATE:
case DTK_NUMBER:
@ -3577,6 +3577,7 @@ DecodeISO8601Interval(char *str,
continue;
}
/* Else fall through to extended alternative format */
/* FALLTHROUGH */
case '-': /* ISO 8601 4.4.3.3 Alternative Format,
* Extended */
if (havefield)
@ -3655,6 +3656,7 @@ DecodeISO8601Interval(char *str,
return 0;
}
/* Else fall through to extended alternative format */
/* FALLTHROUGH */
case ':': /* ISO 8601 4.4.3.3 Alternative Format,
* Extended */
if (havefield)

View File

@ -1522,6 +1522,7 @@ width_bucket_numeric(PG_FUNCTION_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_ARGUMENT_FOR_WIDTH_BUCKET_FUNCTION),
errmsg("lower bound cannot equal upper bound")));
break;
/* bound1 < bound2 */
case -1:

View File

@ -7481,8 +7481,8 @@ isSimpleNode(Node *node, Node *parentNode, int prettyFlags)
return false;
}
/* else do the same stuff as for T_SubLink et al. */
/* FALL THROUGH */
}
/* FALLTHROUGH */
case T_SubLink:
case T_NullTest:

View File

@ -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;

View File

@ -5391,6 +5391,7 @@ AtEOXact_GUC(bool isCommit, int nestLevel)
{
case GUC_SAVE:
Assert(false); /* can't get here */
break;
case GUC_SET:
/* next level always becomes SET */
@ -6257,7 +6258,8 @@ set_config_option(const char *name, const char *value,
name)));
return 0;
}
/* FALL THRU to process the same as PGC_BACKEND */
/* fall through to process the same as PGC_BACKEND */
/* FALLTHROUGH */
case PGC_BACKEND:
if (context == PGC_SIGHUP)
{

View File

@ -972,7 +972,7 @@ tuplestore_gettuple(Tuplestorestate *state, bool forward,
(errcode_for_file_access(),
errmsg("could not seek in tuplestore temporary file: %m")));
state->status = TSS_READFILE;
/* FALL THRU into READFILE case */
/* FALLTHROUGH */
case TSS_READFILE:
*should_free = true;

View File

@ -1978,6 +1978,8 @@ evalStandardFunc(TState *thread, CState *st,
Assert(0);
}
}
break; /* NOTREACHED */
}
/* integer bitwise operators */

View File

@ -184,6 +184,7 @@ DecodeISO8601Interval(char *str,
continue;
}
/* Else fall through to extended alternative format */
/* FALLTHROUGH */
case '-': /* ISO 8601 4.4.3.3 Alternative Format,
* Extended */
if (havefield)
@ -262,6 +263,7 @@ DecodeISO8601Interval(char *str,
return 0;
}
/* Else fall through to extended alternative format */
/* FALLTHROUGH */
case ':': /* ISO 8601 4.4.3.3 Alternative Format,
* Extended */
if (havefield)

View File

@ -189,8 +189,8 @@ main(int argc, char *const argv[])
break;
case 'h':
header_mode = true;
/* this must include "-c" to make sense */
/* so do not place a "break;" here */
/* this must include "-c" to make sense, so fall through */
/* FALLTHROUGH */
case 'c':
auto_create_c = true;
break;

View File

@ -3968,14 +3968,17 @@ exec_prepare_plan(PLpgSQL_execstate *estate,
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot COPY to/from client in PL/pgSQL")));
break;
case SPI_ERROR_TRANSACTION:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot begin/end transactions in PL/pgSQL"),
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
break;
default:
elog(ERROR, "SPI_prepare_params failed for \"%s\": %s",
expr->query, SPI_result_code_string(SPI_result));
break;
}
}
if (keepplan)
@ -4115,15 +4118,19 @@ exec_stmt_execsql(PLpgSQL_execstate *estate,
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot COPY to/from client in PL/pgSQL")));
break;
case SPI_ERROR_TRANSACTION:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot begin/end transactions in PL/pgSQL"),
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
break;
default:
elog(ERROR, "SPI_execute_plan_with_paramlist failed executing query \"%s\": %s",
expr->query, SPI_result_code_string(rc));
break;
}
/* All variants should save result info for GET DIAGNOSTICS */
@ -4299,11 +4306,14 @@ exec_stmt_dynexecute(PLpgSQL_execstate *estate,
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot COPY to/from client in PL/pgSQL")));
break;
case SPI_ERROR_TRANSACTION:
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("cannot begin/end transactions in PL/pgSQL"),
errhint("Use a BEGIN block with an EXCEPTION clause instead.")));
break;
default:
elog(ERROR, "SPI_execute failed executing query \"%s\": %s",

View File

@ -2451,7 +2451,8 @@ pltcl_process_SPI_result(Tcl_Interp *interp,
Tcl_SetObjResult(interp, Tcl_NewIntObj(0));
break;
}
/* FALL THRU for utility returning tuples */
/* fall through for utility returning tuples */
/* FALLTHROUGH */
case SPI_OK_SELECT:
case SPI_OK_INSERT_RETURNING: