mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
gh-128902: Fix check for fallthrough attribute support (#128903)
Clang versions prior to 10 (which corresponds to Apple Clang 12) do not
support the GCC extension syntax __attribute__((fallthrough)), but do
evaluate __has_attribute(fallthrough) to 1 because they support the
C++11 style syntax [[fallthrough]]. The only way to tell if the GCC
style syntax is supported is thus to check the clang version.
Ref: 1e0affb6e5
This commit is contained in:
parent
86c1a60d5a
commit
edf803345a
2 changed files with 8 additions and 2 deletions
|
@ -625,8 +625,13 @@ extern "C" {
|
|||
// case 2: code; break;
|
||||
// }
|
||||
//
|
||||
// __attribute__((fallthrough)) was introduced in GCC 7.
|
||||
#if _Py__has_attribute(fallthrough)
|
||||
// __attribute__((fallthrough)) was introduced in GCC 7 and Clang 10 /
|
||||
// Apple Clang 12.0. Earlier Clang versions support only the C++11
|
||||
// style fallthrough attribute, not the GCC extension syntax used here,
|
||||
// and __has_attribute(fallthrough) evaluates to 1.
|
||||
#if _Py__has_attribute(fallthrough) && (!defined(__clang__) || \
|
||||
(!defined(__apple_build_version__) && __clang_major__ >= 10) || \
|
||||
(defined(__apple_build_version__) && __clang_major__ >= 12))
|
||||
# define _Py_FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
# define _Py_FALLTHROUGH do { } while (0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue