Skip to content

[3.15] gh-157649: Fix Py_CLEAR()/Py_SETREF() on C++ - #159143

Merged
vstinner merged 2 commits into
python:3.15from
vstinner:clear15
Oct 10, 2026
Merged

vstinner merged 2 commits into
python:3.15from
vstinner:clear15

Conversation

@vstinner

@vstinner vstinner commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Using MSVC (on Windows), _Py_TYPEOF() prefers decltype()
over __typeof__() on C++.

Fix also _Py_TYPEOF() usage in Py_CLEAR() and Py_SETREF() macros.
Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++,
"_Py_TYPEOF(dst)*" can fail with a compiler error.

(cherry picked from commit bba99f2)
On C++, do not use decltype() in _Py_TYPEOF since it produces invalid
code in Py_CLEAR() and Py_SETREF(). Instead, implement Py_CLEAR(),
Py_SETREF() and Py_XSETREF() using "auto" on C++11 and newer.

Add Py_CLEAR(), Py_SETREF() and Py_XSETREF() tests on an array.

(cherry picked from commit 3330712)
@vstinner

Copy link
Copy Markdown
Member Author

Note to myself: the changes should be backported to 3.14 including #157186.

@vstinner
vstinner merged commit 7ba9a77 into python:3.15 Oct 10, 2026
55 checks passed
@vstinner
vstinner deleted the clear15 branch October 10, 2026 20:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant