Skip to content

Commit 8d78fea

Browse files
committed
gh-121647: Define _Py_TYPEOF macro on more compilers
Extend the _Py_TYPEOF macro to use __typeof__() with MSVC 17.9 and newer, or decltype() under C++11 and newer.
1 parent f715d25 commit 8d78fea

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

Include/pyport.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,12 +538,15 @@ extern "C" {
538538
//
539539
// Example: _Py_TYPEOF(x) x_copy = (x);
540540
//
541-
// On C23, use typeof(). Otherwise, the macro is only defined
542-
// if GCC or clang compiler is used.
541+
// On C23, use typeof(). Otherwise __typeof__() if on GCC, clang or
542+
// MSVC 17.9 and newer. Else if on C++11 or newer, decltype() is used.
543543
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
544544
# define _Py_TYPEOF(expr) typeof(expr)
545-
#elif defined(__GNUC__) || defined(__clang__)
545+
#elif defined(__GNUC__) || defined(__clang__) || \
546+
(defined(_MSC_VER) && _MSC_VER >= 1939)
546547
# define _Py_TYPEOF(expr) __typeof__(expr)
548+
#elif defined(__cplusplus) && __cplusplus >= 201103L
549+
# define _Py_TYPEOF(expr) decltype(expr)
547550
#endif
548551

549552

0 commit comments

Comments
 (0)