Re: -Wcast-qual cleanup, part 1 - Mailing list pgsql-hackers

From Tom Lane
Subject Re: -Wcast-qual cleanup, part 1
Date
Msg-id 24642.1320678470@sss.pgh.pa.us
Whole thread Raw
In response to Re: -Wcast-qual cleanup, part 1  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: -Wcast-qual cleanup, part 1
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Nov 7, 2011 at 12:13 AM, Peter Eisentraut <peter_e@gmx.net> wrote:
>>  typedef struct ErrorContextCallback
>>  {
>>      struct ErrorContextCallback *previous;
>> -    void        (*callback) (void *arg);
>> -    void       *arg;
>> +    void        (*callback) (const void *arg);
>> +    const void   *arg;
>>  } ErrorContextCallback;

> Why should the callback be forced to treat its private argument as const?

Yes, the above seems like a seriously bad idea.  It's probably true that
most existing callbacks could afford to declare their callback args as
const, but it does not follow that we should legislate that in the API.
All that that will accomplish is to move the need to cast away const
from some places to some other places.

>>  #define XLogRecGetData(record)    ((char*) (record) + SizeOfXLogRecord)
>> +#define XLogRecGetConstData(record)    ((const char*) (record) + SizeOfXLogRecord)

> IMHO, this is an example of everything that's wrong with const.

Yes, this seems pretty horrid as well.  Not so much just the one instance
as the implications of this sweeping requirement:

>> 2. Macros accessing  structures should come in two variants: a "get"
>> version, and a "set"/anything else version, so that the "get" version
>> can preserve the const qualifier.

I'm not prepared to buy into that as a general coding rule.

Maybe it would be better to just add -Wno-cast-qual to CFLAGS.
        regards, tom lane


pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: synchronous commit vs. hint bits
Next
From: Tom Lane
Date:
Subject: Re: synchronous commit vs. hint bits