From owner-freebsd-bugs@FreeBSD.ORG Mon Jan 10 19:50:05 2005 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 35A3016A4CE for ; Mon, 10 Jan 2005 19:50:05 +0000 (GMT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0B04143D48 for ; Mon, 10 Jan 2005 19:50:05 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.1/8.13.1) with ESMTP id j0AJo4wL062755 for ; Mon, 10 Jan 2005 19:50:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.1/8.13.1/Submit) id j0AJo4Xl062751; Mon, 10 Jan 2005 19:50:04 GMT (envelope-from gnats) Resent-Date: Mon, 10 Jan 2005 19:50:04 GMT Resent-Message-Id: <200501101950.j0AJo4Xl062751@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Dmitrij Tejblum Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id CA91216A4CE for ; Mon, 10 Jan 2005 19:40:42 +0000 (GMT) Received: from developer.yandex.ru (developer.yandex.ru [213.180.193.15]) by mx1.FreeBSD.org (Postfix) with ESMTP id A3B6E43D1F for ; Mon, 10 Jan 2005 19:40:41 +0000 (GMT) (envelope-from tejblum@developer.yandex.ru) Received: from developer.yandex.ru (localhost [127.0.0.1]) by developer.yandex.ru (8.13.1/8.13.1) with ESMTP id j0AJedQT017491 for ; Mon, 10 Jan 2005 22:40:39 +0300 (MSK) (envelope-from tejblum@developer.yandex.ru) Received: (from tejblum@localhost) by developer.yandex.ru (8.13.1/8.13.1/Submit) id j0AJedbx017490; Mon, 10 Jan 2005 22:40:39 +0300 (MSK) (envelope-from tejblum) Message-Id: <200501101940.j0AJedbx017490@developer.yandex.ru> Date: Mon, 10 Jan 2005 22:40:39 +0300 (MSK) From: Dmitrij Tejblum To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Subject: gnu/76069: FreeBSD's definition of offsetof isn't good for C++ X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Dmitrij Tejblum List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 10 Jan 2005 19:50:05 -0000 >Number: 76069 >Category: gnu >Synopsis: FreeBSD's definition of offsetof isn't good for C++ >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jan 10 19:50:04 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Dmitrij Tejblum >Release: FreeBSD 5.3-STABLE i386 >Organization: >Environment: System: FreeBSD developer.yandex.ru 5.3-STABLE FreeBSD 5.3-STABLE #11: Sun Dec 12 06:00:53 MSK 2004 root@developer.yandex.ru:/opt/obj/usr/src/sys/DEVEL i386 >Description: The good old definition of the offsetof macro, found in , leads to various compile problems with G++ 3.4 as supplied by FreeBSD. These problems doesn't exists with "original" version of GCC, it has its own stddef.h. E.g., GCC's stddef.h use special __offsetof__ extension. >How-To-Repeat: Example: the following C++ snippet compiles with original GCC, but doesn't compile with native FreeBSD GCC. ---------------offsetof.cpp----- #include struct A { int a, b; }; enum e { aoff = offsetof(A, a) }; ------------------------------ Compile with c++ -c offsetof.cpp fails with offsetof.cpp:8: error: a casts to a type other than an integral or enumeration type cannot appear in a constant-expression offsetof.cpp:8: error: '->' cannot appear in a constant-expression offsetof.cpp:8: error: &' cannot appear in a constant-expression offsetof.cpp:9: error: enumerator value for `aoff' not integer constant >Fix: The definition of offsetof is basically taken from GCC's stddef.h --- src/sys/sys/cdefs.h Fri Aug 27 17:14:59 2004 +++ src/sys/sys/cdefs.h Mon Jan 10 22:19:30 2005 @@ -240,7 +240,14 @@ * We define this here since , , and * require it. */ +#if defined(__cplusplus) && __GNUC_PREREQ__(3,4) +#define __offsetof(type, field) \ + (__offsetof__ (reinterpret_cast \ + (&reinterpret_cast \ + (static_cast (0)->field)))) +#else #define __offsetof(type, field) ((size_t)(&((type *)0)->field)) +#endif #define __rangeof(type, start, end) \ (__offsetof(type, end) - __offsetof(type, start)) >Release-Note: >Audit-Trail: >Unformatted: