From 82bbdbd15b9ac4c66a947bf82d3ffb00fa403d64 Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Thu, 16 Jan 2025 14:12:25 +1100 Subject: [PATCH 1/2] 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: https://github.com/llvm/llvm-project/commit/1e0affb6e564b7361b0aadb38805f26deff4ecfc --- Include/pyport.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) From e24773d88da48414618bf5c92b2dac477f6e9c75 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 16 Jan 2025 03:35:40 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Build/2025-01-16-03-35-37.gh-issue-128902.Dt7xtV.rst 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.