From: | Andres Freund <andres(at)anarazel(dot)de> |
---|---|
To: | pgsql-hackers(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net> |
Subject: | Const version of castNode() |
Date: | 2019-09-03 08:44:17 |
Message-ID: | 20190903084417.z67abhwk5w6ewasy@alap3.anarazel.de |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Swen Kooij | 2019-09-03 09:14:28 | Re: Patch to add hook to copydir() |
Previous Message | Magnus Hagander | 2019-09-03 07:50:44 | Re: Improve base backup protocol documentation |