Skip to content

Support Py_UNUSED() on clang #13544

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

Merged
merged 1 commit into from
May 24, 2019
Merged
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
2 changes: 1 addition & 1 deletion Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ complete listing.
.. c:macro:: Py_UNUSED(arg)

Use this for unused arguments in a function definition to silence compiler
warnings, e.g. ``PyObject* func(PyObject *Py_UNUSED(ignored))``.
warnings. Example: ``int func(int a, int Py_UNUSED(b)) { return a; }``.

.. versionadded:: 3.4

Expand Down
11 changes: 8 additions & 3 deletions Include/pymacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,15 @@
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))

#ifdef __GNUC__
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
/* Use this for unused arguments in a function definition to silence compiler
* warnings. Example:
*
* int func(int a, int Py_UNUSED(b)) { return a; }
*/
#if defined(__GNUC__) || defined(__clang__)
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
#else
#define Py_UNUSED(name) _unused_ ## name
# define Py_UNUSED(name) _unused_ ## name
#endif

#define Py_UNREACHABLE() abort()
Expand Down