Analogous to 388e80132c (which was for Perl) but for Python, I propose adding #pragma GCC system_header to plpython.h. Without it, you get tons of warnings about -Wdeclaration-after-statement, starting with Python 3.12. (In the past, I have regularly sent feedback to Python to fix their header files, but this is getting old, and we have an easier solution now.)
From 7ca9e82d3c5e30ea21fe5d428b3fa0d6e5b3e942 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Mon, 6 Nov 2023 12:57:54 +0100
Subject: [PATCH] python: Hide warnings inside Python headers when using gcc
 compatible compiler

Analogous to 388e80132c but for Python.  This is necessary from Python
3.12 to get a warning-free build.
---
 src/pl/plpython/plpython.h | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/pl/plpython/plpython.h b/src/pl/plpython/plpython.h
index 91f6f8d860..eb01e62fb6 100644
--- a/src/pl/plpython/plpython.h
+++ b/src/pl/plpython/plpython.h
@@ -25,6 +25,16 @@
  */
 #define HAVE_SNPRINTF 1
 
+/*
+ * Newer versions of the Python headers trigger a lot of warnings with our
+ * compiler flags (at least -Wdeclaration-after-statement is known to be
+ * problematic). The system_header pragma hides warnings from within the rest
+ * of this file, if supported.
+ */
+#ifdef HAVE_PRAGMA_GCC_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
+
 #if defined(_MSC_VER) && defined(_DEBUG)
 /* Python uses #pragma to bring in a non-default libpython on VC++ if
  * _DEBUG is defined */
-- 
2.42.0

Reply via email to