Re: Remove shadowed declaration warnings - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Remove shadowed declaration warnings
Date
Msg-id 3935878.1726106579@sss.pgh.pa.us
Whole thread Raw
In response to Re: Remove shadowed declaration warnings  (David Rowley <dgrowleyml@gmail.com>)
Responses Re: Remove shadowed declaration warnings
List pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes:
> On Thu, 12 Sept 2024 at 12:33, Peter Smith <smithpb2250@gmail.com> 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



pgsql-hackers by date:

Previous
From: David Rowley
Date:
Subject: Re: Remove useless GROUP BY columns considering unique index
Next
From: Tatsuo Ishii
Date:
Subject: Re: Add memory/disk usage for WindowAgg nodes in EXPLAIN