Use func(void) for functions with no parameters

Started by Bertrand Drouvotabout 1 month ago10 messages
#1Bertrand Drouvot
bertranddrouvot.pg@gmail.com
1 attachment(s)

Hi hackers,

In C standards till C17, func() means "unspecified parameters" while func(void)
means "no parameters". The former disables compile time type checking and was
marked obsolescent in C99 ([1]https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf).

This patch replaces empty parameter lists with explicit void to enable proper
type checking and eliminate possible undefined behavior (see [1]https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) if the function
is called with parameters. This also prevents real bugs (API misuse for example).

Remarks:

- C23 ([2]https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) made func() and func(void) equivalent and would produce an error
if an argument is passed.

- The patch has been generated with the help of a coccinelle script [3]https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/use_func_void.cocci. It does
modify 8 functions and did not touch the few ones in .c "test" files (libpq_testclient.c
for example).

[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
[2]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf
[3]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/misc/use_func_void.cocci

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

v1-0001-Use-func-void-for-functions-with-no-parameters.patchtext/x-diff; charset=us-asciiDownload
From 8467b0c7d0a57e08e188377642dd1c8e641f42d6 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Wed, 3 Dec 2025 13:25:24 +0000
Subject: [PATCH v1] Use func(void) for functions with no parameters

In C standards till C17, func() means "unspecified parameters" while func(void)
means "no parameters". The former disables compile time type checking and was
marked obsolescent in C99.

This commit replaces empty parameter lists with explicit void to enable proper
type checking and eliminate possible undefined behavior if the function is called
with parameters. This also prevents real bugs (API misuse for example).

Note: C23 made func() and func(void) equivalent.
---
 src/backend/access/common/heaptuple.c                 | 2 +-
 src/backend/access/index/genam.c                      | 2 +-
 src/backend/replication/logical/applyparallelworker.c | 2 +-
 src/backend/replication/logical/sequencesync.c        | 2 +-
 src/backend/replication/logical/slotsync.c            | 2 +-
 src/backend/replication/logical/tablesync.c           | 2 +-
 src/backend/replication/logical/worker.c              | 2 +-
 src/backend/utils/adt/uuid.c                          | 4 ++--
 8 files changed, 9 insertions(+), 9 deletions(-)
   8.7% src/backend/access/common/
   9.8% src/backend/access/index/
  50.0% src/backend/replication/logical/
  31.4% src/backend/utils/adt/

diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 74a52d87067..1967b047020 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -123,7 +123,7 @@ missing_match(const void *key1, const void *key2, Size keysize)
 }
 
 static void
