Skip to content

Commit c0e7736

Browse files
authored
[3.6] bpo-30923: Silence fall-through warnings included in -Wextra since gcc-7.0 (#3518)
* bpo-30923: Disable warning that has been part of -Wextra since gcc-7.0. (#3142) (cherry picked from commit d73a960) * bpo-30923: Silence fall-through warnings included in -Wextra since gcc-7.0. (#3157) (cherry picked from commit f432a32) * bpo-31275: Small refactoring to silence a fall-through warning. (#3206) (cherry picked from commit 138753c)
1 parent 5013a5e commit c0e7736

File tree

14 files changed

+41
-27
lines changed

14 files changed

+41
-27
lines changed

Modules/_ctypes/_ctypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3675,7 +3675,7 @@ _build_callargs(PyCFuncPtrObject *self, PyObject *argtypes,
36753675
case (PARAMFLAG_FIN | PARAMFLAG_FOUT):
36763676
*pinoutmask |= (1 << i); /* mark as inout arg */
36773677
(*pnumretvals)++;
3678-
/* fall through to PARAMFLAG_FIN... */
3678+
/* fall through */
36793679
case 0:
36803680
case PARAMFLAG_FIN:
36813681
/* 'in' parameter. Copy it from inargs. */

Modules/_decimal/libmpdec/io.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
PEP-3101 formatting for numeric types. */
4646

4747

48+
/* Disable warning that is part of -Wextra since gcc 7.0. */
49+
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && __GNUC__ >= 7
50+
#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
51+
#endif
52+
53+
4854
/*
4955
* Work around the behavior of tolower() and strcasecmp() in certain
5056
* locales. For example, in tr_TR.utf8:

Modules/cjkcodecs/_codecs_iso2022.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -807,15 +807,9 @@ jisx0213_encoder(const Py_UCS4 *data, Py_ssize_t *length, void *config)
807807
case 2: /* second character of unicode pair */
808808
coded = find_pairencmap((ucs2_t)data[0], (ucs2_t)data[1],
809809
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
810-
if (coded == DBCINV) {
811-
*length = 1;
812-
coded = find_pairencmap((ucs2_t)data[0], 0,
813-
jisx0213_pair_encmap, JISX0213_ENCPAIRS);
814-
if (coded == DBCINV)
815-
return MAP_UNMAPPABLE;
816-
}
817-
else
810+
if (coded != DBCINV)
818811
return coded;
812+
/* fall through */
819813

820814
case -1: /* flush unterminated */
821815
*length = 1;

Objects/stringlib/codecs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
330330
case _Py_ERROR_REPLACE:
331331
memset(p, '?', endpos - startpos);
332332
p += (endpos - startpos);
333-
/* fall through the ignore handler */
333+
/* fall through */
334334
case _Py_ERROR_IGNORE:
335335
i += (endpos - startpos - 1);
336336
break;
@@ -378,7 +378,7 @@ STRINGLIB(utf8_encoder)(PyObject *unicode,
378378
}
379379
startpos = k;
380380
assert(startpos < endpos);
381-
/* fall through the default handler */
381+
/* fall through */
382382
default:
383383
rep = unicode_encode_call_errorhandler(
384384
errors, &error_handler_obj, "utf-8", "surrogates not allowed",

Objects/unicodeobject.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ unicode_dealloc(PyObject *unicode)
17791779

17801780
case SSTATE_INTERNED_IMMORTAL:
17811781
Py_FatalError("Immortal interned string died.");
1782+
/* fall through */
17821783

17831784
default:
17841785
Py_FatalError("Inconsistent interned string state.");
@@ -6816,7 +6817,7 @@ unicode_encode_ucs1(PyObject *unicode,
68166817
case _Py_ERROR_REPLACE:
68176818
memset(str, '?', collend - collstart);
68186819
str += (collend - collstart);
6819-
/* fall through ignore error handler */
6820+
/* fall through */
68206821
case _Py_ERROR_IGNORE:
68216822
pos = collend;
68226823
break;
@@ -6855,7 +6856,7 @@ unicode_encode_ucs1(PyObject *unicode,
68556856
break;
68566857
collstart = pos;
68576858
assert(collstart != collend);
6858-
/* fallback to general error handling */
6859+
/* fall through */
68596860

68606861
default:
68616862
rep = unicode_encode_call_errorhandler(errors, &error_handler_obj,

Python/ast.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
11751175
return In;
11761176
if (strcmp(STR(n), "is") == 0)
11771177
return Is;
1178+
/* fall through */
11781179
default:
11791180
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s",
11801181
STR(n));
@@ -1189,6 +1190,7 @@ ast_for_comp_op(struct compiling *c, const node *n)
11891190
return NotIn;
11901191
if (strcmp(STR(CHILD(n, 0)), "is") == 0)
11911192
return IsNot;
1193+
/* fall through */
11921194
default:
11931195
PyErr_Format(PyExc_SystemError, "invalid comp_op: %s %s",
11941196
STR(CHILD(n, 0)), STR(CHILD(n, 1)));
@@ -3149,6 +3151,7 @@ ast_for_flow_stmt(struct compiling *c, const node *n)
31493151
}
31503152
return Raise(expression, cause, LINENO(n), n->n_col_offset, c->c_arena);
31513153
}
3154+
/* fall through */
31523155
default:
31533156
PyErr_Format(PyExc_SystemError,
31543157
"unexpected flow_stmt: %d", TYPE(ch));

Python/ceval.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,9 +1875,11 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag)
18751875
switch (oparg) {
18761876
case 2:
18771877
cause = POP(); /* cause */
1878+
/* fall through */
18781879
case 1:
18791880
exc = POP(); /* exc */
1880-
case 0: /* Fallthrough */
1881+
/* fall through */
1882+
case 0:
18811883
if (do_raise(exc, cause)) {
18821884
why = WHY_EXCEPTION;
18831885
goto fast_block_end;

Python/compile.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4069,6 +4069,7 @@ expr_constant(struct compiler *c, expr_ty e)
40694069
else if (o == Py_False)
40704070
return 0;
40714071
}
4072+
/* fall through */
40724073
default:
40734074
return -1;
40744075
}
@@ -4361,13 +4362,13 @@ compiler_visit_expr(struct compiler *c, expr_ty e)
43614362
switch (e->v.Attribute.ctx) {
43624363
case AugLoad:
43634364
ADDOP(c, DUP_TOP);
4364-
/* Fall through to load */
4365+
/* Fall through */
43654366
case Load:
43664367
ADDOP_NAME(c, LOAD_ATTR, e->v.Attribute.attr, names);
43674368
break;
43684369
case AugStore:
43694370
ADDOP(c, ROT_TWO);
4370-
/* Fall through to save */
4371+
/* Fall through */
43714372
case Store:
43724373
ADDOP_NAME(c, STORE_ATTR, e->v.Attribute.attr, names);
43734374
break;

Python/dtoa.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ _Py_dg_strtod(const char *s00, char **se)
14541454
switch (c) {
14551455
case '-':
14561456
sign = 1;
1457-
/* no break */
1457+
/* fall through */
14581458
case '+':
14591459
c = *++s;
14601460
}
@@ -1523,7 +1523,7 @@ _Py_dg_strtod(const char *s00, char **se)
15231523
switch (c) {
15241524
case '-':
15251525
esign = 1;
1526-
/* no break */
1526+
/* fall through */
15271527
case '+':
15281528
c = *++s;
15291529
}
@@ -2441,15 +2441,15 @@ _Py_dg_dtoa(double dd, int mode, int ndigits,
24412441
break;
24422442
case 2:
24432443
leftright = 0;
2444-
/* no break */
2444+
/* fall through */
24452445
case 4:
24462446
if (ndigits <= 0)
24472447
ndigits = 1;
24482448
ilim = ilim1 = i = ndigits;
24492449
break;
24502450
case 3:
24512451
leftright = 0;
2452-
/* no break */
2452+
/* fall through */
24532453
case 5:
24542454
i = ndigits + k + 1;
24552455
ilim = i;

Python/formatter_unicode.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ parse_internal_render_format_spec(PyObject *format_spec,
312312
format->thousands_separators = LT_UNDER_FOUR_LOCALE;
313313
break;
314314
}
315+
/* fall through */
315316
default:
316317
invalid_comma_type(format->type);
317318
return 0;

Python/getargs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2260,8 +2260,8 @@ skipitem(const char **p_format, va_list *p_va, int flags)
22602260
/* after 'e', only 's' and 't' is allowed */
22612261
goto err;
22622262
format++;
2263-
/* explicit fallthrough to string cases */
22642263
}
2264+
/* fall through */
22652265

22662266
case 's': /* string */
22672267
case 'z': /* string or None */

Python/marshal.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,7 @@ r_object(RFILE *p)
11051105

11061106
case TYPE_ASCII_INTERNED:
11071107
is_interned = 1;
1108+
/* fall through */
11081109
case TYPE_ASCII:
11091110
n = r_long(p);
11101111
if (PyErr_Occurred())
@@ -1117,6 +1118,7 @@ r_object(RFILE *p)
11171118

11181119
case TYPE_SHORT_ASCII_INTERNED:
11191120
is_interned = 1;
1121+
/* fall through */
11201122
case TYPE_SHORT_ASCII:
11211123
n = r_byte(p);
11221124
if (n == EOF) {
@@ -1142,6 +1144,7 @@ r_object(RFILE *p)
11421144

11431145
case TYPE_INTERNED:
11441146
is_interned = 1;
1147+
/* fall through */
11451148
case TYPE_UNICODE:
11461149
{
11471150
const char *buffer;

Python/pyhash.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,13 @@ siphash24(const void *src, Py_ssize_t src_sz) {
393393
pt = (uint8_t *)&t;
394394
m = (uint8_t *)in;
395395
switch (src_sz) {
396-
case 7: pt[6] = m[6];
397-
case 6: pt[5] = m[5];
398-
case 5: pt[4] = m[4];
396+
case 7: pt[6] = m[6]; /* fall through */
397+
case 6: pt[5] = m[5]; /* fall through */
398+
case 5: pt[4] = m[4]; /* fall through */
399399
case 4: memcpy(pt, m, sizeof(uint32_t)); break;
400-
case 3: pt[2] = m[2];
401-
case 2: pt[1] = m[1];
402-
case 1: pt[0] = m[0];
400+
case 3: pt[2] = m[2]; /* fall through */
401+
case 2: pt[1] = m[1]; /* fall through */
402+
case 1: pt[0] = m[0]; /* fall through */
403403
}
404404
b |= _le64toh(t);
405405

Python/wordcode_helpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,13 @@ write_op_arg(_Py_CODEUNIT *codestr, unsigned char opcode,
2828
switch (ilen) {
2929
case 4:
3030
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 24) & 0xff);
31+
/* fall through */
3132
case 3:
3233
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 16) & 0xff);
34+
/* fall through */
3335
case 2:
3436
*codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 8) & 0xff);
37+
/* fall through */
3538
case 1:
3639
*codestr++ = PACKOPARG(opcode, oparg & 0xff);
3740
break;

0 commit comments

Comments
 (0)