8000 gh-128902: Fix check for fallthrough attribute support by jmroot · Pull Request #128903 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-128902: Fix check for fallthrough attribute support #128903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix check for fallthrough attribute support
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: llvm/llvm-project@1e0affb
  • Loading branch information
jmroot committed Jan 16, 2025
commit 82bbdbd15b9ac4c66a947bf82d3ffb00fa403d64
9 changes: 7 additions & 2 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading
0