Re: shadow variables - pg15 edition
David Rowley <dgrowleyml@gmail.com>
From: David Rowley <dgrowleyml@gmail.com>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: Justin Pryzby <pryzby@telsasoft.com>, pgsql-hackers@postgresql.org, Tomas Vondra <tomas.vondra@postgresql.org>,
Peter Smith <smithpb2250@gmail.com>
Date: 2022-10-06T20:13:31Z
Lists: pgsql-hackers
On Thu, 6 Oct 2022 at 20:32, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote: > > On 2022-Oct-06, David Rowley wrote: > > I didn't want to do it that way because all this code is in a while > > loop and the outer "now" will be reused after it's set by the code > > above. It's not really immediately obvious to me what repercussions > > that would have, but it didn't seem worth taking any risks. > > No, it's re-initialized to zero every time through the loop, so setting > it to something else at the bottom doesn't have any further effect. Oh yeah, you're right. > If it were *not* reinitialized every time through the loop, then what > would happen is that every iteration in the loop (and each operation > within) would see exactly the same value of "now", because it's only set > "lazily" (meaning, if already set, don't change it.) On my misread, that's what I was afraid of changing, but now seeing that now = 0 at the start of each loop, I understand that pg_time_now_lazy will get an up-to-date time on each loop. I'm happy if you want to change it to use the outer scoped variable instead of the now2 one. David
Commits
-
Fix shadow variable in postgres.c
- 4574eb9d38c6 16.0 landed
-
Add -Wshadow=compatible-local to the standard compilation flags
- 0fe954c28584 16.0 landed
-
Fix final warnings produced by -Wshadow=compatible-local
- cd4e8caaa0eb 16.0 landed
-
Fix final compiler warning produced by -Wshadow=compatible-local
- d8df67bb1ad9 16.0 landed
-
Add optional parameter to PG_TRY() macros
- 112f0225dbfe 16.0 landed
-
Small refactor to get rid of -Wshadow=compatible-local warning
- d389487525bc 16.0 landed
-
More -Wshadow=compatible-local warning fixes
- 3e0fff2e6888 16.0 landed
-
Further -Wshadow=compatible-local warning fixes
- f959bf9a5b9c 16.0 landed
-
Further reduce warnings with -Wshadow=compatible-local
- 421892a192b8 16.0 landed
-
Reduce warnings with -Wshadow=compatible-local builds
- 92fce4e1eda9 16.0 landed
-
Remove shadowed local variables that are new in v15
- 24f457aa2b70 15.0 landed
- f01592f91577 16.0 landed