gh-121040: Use __attribute__((fallthrough)) (#121044)

Fix warnings when using -Wimplicit-fallthrough compiler flag.

Annotate explicitly "fall through" switch cases with a new
_Py_FALLTHROUGH macro which uses __attribute__((fallthrough)) if
available. Replace "fall through" comments with _Py_FALLTHROUGH.

Add _Py__has_attribute() macro. No longer define __has_attribute()
macro if it's not defined. Move also _Py__has_builtin() at the top
of pyport.h.

Co-Authored-By: Nikita Sobolev <mail@sobolevn.me>
This commit is contained in:
Victor Stinner 2024-06-27 11:58:44 +02:00 committed by GitHub
parent 4999e0bda0
commit 12af8ec864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 131 additions and 104 deletions

View file

@ -5073,7 +5073,7 @@ unicode_decode_utf8_impl(_PyUnicodeWriter *writer,
/* Truncated surrogate code in range D800-DFFF */
goto End;
}
/* fall through */
_Py_FALLTHROUGH;
case 3:
case 4:
errmsg = "invalid continuation byte";
@ -7108,7 +7108,7 @@ unicode_encode_ucs1(PyObject *unicode,
case _Py_ERROR_REPLACE:
memset(str, '?', collend - collstart);
str += (collend - collstart);
/* fall through */
_Py_FALLTHROUGH;
case _Py_ERROR_IGNORE:
pos = collend;
break;
@ -7147,7 +7147,7 @@ unicode_encode_ucs1(PyObject *unicode,
break;
collstart = pos;
assert(collstart != collend);
/* fall through */
_Py_FALLTHROUGH;
default:
rep = unicode_encode_call_errorhandler(errors, &error_handler_obj,
@ -8699,7 +8699,7 @@ charmap_encoding_error(
return -1;
}
}
/* fall through */
_Py_FALLTHROUGH;
case _Py_ERROR_IGNORE:
*inpos = collendpos;
break;
@ -15673,7 +15673,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
#endif
break;
case SSTATE_NOT_INTERNED:
/* fall through */
_Py_FALLTHROUGH;
default:
Py_UNREACHABLE();
}