ilist.h fails cpluspluscheck

Started by Peter Eisentrautabout 13 years ago4 messages
#1Peter Eisentraut
peter_e@gmx.net

In file included from ./src/include/utils/catcache.h:25:0,
from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:
src/include/lib/ilist.h: In function ‘dlist_node* dlist_head_node(dlist_head*)’:
src/include/lib/ilist.h:470:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]
src/include/lib/ilist.h: In function ‘dlist_node* dlist_tail_node(dlist_head*)’:
src/include/lib/ilist.h:487:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]
In file included from ./src/include/utils/catcache.h:25:0,
from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:
src/include/lib/ilist.h: In function ‘slist_node* slist_head_node(slist_head*)’:
src/include/lib/ilist.h:680:39: error: invalid conversion from ‘void*’ to ‘slist_node*’ [-fpermissive]
In file included from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:0:
./src/include/lib/ilist.h: In function ‘dlist_node* dlist_head_node(dlist_head*)’:
./src/include/lib/ilist.h:470:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]
./src/include/lib/ilist.h: In function ‘dlist_node* dlist_tail_node(dlist_head*)’:
./src/include/lib/ilist.h:487:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]
In file included from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:0:
./src/include/lib/ilist.h: In function ‘slist_node* slist_head_node(slist_head*)’:
./src/include/lib/ilist.h:680:39: error: invalid conversion from ‘void*’ to ‘slist_node*’ [-fpermissive]

Maybe some ifndef __cplusplus would help.

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Peter Eisentraut (#1)
Re: ilist.h fails cpluspluscheck

Peter Eisentraut <peter_e@gmx.net> writes:

In file included from ./src/include/utils/catcache.h:25:0,
from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:
src/include/lib/ilist.h: In function ‘dlist_node* dlist_head_node(dlist_head*)’:
src/include/lib/ilist.h:470:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]

Maybe some ifndef __cplusplus would help.

Or maybe we need to recommend use of -fpermissive? If C++ thinks
casting void * to something else is illegitimate, it's basically not
going to cope with most things we might try to inline in Postgres.
And I don't think that saying "you don't get to call these fundamental
support functions from C++" is likely to fly, so just hiding the
functions won't help much.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Andres Freund
andres@2ndquadrant.com
In reply to: Tom Lane (#2)
1 attachment(s)
Re: ilist.h fails cpluspluscheck

On 2012-11-27 01:14:27 -0500, Tom Lane wrote:

Peter Eisentraut <peter_e@gmx.net> writes:

In file included from ./src/include/utils/catcache.h:25:0,
from /tmp/cpluspluscheck.bt8VZr/test.cpp:3:
src/include/lib/ilist.h: In function ‘dlist_node* dlist_head_node(dlist_head*)’:
src/include/lib/ilist.h:470:39: error: invalid conversion from ‘void*’ to ‘dlist_node*’ [-fpermissive]

Maybe some ifndef __cplusplus would help.

Or maybe we need to recommend use of -fpermissive? If C++ thinks
casting void * to something else is illegitimate, it's basically not
going to cope with most things we might try to inline in Postgres.
And I don't think that saying "you don't get to call these fundamental
support functions from C++" is likely to fly, so just hiding the
functions won't help much.

Its rather easy to fix in the ilist code at least - the cases it points
out are those where I took a slightly ugly shortcut to reduce some very
minor code duplication...

Some casts fix it, alternatively the

Assert(!dlist_is_empty());
return head->head.next
could be moved into [ds]list_(head|tail)_node instead of relying on the
*_elemen_off support functions.

Greetings,

Andres

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Attachments:

0001-Fix-some-warnings-in-ilist.h-pointed-out-by-cplusplu.patchtext/x-patch; charset=us-asciiDownload
>From 8089edcc6d448529dbd091ec95a69e138a55efa6 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 27 Nov 2012 10:55:37 +0100
Subject: [PATCH] Fix some warnings in ilist.h pointed out by cpluspluscheck
 via Peter

---
 src/include/lib/ilist.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/include/lib/ilist.h b/src/include/lib/ilist.h
index bc684b8..8f58486 100644
--- a/src/include/lib/ilist.h
+++ b/src/include/lib/ilist.h
@@ -467,7 +467,7 @@ dlist_head_element_off(dlist_head *head, size_t off)
 STATIC_IF_INLINE dlist_node *
 dlist_head_node(dlist_head *head)
 {
-	return dlist_head_element_off(head, 0);
+	return (dlist_node *) dlist_head_element_off(head, 0);
 }
 
 /* internal support function to get address of tail element's struct */
@@ -484,7 +484,7 @@ dlist_tail_element_off(dlist_head *head, size_t off)
 STATIC_IF_INLINE dlist_node *
 dlist_tail_node(dlist_head *head)
 {
-	return dlist_tail_element_off(head, 0);
+	return (dlist_node *) dlist_tail_element_off(head, 0);
 }
 #endif   /* PG_USE_INLINE || ILIST_INCLUDE_DEFINITIONS */
 
@@ -677,7 +677,7 @@ slist_head_element_off(slist_head *head, size_t off)
 STATIC_IF_INLINE slist_node *
 slist_head_node(slist_head *head)
 {
-	return slist_head_element_off(head, 0);
+	return (slist_node *) slist_head_element_off(head, 0);
 }
 #endif   /* PG_USE_INLINE || ILIST_INCLUDE_DEFINITIONS */
 
-- 
1.7.12.289.g0ce9864.dirty

#4Tom Lane
tgl@sss.pgh.pa.us
In reply to: Andres Freund (#3)
Re: ilist.h fails cpluspluscheck

Andres Freund <andres@2ndquadrant.com> writes:

On 2012-11-27 01:14:27 -0500, Tom Lane wrote:

Peter Eisentraut <peter_e@gmx.net> writes:

Maybe some ifndef __cplusplus would help.

Its rather easy to fix in the ilist code at least - the cases it points
out are those where I took a slightly ugly shortcut to reduce some very
minor code duplication...

Some casts fix it,

Seems reasonable, committed.

I wonder if we could get a buildfarm member or two running
cpluspluscheck.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers