https://github.com/python/cpython/commit/edf803345a5c57c38fca3850386530e30b397eca
commit: edf803345a5c57c38fca3850386530e30b397eca
branch: main
author: Joshua Root <j...@macports.org>
committer: ned-deily <n...@python.org>
date: 2025-01-22T04:25:30-05:00
summary:

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: 
https://github.com/llvm/llvm-project/commit/1e0affb6e564b7361b0aadb38805f26deff4ecfc

files:
A Misc/NEWS.d/next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst
M Include/pyport.h

diff --git a/Include/pyport.h b/Include/pyport.h
index 2b6bd4c21110e5..aabd094df54a74 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -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)
diff --git 
a/Misc/NEWS.d/next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst 
b/Misc/NEWS.d/next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst
new file mode 100644
index 00000000000000..42ac492498e029
--- /dev/null
+++ b/Misc/NEWS.d/next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst
@@ -0,0 +1 @@
+Fix compile errors with Clang 9 and older due to lack of 
``__attribute__((fallthrough))`` support.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to