Fix C23 compiler warning

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Fix C23 compiler warning
Date: 2024-10-20 07:07:16
Message-ID: 95c6a9bf-d306-43d8-b880-664ef08f2944@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Commit a67a49648d9 fixed a compiler error under C23. After that, there
is one compiler warning left under C23. It has to do with this in
src/include/nodes/pathnodes.h:

struct IndexOptInfo
{
...
/* AM's cost estimator */
/* Rather than include amapi.h here, we declare amcostestimate like
this */
void (*amcostestimate) () pg_node_attr(read_write_ignore);

This no longer works because in C23, because an empty argument list is
now equivalent to (void), rather than an indeterminate one as before.
And so this results in an incompatible function pointer type and
compiler warnings. (gcc and clang agree on this.)

I think we can fix this easily with a few struct forward declarations,
preserving the goal of not including extra header files, like this:

struct IndexPath;
struct PlannerInfo;

struct IndexOptInfo
{
...
/* AM's cost estimator */
/* Rather than include amapi.h here, we declare amcostestimate like
this */
void (*amcostestimate) (struct PlannerInfo *, struct
IndexPath *, double, Cost *, Cost *, Selectivity *, double *, double *)
pg_node_attr(read_write_ignore);

That way the function pointer has the correct type. This works in older
versions of C as well.

Attachment Content-Type Size
0001-Fix-C23-compiler-warning.patch text/plain 1.6 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andrey M. Borodin 2024-10-20 07:19:45 Re: Using read_stream in index vacuum
Previous Message Michael Paquier 2024-10-20 07:06:42 Re: report a typo in WaitReadBuffers