Add pg_nodiscard decorations to Bitmapset functions
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
This thread has been committed, so CI has stopped here. Anything below is the last result it produced.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t253712psql -h localhost -U postgresBuilt from patchset v1 (message #1), September 09, 2026 at 03:25 PM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t253712_1 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t253712_1 && git checkout t253712_1Patchset v1 (message #1) is on t253712_1
Hi Hackers,
The functions in bitmapset.h that return a Bitmapset * either build a
new set or recycle their input, so ignoring the return value is always a
bug.
Commit c617aea6acd introduced the macro pg_nodiscard, which generates a
compiler warning when the result of a function call is ignored. The List
functions in pg_list.h have the same requirement, and commit a378ba49a5c
added pg_nodiscard to most of them.
However, bitmapset.h was never adjusted. The attached patch adds
pg_nodiscard to all functions there that return a Bitmapset *.
This patch does not make REALLOCATE_BITMAPSETS redundant.
REALLOCATE_BITMAPSETS reallocates the set on every modification, so a
stale pointer to the old set is likely to be noticed. However, only at
runtime and only in builds that enable it. pg_nodiscard catches the
simpler case of dropping the return value entirely at compile time.
Best regards
Jan
--
Jan Nidzwetzki
PlanetScale Postgres Core Team
On Tue, Sep 08, 2026 at 05:13:08PM +0200, Jan Nidzwetzki wrote:
The functions in bitmapset.h that return a Bitmapset * either build a
new set or recycle their input, so ignoring the return value is always a
bug.Commit c617aea6acd introduced the macro pg_nodiscard, which generates a
compiler warning when the result of a function call is ignored. The List
functions in pg_list.h have the same requirement, and commit a378ba49a5c
added pg_nodiscard to most of them.However, bitmapset.h was never adjusted. The attached patch adds
pg_nodiscard to all functions there that return a Bitmapset *.
This seems generally reasonable to me. In fact, it looks like this idea
was brought up and then deferred during some other Bitmapset work earlier
in the year [0]/messages/by-id/3432490.1776524971@sss.pgh.pa.us.
[0]: /messages/by-id/3432490.1776524971@sss.pgh.pa.us
--
nathan