]> granicus.if.org Git - python/commitdiff
Support Py_UNUSED() on clang (GH-13544)
authorVictor Stinner <vstinner@redhat.com>
Fri, 24 May 2019 13:16:08 +0000 (15:16 +0200)
committerGitHub <noreply@github.com>
Fri, 24 May 2019 13:16:08 +0000 (15:16 +0200)
Doc/c-api/intro.rst
Include/pymacro.h

index b003bbaeff2f5b2354153aee1e2971ec88b6ba6a..672936a458f4638eeaaaf6d1825a7ccb2175e6de 100644 (file)
@@ -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
 
index 546f9c6e7020254cb9c46bb8f987dcda04e1fa6f..1890619099a35b121ee52844b1f229a8899204f7 100644 (file)
 /* 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()