public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: David Rowley <[email protected]>
Cc: Peter Smith <[email protected]>
Cc: PostgreSQL Hackers <[email protected]>
Subject: Re: Remove shadowed declaration warnings
Date: Wed, 11 Sep 2024 22:02:59 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAApHDvpkr2TdZss4amJGXh0cxVzU+DHpphnmgE89Qazb58Vc6w@mail.gmail.com>
References: <CAHut+Pve+Dyq_piJPG0Ykhn7-gnBsXqge2HQt-baB4i9TJAfnA@mail.gmail.com>
	<CAApHDvpkr2TdZss4amJGXh0cxVzU+DHpphnmgE89Qazb58Vc6w@mail.gmail.com>

David Rowley <[email protected]> writes:
> On Thu, 12 Sept 2024 at 12:33, Peter Smith <[email protected]> wrote:
>> I normally build the code with warnings enabled (specifically,
>> -Wshadow) which exposes many "shadowed" declarations.

> 0fe954c28 did add -Wshadow=compatible-local to the standard set of
> complication flags.  I felt it was diminishing returns after that, but
> -Wshadow=local would be the next step before going full -Wshadow.

I think that insisting that local declarations not shadow globals
is an anti-pattern, and I'll vote against any proposal to make
that a standard warning.  Impoverished as C is, it does have block
structure; why would we want to throw that away by (in effect)
demanding a single flat namespace for the entire program?

I do grant that sometimes shadowing of locals can cause bugs.  I don't
recall right now why we opted for -Wshadow=compatible-local over
-Wshadow=local, but we could certainly take another look at that.

			regards, tom lane






view thread (6+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Remove shadowed declaration warnings
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox