Hi,

On Wed, Jan 21, 2026 at 12:31:27PM +0100, Peter Eisentraut wrote:
> On 20.01.26 13:10, Bertrand Drouvot wrote:
> > On Tue, Jan 20, 2026 at 08:54:18AM +0100, Peter Eisentraut wrote:
> > > This patch fixes cases where a qualifier (const, in all cases here) was
> > > dropped by a cast, but the cast was otherwise necessary or desirable, so 
> > > the
> > > straightforward fix is to add the qualifier into the cast.
> > > 
> > > This was checked with gcc -Wcast-qual, but it doesn't fix all such 
> > > warnings,
> > > only the trivially fixable ones.
> > 
> > diff --git a/src/include/varatt.h b/src/include/varatt.h
> > index eccd3ca04d6..03e9d1869aa 100644
> > --- a/src/include/varatt.h
> > +++ b/src/include/varatt.h
> > 
> > It looks like those changes produce:
> > 
> > ../../../src/include/varatt.h: In function ‘VARDATA’:
> > ../../../src/include/varatt.h:261:33: warning: return discards ‘const’ 
> > qualifier from pointer target type [-Wdiscarded-qualifiers]
> >    261 | #define VARDATA_4B(PTR)         (((const varattrib_4b *) 
> > (PTR))->va_4byte.va_data)
> 
> Strange, I don't see that.  What compiler is this, and do you use any
> special options?

It's gcc 14.1.0 with "CFLAGS=-O0 -ggdb3 -fno-omit-frame-pointer -gdwarf-2 -g3
-Wdiscarded-qualifiers -Wunused-value -Werror=maybe-uninitialized
-Werror=format -Wreturn-type"

But I just tested with a simple test case, some compilers and some options and 
I've
always seen the warning (see [1]), so I'm not sure why you don't.

> 
> > Also [1], detected a few more trivially fixable ones (see attached).
> 
> Yes, these should be included.
> 
> The one in spgquadtreeproc.c was #ifdef'ed out, so my testing didn't see it.
> I suppose the other one is only compiled when you run the unicode tests.

Yeah, that could lead to the same "concern" that Tom had in [2] (and using 
a tool like Coccinelle could be an answer).

[1]: https://godbolt.org/z/T9hffKaPW
[2]: 
https://postgr.es/m/aVJCoNqO6ybov7eW%40ip-10-97-1-34.eu-west-3.compute.internal

Regards,

-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com


Reply via email to