Skip to content

Fix build warnings against PG 16+ - #526

Open
devrimgunduz wants to merge 1 commit into
2ndQuadrant:REL2_x_STABLEfrom
devrimgunduz:REL2_x_STABLE
Open

devrimgunduz wants to merge 1 commit into
2ndQuadrant:REL2_x_STABLEfrom
devrimgunduz:REL2_x_STABLE

Conversation

@devrimgunduz

Copy link
Copy Markdown

PG_ENSURE_ERROR_CLEANUP()/PG_END_ENSURE_ERROR_CLEANUP(), as defined in storage/ipc.h, expand to a plain PG_TRY()/PG_CATCH()/PG_END_TRY() with no suffix argument. Nesting two such blocks in the same function (as happens below, in pglogical_sync_subscription()) makes the inner block's PG_TRY()-generated locals shadow the outer block's, which trips -Wshadow=compatible-local on modern gcc. This is purely cosmetic: each PG_TRY() only ever touches its own copy of the saved exception/context stack, so the shadowing has no runtime effect.

As of PG 16, core's PG_TRY()/PG_CATCH()/PG_END_TRY() accept an optional suffix argument specifically to let nested blocks use distinct variable names and silence this warning -- but PG_ENSURE_ERROR_CLEANUP() itself doesn't forward that suffix through. On PG 16+ we define local wrappers that do. On PG 14/15, PG_TRY() and friends take no arguments at all, so there's no way to avoid the warning short of restructuring the code (e.g. moving the inner block into a separate function); we just fall back to the plain core macros there and accept the harmless warning.

These wrappers can be removed if/when upstream teaches PG_ENSURE_ERROR_CLEANUP() to forward a suffix through itself on all still-supported branches.

Hacked by Claude, tested by me.

PG_ENSURE_ERROR_CLEANUP()/PG_END_ENSURE_ERROR_CLEANUP(), as defined in
storage/ipc.h, expand to a plain PG_TRY()/PG_CATCH()/PG_END_TRY() with no
suffix argument.  Nesting two such blocks in the same function (as
happens below, in pglogical_sync_subscription()) makes the inner block's
PG_TRY()-generated locals shadow the outer block's, which trips
-Wshadow=compatible-local on modern gcc.  This is purely cosmetic: each
PG_TRY() only ever touches its own copy of the saved exception/context
stack, so the shadowing has no runtime effect.

As of PG 16, core's PG_TRY()/PG_CATCH()/PG_END_TRY() accept an optional
suffix argument specifically to let nested blocks use distinct variable
names and silence this warning -- but PG_ENSURE_ERROR_CLEANUP() itself
doesn't forward that suffix through. On PG 16+ we define local wrappers
that do. On PG 14/15, PG_TRY() and friends take no arguments at all, so
there's no way to avoid the warning short of restructuring the code (e.g.
moving the inner block into a separate function); we just fall back to
the plain core macros there and accept the harmless warning.

These wrappers can be removed if/when upstream teaches
PG_ENSURE_ERROR_CLEANUP() to forward a suffix through itself on all
still-supported branches.

Hacked by Claude, tested by me.
@eulerto

eulerto commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants