Re: Fix a recent "shadow warning" in subscriptioncmds.c

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Peter Smith <smithpb2250(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix a recent "shadow warning" in subscriptioncmds.c
Date: 2025-11-28 04:49:46
Message-ID: 6E5D4D5A-D614-4AB5-876C-E22EE9BFB6C9@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 28, 2025, at 11:59, Peter Smith <smithpb2250(at)gmail(dot)com> wrote:
>
> I noticed that recently, a shadow warning has crept into the code I am building.
>
> ----------
> subscriptioncmds.c:1125:30: warning: declaration of ‘rel’ shadows a
> previous local [-Wshadow]
> foreach_ptr(SubRemoveRels, rel, sub_remove_rels)
> ^
> ../../../src/include/nodes/pg_list.h:482:20: note: in definition of
> macro ‘foreach_internal’
> for (type pointer var = 0, pointer var##__outerloop = (type pointer) 1; \
> ^
> subscriptioncmds.c:1125:3: note: in expansion of macro ‘foreach_ptr’
> foreach_ptr(SubRemoveRels, rel, sub_remove_rels)
> ^
> subscriptioncmds.c:934:11: warning: shadowed declaration is here [-Wshadow]
> Relation rel = NULL;
> ^
> ----------
>
> This seems to have been introduced recently by the REFRESH SEQUENCES
> commit f0b3573.
>
> IIUC, this particular case is harmless, but IMO it's still worth
> fixing to avoid recurring doubts about potential issues every time it
> appears.
>
> PSA patch v1 to address the warning.
>
> ======
> Kind Regards,
> Peter Smith.
> Fujitsu Australia
> <v1-0001-Fix-shadow-warning-in-subscriptioncmds.c.patch>

The fix just renamed the loop variable name “rel” that hides the other local variable to “sub_remove_rel”, totally makes sense.

I’m just curious why my compile doesn’t warn on that? I am on M4 MacOS 15.6.1, Apple clang 17.0.0.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Soumya S Murali 2025-11-28 04:53:54 Re: [PATCH] Expose checkpoint timestamp and duration in pg_stat_checkpointer
Previous Message Ajin Cherian 2025-11-28 04:46:18 Re: Improve pg_sync_replication_slots() to wait for primary to advance