Re: Use func(void) for functions with no parameters

From: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Matthias van de Meent <boekewurm+postgres(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Use func(void) for functions with no parameters
Date: 2025-12-04 10:04:37
Message-ID: aTFctZwWSpl2/LG5@ip-10-97-1-34.eu-west-3.compute.internal
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Wed, Dec 03, 2025 at 11:32:10PM -0500, Tom Lane wrote:
> Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)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

Attachment Content-Type Size
v1-0001-Suppress-strict-prototypes-warnings-from-readline.patch text/x-diff 1.2 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2025-12-04 10:18:33 Re: Remove unused function parameters, part 2: replication
Previous Message Maxim Orlov 2025-12-04 10:03:23 Re: POC: make mxidoff 64 bits