Const version of castNode()

Поиск
Список
Период
Сортировка
От Andres Freund
Тема Const version of castNode()
Дата
Msg-id 20190903084417.z67abhwk5w6ewasy@alap3.anarazel.de
обсуждение исходный текст
Список pgsql-hackers
Hi,

Right now, when assertions are enabled, using castNode() on a pointer to
const triggers a warning for my compilers:
warning: passing argument 2 of ‘castNodeImpl’ discards ‘const’ qualifier from pointer target type
[-Wdiscarded-qualifiers]

which seems appropriate. Obviously we could easily suppress that just by
adding an explicit cast into the castNode definition or to the
caller. But it strikes me as a somewhat legitimate warning.

On gcc etc we could fairly easily reformulate castNodeImpl() to not
trigger the above warning, but we'd still cast constness away due to the
return type cast.

#ifdef USE_ASSERT_CHECKING
...
#define castNode(_type_, nodeptr) ((_type_ *) castNodeImpl(T_##_type_, nodeptr))
#else
#define castNode(_type_, nodeptr) ((_type_ *) (nodeptr))
#endif                            /* USE_ASSERT_CHECKING */

ISTM adding a castConstNode or castNodeConst would make sense?

Greetings,

Andres Freund



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

Предыдущее
От: Magnus Hagander
Дата:
Сообщение: Re: Improve base backup protocol documentation
Следующее
От: Swen Kooij
Дата:
Сообщение: Re: Patch to add hook to copydir()