Skip to content

Commit b3a9843

Browse files
authored
Support Py_UNUSED() on clang (GH-13544)
1 parent b4bdecd commit b3a9843

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

Doc/c-api/intro.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ complete listing.
156156
.. c:macro:: Py_UNUSED(arg)
157157
158158
Use this for unused arguments in a function definition to silence compiler
159-
warnings, e.g. ``PyObject* func(PyObject *Py_UNUSED(ignored))``.
159+
warnings. Example: ``int func(int a, int Py_UNUSED(b)) { return a; }``.
160160

161161
.. versionadded:: 3.4
162162

Include/pymacro.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,15 @@
8989
/* Check if pointer "p" is aligned to "a"-bytes boundary. */
9090
#define _Py_IS_ALIGNED(p, a) (!((uintptr_t)(p) & (uintptr_t)((a) - 1)))
9191

92-
#ifdef __GNUC__
93-
#define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
92+
/* Use this for unused arguments in a function definition to silence compiler
93+
* warnings. Example:
94+
*
95+
* int func(int a, int Py_UNUSED(b)) { return a; }
96+
*/
97+
#if defined(__GNUC__) || defined(__clang__)
98+
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
9499
#else
95-
#define Py_UNUSED(name) _unused_ ## name
100+
# define Py_UNUSED(name) _unused_ ## name
96101
#endif
97102

98103
#define Py_UNREACHABLE() abort()

0 commit comments

Comments
 (0)