Re: Fix accidentally cast away qualifiers - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: Fix accidentally cast away qualifiers
Date
Msg-id e9088f15-d3f1-464e-a6e6-7c7fd94b909b@eisentraut.org
Whole thread Raw
In response to Re: Fix accidentally cast away qualifiers  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: Fix accidentally cast away qualifiers
List pgsql-hackers
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?

> 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.




pgsql-hackers by date:

Previous
From: shveta malik
Date:
Subject: Re: Skipping schema changes in publication
Next
From: Peter Eisentraut
Date:
Subject: Re: enable fallthrough warnings on clang