From owner-freebsd-current@FreeBSD.ORG Mon Oct 4 14:19:45 2004 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 1F32A16A4CE for ; Mon, 4 Oct 2004 14:19:45 +0000 (GMT) Received: from sccmmhc91.asp.att.net (sccmmhc91.asp.att.net [204.127.203.211]) by mx1.FreeBSD.org (Postfix) with ESMTP id BB6B143D49 for ; Mon, 4 Oct 2004 14:19:44 +0000 (GMT) (envelope-from patrick@137.org) Received: from morpheus.infiscape.com ([12.216.47.168]) by sccmmhc91.asp.att.net (sccmmhc91) with ESMTP id <20041004141941m9100iptv2e>; Mon, 4 Oct 2004 14:19:41 +0000 Received: from dsl.80.187.networkiowa.com (dsl.80.187.networkiowa.com [209.234.80.187]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by morpheus.infiscape.com (Postfix) with ESMTP id 13D77390014 for ; Mon, 4 Oct 2004 09:19:41 -0500 (CDT) From: Patrick Hartling To: freebsd-current@freebsd.org In-Reply-To: <1096851735.869.18.camel@dsl.80.187.networkiowa.com> References: <1096851735.869.18.camel@dsl.80.187.networkiowa.com> Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="=-CeBMepCzE2rwZxhzAKk6" Date: Mon, 04 Oct 2004 09:18:18 -0500 Message-Id: <1096899498.16314.2.camel@dsl.80.187.networkiowa.com> Mime-Version: 1.0 X-Mailer: Evolution 2.0.0FreeBSD GNOME Team Port Subject: Re: offsetof() macro, C++, and GCC 3.4.2 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 04 Oct 2004 14:19:45 -0000 --=-CeBMepCzE2rwZxhzAKk6 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable At Joseph Koshy's request, this is now filed as misc/72307. -Patrick On Sun, 2004-10-03 at 20:02 -0500, Patrick Hartling wrote: > The offsetof() macro defined in stddef.h evaluates to code that can > violate the C++ standard depending upon the context of its use. I have > attached code that demonstrates the problem. GCC 3.4.2 in the base > system refuses to compile the code, giving this error message: >=20 > % g++ -c const-exp.cpp > const-exp.cpp:14: error: a casts to a type other than an integral or > enumeration type cannot appear in a constant-expression > const-exp.cpp:14: error: '->' cannot appear in a constant-expression > const-exp.cpp:14: error: `&' cannot appear in a constant-expression >=20 > The gcc34 port (gcc-3.4.2_20040827) builds it just fine. The > difference, as far as I can tell, is that gcc34 from the Ports > Collection gets offsetof() from its own stddef.h, which has C++-friendly > code: >=20 > /* Offset of member MEMBER in a struct of type TYPE. */ > #ifndef __cplusplus > #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) > #else > /* The cast to "char &" below avoids problems with user-defined > "operator &", which can appear in a POD type. */ > #define offsetof(TYPE, MEMBER) \ > (__offsetof__ (reinterpret_cast \ > (&reinterpret_cast \ > (static_cast (0)->MEMBER)))) > #endif /* C++ */ >=20 > Would fixing this problem be as simple as using the above code > in /usr/include/stddef.h? >=20 > The attached code was adapted from some very similar code in > Boost.Python (from the file boost/python/object/instance.hpp), which > does not compile with the base system GCC 3.4.2. There may be other > parts of Boost 1.31.0--and the upcoming Boost 1.32.0--that are affected > by this offsetof() problem. >=20 > -Patrick >=20 >=20 --=20 Patrick L. Hartling | Research Assistant, VRAC http://www.137.org/patrick/ | 2274 Howe Hall Room 2624 PGP: http://tinyurl.com/2oum9 | http://www.vrac.iastate.edu/ --=-CeBMepCzE2rwZxhzAKk6 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.6 (FreeBSD) iD8DBQBBYVuqwZ1qaMh08hcRAuT6AJ9/s096Jf4K2iwX144IQf/6qa8wFwCeME4R juPXrBSb8WGPa5fdFPzl9MU= =csgn -----END PGP SIGNATURE----- --=-CeBMepCzE2rwZxhzAKk6--