-init_missing_cache()
+init_missing_cache(void)
 {
 	HASHCTL		hash_ctl;
 
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 0cb27af1310..c96917085c2 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -488,7 +488,7 @@ systable_beginscan(Relation heapRelation,
  * is declared.
  */
 static inline void
-HandleConcurrentAbort()
+HandleConcurrentAbort(void)
 {
 	if (TransactionIdIsValid(CheckXidAlive) &&
 		!TransactionIdIsInProgress(CheckXidAlive) &&
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index baa68c1ab6c..a4eb3962cb1 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -640,7 +640,7 @@ pa_detach_all_error_mq(void)
  * Check if there are any pending spooled messages.
  */
 static bool
-pa_has_spooled_message_pending()
+pa_has_spooled_message_pending(void)
 {
 	PartialFileSetState fileset_state;
 
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index e093e65e540..019e5ec6a7d 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -711,7 +711,7 @@ LogicalRepSyncSequences(void)
  * resource error and are not repeatable.
  */
 static void
-start_sequence_sync()
+start_sequence_sync(void)
 {
 	Assert(am_sequencesync_worker());
 
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 53c7d629239..31d7cb3ca77 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -1410,7 +1410,7 @@ check_and_set_sync_info(pid_t worker_pid)
  * Reset syncing flag.
  */
 static void
-reset_syncing_flag()
+reset_syncing_flag(void)
 {
 	SpinLockAcquire(&SlotSyncCtx->mutex);
 	SlotSyncCtx->syncing = false;
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index fa8e3bf969a..6bb0cbeedad 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1551,7 +1551,7 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
  * and starts streaming to catchup with apply worker.
  */
 static void
-run_tablesync_worker()
+run_tablesync_worker(void)
 {
 	char		originname[NAMEDATALEN];
 	XLogRecPtr	origin_startpos = InvalidXLogRecPtr;
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 93970c6af29..e22f1a1edef 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5561,7 +5561,7 @@ set_stream_options(WalRcvStreamOptions *options,
  * Cleanup the memory for subxacts and reset the related variables.
  */
 static inline void
-cleanup_subxact_info()
+cleanup_subxact_info(void)
 {
 	if (subxact_data.subxacts)
 		pfree(subxact_data.subxacts);
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index e5f27ff892b..5df35d7cacb 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -71,7 +71,7 @@ static int	uuid_fast_cmp(Datum x, Datum y, SortSupport ssup);
 static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
 static Datum uuid_abbrev_convert(Datum original, SortSupport ssup);
 static inline void uuid_set_version(pg_uuid_t *uuid, unsigned char version);
-static inline int64 get_real_time_ns_ascending();
+static inline int64 get_real_time_ns_ascending(void);
 static pg_uuid_t *generate_uuidv7(uint64 unix_ts_ms, uint32 sub_ms);
 
 Datum
@@ -545,7 +545,7 @@ gen_random_uuid(PG_FUNCTION_ARGS)
  * than the previous returned timestamp (on this backend).
  */
 static inline int64
-get_real_time_ns_ascending()
+get_real_time_ns_ascending(void)
 {
 	static int64 previous_ns = 0;
 	int64		ns;
-- 
2.34.1

#2Matthias van de Meent
boekewurm+postgres@gmail.com
In reply to: Bertrand Drouvot (#1)
Re: Use func(void) for functions with no parameters

On Wed, 3 Dec 2025 at 15:51, Bertrand Drouvot
<bertranddrouvot.pg@gmail.com> wrote:

Hi hackers,

In C standards till C17, func() means "unspecified parameters" while func(void)
means "no parameters". The former disables compile time type checking and was
marked obsolescent in C99 ([1]).

This patch replaces empty parameter lists with explicit void to enable proper
type checking and eliminate possible undefined behavior (see [1]) if the function
is called with parameters. This also prevents real bugs (API misuse for example).

LGTM, thanks!

I noticed the only changes here are for `static` definitions. Are we
just more careful with normal functions, or does the compiler complain
more easily about such "incomplete" definitions when they're in
headers or need to be linked against?

Kind regards,

Matthias van de Meent
Databricks (https://www.databricks.com)

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Matthias van de Meent (#2)
Re: Use func(void) for functions with no parameters

Matthias van de Meent <boekewurm+postgres@gmail.com> writes:

I noticed the only changes here are for `static` definitions. Are we
just more careful with normal functions, or does the compiler complain
more easily about such "incomplete" definitions when they're in
headers or need to be linked against?

Some years ago we had a buildfarm animal that would complain about
this construct, so the tree used to be clean. Probably it's just
chance that these have only snuck into local functions.

regards, tom lane

#4Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Tom Lane (#3)
1 attachment(s)
Re: Use func(void) for functions with no parameters

Hi,

On Wed, Dec 03, 2025 at 10:15:41AM -0500, Tom Lane wrote:

Matthias van de Meent <boekewurm+postgres@gmail.com> writes:

I noticed the only changes here are for `static` definitions. Are we
just more careful with normal functions, or does the compiler complain
more easily about such "incomplete" definitions when they're in
headers or need to be linked against?

Some years ago we had a buildfarm animal that would complain about
this construct, so the tree used to be clean. Probably it's just
chance that these have only snuck into local functions.

Thank you both for looking at it!

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...

Those new two (run_apply_worker() and usage()) are also static, so that's just
chance.

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com

Attachments:

v2-0001-Use-func-void-for-functions-with-no-parameters.patchtext/x-diff; charset=us-asciiDownload
From 3da01ff159d2e88fad0fd781d514215254614fba Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Date: Wed, 3 Dec 2025 13:25:24 +0000
Subject: [PATCH v2] Use func(void) for functions with no parameters

In C standards till C17, func() means "unspecified parameters" while func(void)
means "no parameters". The former disables compile time type checking and was
marked obsolescent in C99.

This commit replaces empty parameter lists with explicit void to enable proper
type checking and eliminate possible undefined behavior if the function is called
with parameters. This also prevents real bugs (API misuse for example).

Note: C23 made func() and func(void) equivalent.

Author: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
Reviewed-by: Matthias van de Meent <boekewurm+postgres@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://www.postgresql.org/message-id/flat/aTBObQPg%2Bps5I7vl%40ip-10-97-1-34.eu-west-3.compute.internal
---
 src/backend/access/common/heaptuple.c                 | 2 +-
 src/backend/access/index/genam.c                      | 2 +-
 src/backend/replication/logical/applyparallelworker.c | 2 +-
 src/backend/replication/logical/sequencesync.c        | 2 +-
 src/backend/replication/logical/slotsync.c            | 2 +-
 src/backend/replication/logical/tablesync.c           | 2 +-
 src/backend/replication/logical/worker.c              | 4 ++--
 src/backend/utils/adt/uuid.c                          | 4 ++--
 src/bin/pg_basebackup/pg_createsubscriber.c           | 2 +-
 9 files changed, 11 insertions(+), 11 deletions(-)
   7.4% src/backend/access/common/
   8.4% src/backend/access/index/
  49.6% src/backend/replication/logical/
  26.9% src/backend/utils/adt/
   7.4% src/bin/pg_basebackup/

diff --git a/src/backend/access/common/heaptuple.c b/src/backend/access/common/heaptuple.c
index 74a52d87067..1967b047020 100644
--- a/src/backend/access/common/heaptuple.c
+++ b/src/backend/access/common/heaptuple.c
@@ -123,7 +123,7 @@ missing_match(const void *key1, const void *key2, Size keysize)
 }
 
 static void
-init_missing_cache()
+init_missing_cache(void)
 {
 	HASHCTL		hash_ctl;
 
diff --git a/src/backend/access/index/genam.c b/src/backend/access/index/genam.c
index 0cb27af1310..c96917085c2 100644
--- a/src/backend/access/index/genam.c
+++ b/src/backend/access/index/genam.c
@@ -488,7 +488,7 @@ systable_beginscan(Relation heapRelation,
  * is declared.
  */
 static inline void
-HandleConcurrentAbort()
+HandleConcurrentAbort(void)
 {
 	if (TransactionIdIsValid(CheckXidAlive) &&
 		!TransactionIdIsInProgress(CheckXidAlive) &&
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index baa68c1ab6c..a4eb3962cb1 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -640,7 +640,7 @@ pa_detach_all_error_mq(void)
  * Check if there are any pending spooled messages.
  */
 static bool
-pa_has_spooled_message_pending()
+pa_has_spooled_message_pending(void)
 {
 	PartialFileSetState fileset_state;
 
diff --git a/src/backend/replication/logical/sequencesync.c b/src/backend/replication/logical/sequencesync.c
index e093e65e540..019e5ec6a7d 100644
--- a/src/backend/replication/logical/sequencesync.c
+++ b/src/backend/replication/logical/sequencesync.c
@@ -711,7 +711,7 @@ LogicalRepSyncSequences(void)
  * resource error and are not repeatable.
  */
 static void
-start_sequence_sync()
+start_sequence_sync(void)
 {
 	Assert(am_sequencesync_worker());
 
diff --git a/src/backend/replication/logical/slotsync.c b/src/backend/replication/logical/slotsync.c
index 53c7d629239..31d7cb3ca77 100644
--- a/src/backend/replication/logical/slotsync.c
+++ b/src/backend/replication/logical/slotsync.c
@@ -1410,7 +1410,7 @@ check_and_set_sync_info(pid_t worker_pid)
  * Reset syncing flag.
  */
 static void
-reset_syncing_flag()
+reset_syncing_flag(void)
 {
 	SpinLockAcquire(&SlotSyncCtx->mutex);
 	SlotSyncCtx->syncing = false;
diff --git a/src/backend/replication/logical/tablesync.c b/src/backend/replication/logical/tablesync.c
index fa8e3bf969a..6bb0cbeedad 100644
--- a/src/backend/replication/logical/tablesync.c
+++ b/src/backend/replication/logical/tablesync.c
@@ -1551,7 +1551,7 @@ start_table_sync(XLogRecPtr *origin_startpos, char **slotname)
  * and starts streaming to catchup with apply worker.
  */
 static void
-run_tablesync_worker()
+run_tablesync_worker(void)
 {
 	char		originname[NAMEDATALEN];
 	XLogRecPtr	origin_startpos = InvalidXLogRecPtr;
diff --git a/src/backend/replication/logical/worker.c b/src/backend/replication/logical/worker.c
index 93970c6af29..a46f8e0644b 100644
--- a/src/backend/replication/logical/worker.c
+++ b/src/backend/replication/logical/worker.c
@@ -5561,7 +5561,7 @@ set_stream_options(WalRcvStreamOptions *options,
  * Cleanup the memory for subxacts and reset the related variables.
  */
 static inline void
-cleanup_subxact_info()
+cleanup_subxact_info(void)
 {
 	if (subxact_data.subxacts)
 		pfree(subxact_data.subxacts);
@@ -5621,7 +5621,7 @@ start_apply(XLogRecPtr origin_startpos)
  * It sets up replication origin, streaming options and then starts streaming.
  */
 static void
-run_apply_worker()
+run_apply_worker(void)
 {
 	char		originname[NAMEDATALEN];
 	XLogRecPtr	origin_startpos = InvalidXLogRecPtr;
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index e5f27ff892b..5df35d7cacb 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -71,7 +71,7 @@ static int	uuid_fast_cmp(Datum x, Datum y, SortSupport ssup);
 static bool uuid_abbrev_abort(int memtupcount, SortSupport ssup);
 static Datum uuid_abbrev_convert(Datum original, SortSupport ssup);
 static inline void uuid_set_version(pg_uuid_t *uuid, unsigned char version);
-static inline int64 get_real_time_ns_ascending();
+static inline int64 get_real_time_ns_ascending(void);
 static pg_uuid_t *generate_uuidv7(uint64 unix_ts_ms, uint32 sub_ms);
 
 Datum
@@ -545,7 +545,7 @@ gen_random_uuid(PG_FUNCTION_ARGS)
  * than the previous returned timestamp (on this backend).
  */
 static inline int64
-get_real_time_ns_ascending()
+get_real_time_ns_ascending(void)
 {
 	static int64 previous_ns = 0;
 	int64		ns;
diff --git a/src/bin/pg_basebackup/pg_createsubscriber.c b/src/bin/pg_basebackup/pg_createsubscriber.c
index cc4be5d6ef4..43dc6ff7693 100644
--- a/src/bin/pg_basebackup/pg_createsubscriber.c
+++ b/src/bin/pg_basebackup/pg_createsubscriber.c
@@ -78,7 +78,7 @@ struct LogicalRepInfos
 };
 
 static void cleanup_objects_atexit(void);
-static void usage();
+static void usage(void);
 static char *get_base_conninfo(const char *conninfo, char **dbname);
 static char *get_sub_conninfo(const struct CreateSubscriberOptions *opt);
 static char *get_exec_path(const char *argv0, const char *progname);
-- 
2.34.1

#5Nathan Bossart
nathandbossart@gmail.com
In reply to: Bertrand Drouvot (#4)
Re: Use func(void) for functions with no parameters

On Wed, Dec 03, 2025 at 03:53:37PM +0000, Bertrand Drouvot wrote:

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...

Those new two (run_apply_worker() and usage()) are also static, so that's just
chance.

LGTM, too. I'll take care of committing this shortly.

--
nathan

#6Nathan Bossart
nathandbossart@gmail.com
In reply to: Nathan Bossart (#5)
Re: Use func(void) for functions with no parameters

Committed.

--
nathan

#7Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bertrand Drouvot (#4)
Re: Use func(void) for functions with no parameters

Bertrand Drouvot <bertranddrouvot.pg@gmail.com> writes:

On Wed, Dec 03, 2025 at 10:15:41AM -0500, Tom Lane wrote:

Some years ago we had a buildfarm animal that would complain about
this construct, so the tree used to be clean. Probably it's just
chance that these have only snuck into local functions.

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 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.

regards, tom lane

#8Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Tom Lane (#7)
1 attachment(s)
Re: Use func(void) for functions with no parameters

Hi,

On Wed, Dec 03, 2025 at 11:32:10PM -0500, Tom Lane wrote:

Bertrand Drouvot <bertranddrouvot.pg@gmail.com> 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

Attachments:

v1-0001-Suppress-strict-prototypes-warnings-from-readline.patchtext/x-diff; charset=us-asciiDownload
From aeedb7c5cdd4108159e8fb64b79830e4651af6a2 Mon Sep 17 00:00:00 2001
From: Bertrand Drouvot <bertranddrouvot.pg@gmail.com>
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

#9Tom Lane
tgl@sss.pgh.pa.us
In reply to: Bertrand Drouvot (#8)
Re: Use func(void) for functions with no parameters

Bertrand Drouvot <bertranddrouvot.pg@gmail.com> writes:

On Wed, Dec 03, 2025 at 11:32:10PM -0500, Tom Lane wrote:

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.

Oh, duh. You guessed correctly: I was trying this on BF animal
indri, which gets a lot of stuff from MacPorts and therefore these
headers are under /opt/local/include. I wonder whether I should
adjust its build flags to treat that as a system directory.
It hasn't been a problem up to now, but ...

Yeah, what about using Pragma Directives instead, like in the
attached?

Yeah, a pragma is probably safer than what I was thinking about.
But I'd be inclined to just use "#pragma GCC system_header" in
input.h, since that's already tested and used elsewhere in the tree.
There's little enough other stuff in that file that I think we
could just do it, and not bother breaking out a sub-include file
like we did in plperl and plpython.

In any case, I don't think we should bother unless there's a push to
enable -Wstrict-prototypes by default, which I've not heard being
proposed.

regards, tom lane

#10Bertrand Drouvot
bertranddrouvot.pg@gmail.com
In reply to: Tom Lane (#9)
Re: Use func(void) for functions with no parameters

Hi,

On Thu, Dec 04, 2025 at 10:17:28AM -0500, Tom Lane wrote:

Bertrand Drouvot <bertranddrouvot.pg@gmail.com> writes:

Yeah, what about using Pragma Directives instead, like in the
attached?

Yeah, a pragma is probably safer than what I was thinking about.
But I'd be inclined to just use "#pragma GCC system_header" in
input.h, since that's already tested and used elsewhere in the tree.

Agree.

In any case, I don't think we should bother unless there's a push to
enable -Wstrict-prototypes by default, which I've not heard being
proposed.

Now that the code tree is clean, I think that this is a good timing for it.

We have been tracking and cleaning those in commits cdf4b9aff2, 0e72b9d440,
7069dbcc31, f1283ed6cc, 7b66e2c086, e95126cf04, 9f7c527af3 and recently in
9b05e2ec08a, so I think that it would make sense to "ensure" it's always tracked.

This is not just about coding style but also prevents undefined behavior (see
[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
�6.7.7.4/13), so this would align with it.

If that sounds reasonable, I'd happy to work on it, thoughts?

[1]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf
[2]: https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf

Regards,

--
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com