Skip to content

Commit 82bbdbd

Browse files
committed
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
1 parent d05140f commit 82bbdbd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Include/pyport.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,8 +625,13 @@ extern "C" {
625625
// case 2: code; break;
626626
// }
627627
//
628-
// __attribute__((fallthrough)) was introduced in GCC 7.
629-
#if _Py__has_attribute(fallthrough)
628+
// __attribute__((fallthrough)) was introduced in GCC 7 and Clang 10 /
629+
// Apple Clang 12.0. Earlier Clang versions support only the C++11
630+
// style fallthrough attribute, not the GCC extension syntax used here,
631+
// and __has_attribute(fallthrough) evaluates to 1.
632+
#if _Py__has_attribute(fallthrough) && (!defined(__clang__) || \
633+
(!defined(__apple_build_version__) && __clang_major__ >= 10) || \
634+
(defined(__apple_build_version__) && __clang_major__ >= 12))
630635
# define _Py_FALLTHROUGH __attribute__((fallthrough))
631636
#else
632637
# define _Py_FALLTHROUGH do { } while (0)

0 commit comments

Comments
 (0)