I've been writing a C++ extension recently and it turns out that the foreach_ptr macro added in PG17 by one of my patches causes a compilation failure when used in C++. This is due to C++ its stricter rules around implicit casts from void pointers.
Attached is a tiny patch that fixes that by adding an explicit cast to the macro. I think it would be good to backpatch this to PG17 as well, as to not introduce some differences in the macro across versions. (CCed Nathan because he committed the original patch)
From 3c3e94fdb935d71c95cdbee4cfaf971c1a9b93a3 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <github-tech@jeltef.nl> Date: Mon, 14 Oct 2024 21:54:48 +0200 Subject: [PATCH v1] Make foreach_ptr macro work in C++ extensions C++ has stronger requirements on casting from void pointers than C. It turns out that because of this it's impossible to use the foreach_ptr macro in a C++ extension. This additional explicit cast makes it work in both C and C++ extensions. --- src/include/nodes/pg_list.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/nodes/pg_list.h b/src/include/nodes/pg_list.h index 52df93759f..d131350e10 100644 --- a/src/include/nodes/pg_list.h +++ b/src/include/nodes/pg_list.h @@ -485,7 +485,7 @@ for_each_cell_setup(const List *lst, const ListCell *initcell) for (ForEachState var##__state = {(lst), 0}; \ (var##__state.l != NIL && \ var##__state.i < var##__state.l->length && \ - (var = func(&var##__state.l->elements[var##__state.i]), true)); \ + (var = (type pointer) func(&var##__state.l->elements[var##__state.i]), true)); \ var##__state.i++) /* -- 2.43.0