Re: [HACKERS] cast result of copyNode()

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: [HACKERS] cast result of copyNode()
Дата
Msg-id 5922d74e-2a24-10c2-61c2-9070519592ca@2ndquadrant.com
обсуждение исходный текст
Ответ на Re: [HACKERS] cast result of copyNode()  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: [HACKERS] cast result of copyObject()  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Список pgsql-hackers
On 12/31/16 11:56 AM, Tom Lane wrote:
> But doesn't this result in a boatload of warnings on compilers that
> don't have typeof()?

> Also, if your answer is "you shouldn't get any warnings because
> copyObject is already declared to return void *", then why aren't
> we just relying on that today?

Currently, you don't get any warnings, and that would continue to be the
case if a compiler doesn't have typeof().

The casts that are currently there are (apparently) merely for style,
same as casting the result of malloc().

The problem this patch would address is that currently you can write

SomeNode *x = ...;

...


OtherNode *y = copyObject(x);

and there is no notice about that potential mistake.

This patch makes that an error.

If you are sure about what you are doing, you can add a cast.  But
casting the result of copyObject() should be limited to a few specific
cases where the result is assigned to a generic Node * or something like
that.

-- 
Peter Eisentraut              http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: Re: [HACKERS] proposal: session server side variables
Следующее
От: Merlin Moncure
Дата:
Сообщение: Re: [HACKERS] merging some features from plpgsql2 project