Make foreach_ptr macro work in C++ extensions

Jelte Fennema-Nio <postgres@jeltef.nl>

From: Jelte Fennema-Nio <postgres@jeltef.nl>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Nathan Bossart <nathandbossart@gmail.com>
Date: 2024-10-14T20:05:42Z
Lists: pgsql-hackers

Attachments

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)

Commits

  1. Add type cast to foreach_internal's loop variable.