https://github.com/python/cpython/commit/05b60613fd99a37e5d43331a4d219a55df068813
commit: 05b60613fd99a37e5d43331a4d219a55df068813
branch: main
author: Hsiang-Ying Fu <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-10T14:18:01+02:00
summary:

gh-121647: Define _Py_TYPEOF macro on more compilers (#121648)

Extend the _Py_TYPEOF macro to use __typeof__() with MSVC 17.9 and newer,
or decltype() under C++11 and newer.

files:
M Include/pyport.h

diff --git a/Include/pyport.h b/Include/pyport.h
index 73a3e6cdaf09200..03f9b869bc82b55 100644
--- a/Include/pyport.h
+++ b/Include/pyport.h
@@ -538,12 +538,15 @@ extern "C" {
 //
 // Example: _Py_TYPEOF(x) x_copy = (x);
 //
-// On C23, use typeof(). Otherwise, the macro is only defined
-// if GCC or clang compiler is used.
+// On C23, use typeof(). Otherwise __typeof__() if on GCC, clang or
+// MSVC 17.9 and newer. Else if on C++11 or newer, decltype() is used.
 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
 #  define _Py_TYPEOF(expr) typeof(expr)
-#elif defined(__GNUC__) || defined(__clang__)
+#elif defined(__GNUC__) || defined(__clang__) || \
+    (defined(_MSC_VER) && _MSC_VER >= 1939)
 #  define _Py_TYPEOF(expr) __typeof__(expr)
+#elif defined(__cplusplus) && __cplusplus >= 201103L
+#  define _Py_TYPEOF(expr) decltype(expr)
 #endif
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to