[jfw@mango.com: bug with offsetof in egcs-1.1.2]

Jason Molenda jsm@cygnus.com
Wed Apr 21 16:12:00 GMT 1999


Hi, I created a small mailing list hiccup.  You may have seen 4-8 old
(~1997) mail messages sent to egcs-bugs.  It is now fixed.  There were
two notes sent to egcs-bugs that were not distributed to everyone, this
is the first.

----- Forwarded message from "John F. Woods" <jfw@mango.com> -----

From: "John F. Woods" <jfw@mango.com>
To: egcs-bugs@egcs.cygnus.com
Cc: "John F. Woods" <jfw@mango.com>
Subject: bug with offsetof in egcs-1.1.2
Date: Wed, 21 Apr 1999 18:39:09 -0400
X-Mailer: Internet Mail Service (5.5.2232.9)

The following C++ program:

	class thing_one {
	public:
	  int one;
	};
	class thing_two {
	public:
	  int two;
	};

	class things : public thing_one, public thing_two {
	  friend class morething;
	  int stuff;
	};

	class morething : public things {
	  static size_t OffsetTwo() { return offsetof(morething, two); }
	};

gets the error message "t.cxx:18: invalid reference to NULL ptr, use
ptr-to-member instead" trying to compile the OffsetTwo() function.  I
*think* this is valid C++; the official rules for offsetof() and POD-structs
are irritatingly dense, but there are no pointers-to-members in the
structures here, so I think these are legal inputs to offsetof.  (Visual C--
compiles this code with no complaint, but that's little comfort.)

Here is the compiler's -v output:

[jfw@anvil jfw]$ c++ -v --save-temps -c t.cxx
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cpp -lang-c++ -v -undef
-D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix
-Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__
-__linux__ -D__unix -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS
-Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -__i386__ t.cxx
t.ii
GNU CPP version egcs-2.91.66 19990314 (egcs-1.1.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/local/include
 /usr/i386-redhat-linux/include
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.91.66/cc1plus t.ii -quiet
-dumpbase t.cc -version -o t.s
GNU C++ version egcs-2.91.66 19990314 (egcs-1.1.2 release)
(i386-redhat-linux) compiled by GNU C version egcs-2.91.66 9990314
(egcs-1.1.2 release).
t.cxx: In function `static size_t morething::OffsetTwo()':
t.cxx:18: invalid reference to NULL ptr, use ptr-to-member instead


----- End forwarded message -----


More information about the Gcc-bugs mailing list