Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Include/pyport.h
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,14 @@ extern "C" {
//
// Example: _Py_TYPEOF(x) x_copy = (x);
//
// The macro is only defined if GCC or clang compiler is used.
#if defined(__GNUC__) || defined(__clang__)
// Defined if __typeof__ or its equivalents are available.
#if defined(__GNUC__) || defined(__clang__) || defined(HAVE_TYPEOF) || \
(defined(_MSC_VER) && _MSC_VER >= 1939)
# define _Py_TYPEOF(expr) __typeof__(expr)
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
# define _Py_TYPEOF(expr) typeof(expr)
#elif defined(__cplusplus) && __cplusplus >= 201103
# define _Py_TYPEOF(expr) decltype(expr)
#endif


Expand Down
30 changes: 30 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -6983,6 +6983,19 @@ case "$ac_cv_computed_gotos" in yes*)
[Define if the C compiler supports computed gotos.])
esac

AC_CACHE_CHECK([whether $CC supports __typeof__], [ac_cv_typeof],
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
int i;
__typeof__(i) *p = &i;
]])],
[ac_cv_typeof=yes],
[ac_cv_typeof=no]))
if test "$ac_cv_typeof" = yes
then
AC_DEFINE([HAVE_TYPEOF], [1],
[Define if the C compiler supports __typeof__(expr)])
fi

case $ac_sys_system in
AIX*)
AC_DEFINE([HAVE_BROKEN_PIPE_BUF], [1],
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,9 @@
/* Define to 1 if you have the `ttyname' function. */
#undef HAVE_TTYNAME

/* Define if the C compiler supports __typeof__(expr) */
#undef HAVE_TYPEOF

/* Define to 1 if you don't have `tm_zone' but do have the external array
`tzname'. */
#undef HAVE_TZNAME
Expand Down
Loading