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.

From 3be558bf4971904cd67cd9d80a5e2f52b66082b0 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <pe...@eisentraut.org>
Date: Sun, 20 Oct 2024 08:10:30 +0200
Subject: [PATCH] Fix C23 compiler warning

The approach of declaring a function pointer with an empty argument
list and hoping that the compiler will not complain about casting it
to another type no longer works with C23, because foo() is now
equivalent to foo(void).

We don't need to do this here.  With a few struct forward declarations
we can supply a correct argument list without having to pull in
another header file.

(This is the only new warning with C23.  Together with the previous
fix a67a49648d9, this makes the whole code compile cleanly under C23.)
---
 src/include/nodes/pathnodes.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/include/nodes/pathnodes.h b/src/include/nodes/pathnodes.h
index 07e2415398e..464c79c73a5 100644
--- a/src/include/nodes/pathnodes.h
+++ b/src/include/nodes/pathnodes.h
@@ -1107,6 +1107,9 @@ typedef struct IndexOptInfo IndexOptInfo;
 #define HAVE_INDEXOPTINFO_TYPEDEF 1
 #endif
 
+struct IndexPath;
+struct PlannerInfo;
+
 struct IndexOptInfo
 {
        pg_node_attr(no_copy_equal, no_read, no_query_jumble)
@@ -1206,7 +1209,7 @@ struct IndexOptInfo
        bool            amcanmarkpos;
        /* AM's cost estimator */
        /* Rather than include amapi.h here, we declare amcostestimate like 
this */
-       void            (*amcostestimate) () pg_node_attr(read_write_ignore);
+       void            (*amcostestimate) (struct PlannerInfo *, struct 
IndexPath *, double, Cost *, Cost *, Selectivity *, double *, double *) 
pg_node_attr(read_write_ignore);
 };
 
 /*
-- 
2.47.0

Reply via email to