Re: Cleanup shadows variable warnings, round 1

Chao Li <li.evan.chao@gmail.com>

From: Chao Li <li.evan.chao@gmail.com>
To: Postgres hackers <pgsql-hackers@lists.postgresql.org>
Cc: Peter Eisentraut <peter@eisentraut.org>, Peter Smith <smithpb2250@gmail.com>
Date: 2026-03-03T09:04:47Z
Lists: pgsql-hackers

Attachments


> On Dec 4, 2025, at 17:10, Chao Li <li.evan.chao@gmail.com> wrote:
> 
> 
> 
>> On Dec 4, 2025, at 09:08, Peter Smith <smithpb2250@gmail.com> wrote:
>> 
>> FWIW... A few more review comments for v3.
>> 
>> //////////
>> Patch v3-0001.
>> //////////
> 
> This is actually 0002.
> 
>> 
>> ======
>> src/backend/access/gist/gistbuild.c
>> 
>> 2.1.
>> OK, but should you take it 1 step further?
>> 
>> BEFORE
>> foreach(lc, splitinfo)
>> {
>>  GISTPageSplitInfo *si = lfirst(lc);
>> AFTER
>> foreach_ptr(GISTPageSplitInfo, si, splitinfo)
>> {
>> 
>> ======
>> src/backend/commands/schemacmds.c
>> 
> 
> Fixed.
> 
>> 2.2.
>> OK, but should you take it 1 step further?
>> 
>> BEFORE
>> foreach(parsetree_item, parsetree_list)
>> {
>>  Node    *substmt = (Node *) lfirst(parsetree_item);
>> AFTER
>> foreach_ptr(Node, substmt, parsetree_list)
>> {
>> 
> 
> Fixed.
> 
>> ======
>> src/backend/commands/statscmds.c
>> 
>> 2.3.
>> OK, but I felt 'attnums_bms' might be a better replacement name than 'attnumsbm'
>> 
> 
> Fixed.
> 
>> ======
>> src/backend/executor/nodeValuesscan.c
>> 2.4.
>> OK, but should you take it 1 step further?
>> 
>> BEFORE
>> foreach(lc, exprstatelist)
>> {
>>  ExprState  *exprstate = (ExprState *) lfirst(lc);
>> AFTER
>> foreach_ptr(ExprState, exprstate, exprstatelist)
>> {
>> 
> 
> Fixed.
> 
>> ======
>> src/backend/statistics/dependencies.c
>> 
>> 2.5.
>> The other variable in other parts of this function had names like:
>> clause_expr
>> bool_expr
>> or_expr
>> stat_expr
>> 
>> So, perhaps your new names should be changed slightly to look more
>> similar to those?
>> 
> 
> Fixed.
> 
>> ======
>> src/backend/statistics/extended_stats.c
>> 
>> 2.6.
>> This seems to be in the wrong patch because here you renamed the local
>> var, not the inner one, as the patch commit message says.
>> 
> 
> Moved to 0003.
> 
>> ======
>> src/backend/utils/adt/jsonpath_exec.c
>> 
>> 2.7.
>> Wondering if 'vals' might be a better name than 'foundJV' (there is
>> already another JsonValueList vals elsewhere in this code).
>> 
> 
> Fixed.
> 
>> ======
>> src/bin/pgbench/pgbench.c
>> 
>> 2.8.
>> Wondering if 'nskipped' is a better name than 'skips'.
>> 
> 
> The around variables all use “s”:
> ```
> int64 skips = 0;
> int64 serialization_failures = 0;
> int64 deadlock_failures = 0;
> int64 other_sql_failures = 0;
> int64 retried = 0;
> int64 retries = 0;
> ```
> 
> That’s why I used the “s” form.
> 
> All fixes are in v5.
> 
> Best regards,
> --
> Chao Li (Evan)
> HighGo Software Co., Ltd.
> https://www.highgo.com/
> 
> 
> 
> 
> <v5-0003-cleanup-rename-outer-variables-to-avoid-shadowing.patch><v5-0004-cleanup-fix-macro-induced-variable-shadowing-in-i.patch><v5-0005-cleanup-avoid-local-wal_level-and-wal_segment_siz.patch><v5-0002-cleanup-rename-inner-variables-to-avoid-shadowing.patch><v5-0001-cleanup-rename-loop-variables-to-avoid-local-shad.patch><v5-0007-cleanup-rename-local-progname-variables-to-avoid-.patch><v5-0006-cleanup-avoid-local-variables-shadowed-by-static-.patch><v5-0010-cleanup-avoid-local-variables-shadowed-by-static-.patch><v5-0008-cleanup-avoid-local-variables-shadowed-by-static-.patch><v5-0009-cleanup-avoid-local-variables-shadowed-by-globals.patch><v5-0011-cleanup-rename-local-conn-variables-to-avoid-shad.patch><v5-0012-cleanup-avoid-local-variables-shadowed-by-globals.patch><v5-0013-cleanup-avoid-local-variables-shadowed-by-globals.patch>

Gentle ping as I saw a recent commit cdaa67565867ba443afb66b9e82023d65487dc7c that cleaned up a single occurrence in pg_trgm.

Rebased to v6.

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

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix new-to-v19 -Wshadow warnings

  2. Reduce scope of for-loop-local variables to avoid shadowing

  3. Fix local-variable shadowing in pg_trgm's printSourceNFA().