Hi,

On 2022-11-02 17:03:34 -0700, Andres Freund wrote:
> On 2022-11-02 19:57:45 -0400, Tom Lane wrote:
> > Andres Freund <and...@anarazel.de> writes:
> > > On 2022-11-01 17:00:27 -0400, Peter Eisentraut wrote:
> > >> Python has the same issues.  There are a few other Python-embedding 
> > >> projects
> > >> that use -Wdeclaration-after-statement and complain if the Python headers
> > >> violate it.  But it's getting tedious.  -isystem would be a better 
> > >> solution.
> >
> > > Which dependencies should we convert to -isystem?
> >
> > Color me confused about what's being discussed here.  I see nothing
> > in the gcc manual suggesting that -isystem has any effect on warning
> > levels?
>
> It's only indirectly explained :(
>
>            The -isystem and -idirafter options also mark the directory as a 
> system directory, so that it gets the same special treatment that is applied 
> to
>            the standard system directories.
>
> and then https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html

The attached *prototype* patch is a slightly different spin on the idea of
using -isystem: It adds a
  #pragma GCC system_header
to plperl.h if supported by the compiler. That also avoids warnings from
within plperl and subsidiary headers.

I don't really have an opinion about whether using the pragma or -isystem is
preferrable. I chose the pragma because it makes it easier to grep for headers
where we chose to do this.


I added the pragma detection only to the meson build, but if others think this
is a good way to go, I'll do the necessary autoconf wrangling as well.


In the compiler test, I chose to not check whether -Werror=unknown-pragmas is
supported - it appears to be an old gcc flag, and the worst outcome is that
HAVE_PRAGMA_SYSTEM_HEADER isn't defined.

We could alternatively define HAVE_PRAGMA_SYSTEM_HEADER or such based on
__GNUC__ being defined.

Greetings,

Andres Freund
>From ee6d9760206b59baa8f2d9adb09cf730ca2d24a4 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Wed, 28 Dec 2022 10:09:48 -0800
Subject: [PATCH] wip: perl: If supported, use gcc's system_header pragma to
 hide warnings

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 meson.build            | 9 +++++++++
 src/pl/plperl/plperl.h | 8 ++++++++
 2 files changed, 17 insertions(+)

diff --git a/meson.build b/meson.build
index b872470cdfe..1532b04c62a 100644
--- a/meson.build
+++ b/meson.build
@@ -1408,6 +1408,15 @@ if not cc.compiles(c99_test, name: 'c99', args: test_c_args)
   endif
 endif
 
+# Does the compiler support #pragma GCC system_header? We optionally use it to
+# avoid warnings that we can't fix (e.g. in the perl headers).
+# See https://gcc.gnu.org/onlinedocs/cpp/System-Headers.html
+if cc.compiles('#pragma GCC system_header',
+    name: 'pragma system header',
+    args: test_c_args + ['-Werror=unknown-pragmas'])
+  cdata.set('HAVE_PRAGMA_SYSTEM_HEADER', 1)
+endif
+
 sizeof_long = cc.sizeof('long', args: test_c_args)
 cdata.set('SIZEOF_LONG', sizeof_long)
 if sizeof_long == 8
diff --git a/src/pl/plperl/plperl.h b/src/pl/plperl/plperl.h
index 5243f308bd5..2656a0376ee 100644
--- a/src/pl/plperl/plperl.h
+++ b/src/pl/plperl/plperl.h
@@ -74,6 +74,14 @@
 #define HAS_BOOL 1
 #endif
 
+/*
+ * At least in newer versions the perl headers trigger a lot of warnings with
+ * our compiler flags. The system_header pragma hides warnings from within the
+ * rest of this file, if supported.
+ */
+#if HAVE_PRAGMA_SYSTEM_HEADER
+#pragma GCC system_header
+#endif
 
 /*
  * Get the basic Perl API.  We use PERL_NO_GET_CONTEXT mode so that our code
-- 
2.38.0

Reply via email to