Re: shadow variables - pg15 edition

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>, Andres Freund <andres(at)anarazel(dot)de>, Justin Pryzby <pryzby(at)telsasoft(dot)com>, pgsql-hackers(at)postgresql(dot)org, Tomas Vondra <tomas(dot)vondra(at)postgresql(dot)org>, Peter Smith <smithpb2250(at)gmail(dot)com>
Subject: Re: shadow variables - pg15 edition
Date: 2022-10-12 01:39:49
Message-ID: Y0Ya5SH0QiaO9kKG@paquier.xyz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Oct 11, 2022 at 01:16:50PM +1300, David Rowley wrote:
> Aside from this issue, if anything I'd be keen to go a little further
> with this and upgrade to -Wshadow=local. The reason being is that I
> noticed that the const qualifier is not classed as "compatible" with
> the equivalently named and typed variable without the const qualifier.
> ISTM that there's close to as much opportunity to mix up two variables
> with the same name that are const and non-const as there are two
> variables with the same const qualifier. However, I'll be waiting for
> the dust to settle on the current flags before thinking any more about
> that.

-Wshadow=compatible-local causes one extra warning in postgres.c with
-DWRITE_READ_PARSE_PLAN_TREES:
postgres.c: In function ‘pg_rewrite_query’:
postgres.c:818:37: warning: declaration of ‘query’ shadows a parameter [-Wshadow=compatible-local]
818 | Query *query = lfirst_node(Query, lc);
| ^~~~~
postgres.c:771:25: note: shadowed declaration is here
771 | pg_rewrite_query(Query *query)
| ~~~~~~~^~~~~

Something like the patch attached would deal with this one.
--
Michael

Attachment Content-Type Size
shadow-warning.patch text/x-diff 792 bytes

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2022-10-12 01:50:58 Re: shadow variables - pg15 edition
Previous Message osumi.takamichi@fujitsu.com 2022-10-12 01:36:04 RE: Allow logical replication to copy tables in binary format