Skip to content

Commit 85a6ba9

Browse files
committed
gh-121647: Prefer decltype() for _Py_TYPEOF() on C++
Using MSVC (on Windows), prefer decltype() over __typeof__() on C++.
1 parent 05b6061 commit 85a6ba9

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

Include/pyport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -538,15 +538,15 @@ extern "C" {
538538
//
539539
// Example: _Py_TYPEOF(x) x_copy = (x);
540540
//
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.
541+
// On C23, use typeof(). On C++11, use decltype(). Otherwise, use __typeof__()
542+
// if on GCC, clang or MSVC 17.9 and newer.
543543
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
544544
# define _Py_TYPEOF(expr) typeof(expr)
545+
#elif defined(__cplusplus) && __cplusplus >= 201103L
546+
# define _Py_TYPEOF(expr) decltype(expr)
545547
#elif defined(__GNUC__) || defined(__clang__) || \
546548
(defined(_MSC_VER) && _MSC_VER >= 1939)
547549
# define _Py_TYPEOF(expr) __typeof__(expr)
548-
#elif defined(__cplusplus) && __cplusplus >= 201103L
549-
# define _Py_TYPEOF(expr) decltype(expr)
550550
#endif
551551

552552

0 commit comments

Comments
 (0)