Const version of castNode() - Mailing list pgsql-hackers

From Andres Freund
Subject Const version of castNode()
Date
Msg-id 20190903084417.z67abhwk5w6ewasy@alap3.anarazel.de
Whole thread Raw
List 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 by date:

Previous
From: Magnus Hagander
Date:
Subject: Re: Improve base backup protocol documentation
Next
From: Swen Kooij
Date:
Subject: Re: Patch to add hook to copydir()