Hi,
On Wed, Dec 03, 2025 at 11:32:10PM -0500, Tom Lane wrote:
> Bertrand Drouvot <[email protected]> writes:
> > The buildfarm animal remark makes me think to check with -Wstrict-prototypes
> > and -Wold-style-definition. I just did that and found two more (added in v2
> > attached) that the coccinelle script missed...
>
> I looked into enabling -Wstrict-prototypes on one of my buildfarm
> animals, but the attempt failed because libreadline's headers are
> not clean.
It took me some time to reproduce the errors...
The reason is that gcc/clang treat certain directories (like /usr/include and
/usr/local/include on my system) as "system headers" and suppress warnings from
them, even with -Wsystem-headers.
I finally reproduced the issue by installing readline in /opt/readline/include/:
"
In file included from /opt/readline/include/readline/readline.h:36,
from input.h:21,
from command.c:38:
/opt/readline/include/readline/rltypedefs.h:35:1: error: function declaration
isn’t a prototype [-Werror=strict-prototypes]
35 | typedef int Function () __attribute__ ((deprecated));
| ^~~~~~~
/opt/readline/include/readline/rltypedefs.h:36:1: error: function declaration
isn’t a prototype [-Werror=strict-prototypes]
36 | typedef void VFunction () __attribute__ ((deprecated));
| ^~~~~~~
/opt/readline/include/readline/rltypedefs.h:37:1: error: function declaration
isn’t a prototype [-Werror=strict-prototypes]
37 | typedef char *CPFunction () __attribute__ ((deprecated));
| ^~~~~~~
/opt/readline/include/readline/rltypedefs.h:38:1: error: function declaration
isn’t a prototype [-Werror=strict-prototypes]
38 | typedef char **CPPFunction () __attribute__ ((deprecated));
| ^~~~~~~
/opt/readline/include/readline/readline.h:408:1: error: function declaration
isn’t a prototype [-Werror=strict-prototypes]
408 | extern int rl_message ();
| ^~~~~~
"
This makes me wonder: there might be other headers with similar issues that
we just don't see because they're in "system" directories.
Out of curiosity, where is readline installed on your buildfarm animal?
> It looks like we could silence those warnings by #define'ing
> HAVE_STDARG_H and _FUNCTION_DEF before including the readline
> headers. A quick test says that then the warnings do not appear,
> and psql's regression tests still pass. But it would require
> a good deal more investigation of possible side-effects before
> I'd recommend actually doing that.
Yeah, what about using Pragma Directives instead, like in the attached? I don't
see any errors with those and that looks safer to use as it only suppresses
compiler warnings.
Remark: I've read the comment about "pragma GCC diagnostic" in c.h but I think
it's safe to use for -Wstrict-prototypes (as old enough).
Regards,
--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
>From aeedb7c5cdd4108159e8fb64b79830e4651af6a2 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <[email protected]>
Date: Thu, 4 Dec 2025 09:18:24 +0000
Subject: [PATCH v1] Suppress strict-prototypes warnings from readline headers
---
src/bin/psql/input.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
100.0% src/bin/psql/
diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h
index 6b2f84e0d0c..fe9cc5f9769 100644
--- a/src/bin/psql/input.h
+++ b/src/bin/psql/input.h
@@ -17,6 +17,16 @@
#ifdef HAVE_LIBREADLINE
#define USE_READLINE 1
+/*
+ * Suppress strict-prototypes warnings from readline headers.
+ * Some readline implementations have old-style function declarations
+ * that trigger -Wstrict-prototypes, which we can't fix in third party code.
+ */
+#if defined(__GNUC__)
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+#endif
+
#if defined(HAVE_READLINE_READLINE_H)
#include <readline/readline.h>
#if defined(HAVE_READLINE_HISTORY_H)
@@ -33,6 +43,11 @@
#include <history.h>
#endif
#endif /* HAVE_READLINE_READLINE_H, etc */
+
+#if defined(__GNUC__)
+#pragma GCC diagnostic pop
+#endif
+
#endif /* HAVE_LIBREADLINE */
#include "pqexpbuffer.h"
--
2.34.1