Re: Cleanup shadows variable warnings, round 1
Chao Li <li.evan.chao@gmail.com>
From: Chao Li <li.evan.chao@gmail.com>
To: Peter Smith <smithpb2250@gmail.com>
Cc: Peter Eisentraut <peter@eisentraut.org>,
Postgres hackers <pgsql-hackers@lists.postgresql.org>
Date: 2025-12-03T06:52:14Z
Lists: pgsql-hackers
> On Dec 3, 2025, at 14:42, Peter Smith <smithpb2250@gmail.com> wrote:
>
> Patch v2-0001.
>
> src/backend/backup/basebackup_incremental.c:
> PrepareForIncrementalBackup:
>
> Instead of changing the var name from 'i' to 'u', you can fix this one
> by changing all the for loops to declare 'i' within the 'for ('.
> That way kills two birds with one stone: it removes the shadow warning
> and at the same time improves the scope of the loop variables.
>
>
> - int i;
>
> - for (i = 0; i < num_wal_ranges; ++i)
> + for (int i = 0; i < num_wal_ranges; ++i)
>
> - for (i = 0; i < num_wal_ranges; ++i)
> + for (int i = 0; i < num_wal_ranges; ++i)
>
> - unsigned i;
>
> - for (i = 0; i < nblocks; ++i)
> + for (unsigned i = 0; i < nblocks; ++i)
Unfortunately that doesn’t work for my compiler (clang on MacOS), that’s why I renamed “I" to “u”.
By the way, Peter (S), thank you very much for reviewing.
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 →
-
Fix new-to-v19 -Wshadow warnings
- 4f0cbc6fb5df 19 (unreleased) landed
-
Reduce scope of for-loop-local variables to avoid shadowing
- cece37c9843c 19 (unreleased) landed
-
Fix local-variable shadowing in pg_trgm's printSourceNFA().
- cdaa67565867 19 (unreleased) cited