Re: Fix shadow warnings in logical replication code

Michael Paquier <michael@paquier.xyz>

From: Michael Paquier <michael@paquier.xyz>
To: Peter Smith <smithpb2250@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2023-08-30T00:48:48Z
Lists: pgsql-hackers
On Wed, Aug 30, 2023 at 09:16:38AM +1000, Peter Smith wrote:
> logicalfuncs.c:184:13: warning: declaration of ‘name’ shadows a
> previous local [-Wshadow]
>     char    *name = TextDatumGetCString(datum_opts[i]);
>              ^
> logicalfuncs.c:105:8: warning: shadowed declaration is here [-Wshadow]
>   Name  name;

A bit confusing here, particularly as the name is reused with
ReplicationSlotAcquire() at the end of
pg_logical_slot_get_changes_guts() once again.

> reorderbuffer.c:4843:10: warning: declaration of ‘isnull’ shadows a
> previous local [-Wshadow]
>     bool  isnull;
>           ^
> reorderbuffer.c:4734:11: warning: shadowed declaration is here [-Wshadow]
>   bool    *isnull;
>            ^

Agreed as well about this one.

> walsender.c:3543:14: warning: declaration of ‘sentPtr’ shadows a
> global declaration [-Wshadow]
>    XLogRecPtr sentPtr;
>               ^
> walsender.c:155:19: warning: shadowed declaration is here [-Wshadow]
>  static XLogRecPtr sentPtr = InvalidXLogRecPtr;
>                    ^

This one looks pretty serious to me, particularly as the static
sentPtr is used quite a bit.  It is fortunate that the impact is
limited to the WAL sender stat function.

Fixing all these seems like a good thing in the long term, so OK for
me.  Like all the fixes similar to this one, I don't see a need for a
backpatch based on their locality, even if sentPtr makes me a bit
nervous to keep even in stable branches.

There is much more going on with -Wshadow, but let's do things
incrementally, case by case.
--
Michael

Commits

  1. Fix some shadow variables in src/backend/replication/