public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/19605] New: Wrong member offset in inherited classes
@ 2005-01-24 14:52 peter at os dot inf dot tu-dresden dot de
2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: peter at os dot inf dot tu-dresden dot de @ 2005-01-24 14:52 UTC (permalink / raw)
To: gcc-bugs
gcc-4.0 returns incorrect class relative offsets for members
Following:
1. example program producing the error
2. console output for gcc 4.0 (incorrect) and gcc 3.2 (correct)
============================================================
#include <cstdio>
#include <iostream>
#define GET_MEMBER_PTR(type,member) \
({ \
void *type::*p = (void *type::*) &type::member; \
&(((type *) 0)->*p); \
})
using std::endl;
using std::cout;
class A
{
public:
unsigned a;
unsigned b;
};
class B
{
public:
unsigned c;
unsigned d;
};
class C
{
public:
unsigned e;
unsigned f;
};
class D : public A, public B, public C
{
public:
unsigned g;
unsigned h;
};
int
main(void)
{
cout << "a: " << GET_MEMBER_PTR(D, a) << endl;
cout << "b: " << GET_MEMBER_PTR(D, b) << endl;
cout << "c: " << GET_MEMBER_PTR(D, c) << endl;
cout << "d: " << GET_MEMBER_PTR(D, d) << endl;
cout << "e: " << GET_MEMBER_PTR(D, e) << endl;
cout << "f: " << GET_MEMBER_PTR(D, f) << endl;
cout << "g: " << GET_MEMBER_PTR(D, g) << endl;
cout << "h: " << GET_MEMBER_PTR(D, h) << endl;
return 0;
}
===================================================
peter@erwin:~/t5> /usr/local/gcc/head/bin/g++ -v
Using built-in specs.
Configured with: ../gcc/configure --prefix=/usr/local/gcc/head --enable-__cxa_atexit
Thread model: posix
gcc version 4.0.0 20050123 (experimental)
peter@erwin:~/t5> /usr/local/gcc/head/bin/g++ --static -o c.4.x c.cc
peter@erwin:~/t5> ./c.4.x
a: 0
b: 0x4
c: 0
d: 0x4
e: 0
f: 0x4
g: 0x18
h: 0x1c
peter@erwin:~/t5> g++-3.2 -v
Reading specs from /usr/lib/gcc-lib/i386-linux/3.2.3/specs
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr
--mandir=/usr/share/man --infodir=/usr/share/info
--with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib
--enable-nls --without-included-gettext --enable-__cxa_atexit
--enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
Thread model: posix
gcc version 3.2.3
peter@erwin:~/t5> g++-3.2 -o c.3.x c.cc
peter@erwin:~/t5> ./c.3.x
a: 0
b: 0x4
c: 0x8
d: 0xc
e: 0x10
f: 0x14
g: 0x18
h: 0x1c
--
Summary: Wrong member offset in inherited classes
Product: gcc
Version: 4.0.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: peter at os dot inf dot tu-dresden dot de
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
@ 2005-01-24 14:56 ` pinskia at gcc dot gnu dot org
2005-01-24 15:02 ` [Bug c++/19605] [4.0 Regression] " pinskia at gcc dot gnu dot org
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-24 14:56 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-24 14:56 -------
&(((type *) 0)->*p);
That is not offsetof any more.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] [4.0 Regression] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
@ 2005-01-24 15:02 ` pinskia at gcc dot gnu dot org
2005-01-24 15:04 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-24 15:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-24 15:02 -------
Someone else has to say if this is valid C++ but I think it is just undefined but I could be wrong.
--
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Summary|Wrong member offset in |[4.0 Regression] Wrong
|inherited classes |member offset in inherited
| |classes
Target Milestone|--- |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] [4.0 Regression] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
2005-01-24 15:02 ` [Bug c++/19605] [4.0 Regression] " pinskia at gcc dot gnu dot org
@ 2005-01-24 15:04 ` pinskia at gcc dot gnu dot org
2005-01-24 15:12 ` fm3 at os dot inf dot tu-dresden dot de
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-01-24 15:04 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-01-24 15:04 -------
Also one note is that 3.4.0 produces the same as 3.2.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] [4.0 Regression] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
` (2 preceding siblings ...)
2005-01-24 15:04 ` pinskia at gcc dot gnu dot org
@ 2005-01-24 15:12 ` fm3 at os dot inf dot tu-dresden dot de
2005-01-26 4:12 ` bangerth at dealii dot org
2005-01-29 0:01 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: fm3 at os dot inf dot tu-dresden dot de @ 2005-01-24 15:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From fm3 at os dot inf dot tu-dresden dot de 2005-01-24 15:12 -------
added myself as cc
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |fm3 at os dot inf dot tu-
| |dresden dot de
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] [4.0 Regression] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
` (3 preceding siblings ...)
2005-01-24 15:12 ` fm3 at os dot inf dot tu-dresden dot de
@ 2005-01-26 4:12 ` bangerth at dealii dot org
2005-01-29 0:01 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: bangerth at dealii dot org @ 2005-01-26 4:12 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bangerth at dealii dot org 2005-01-26 04:12 -------
This is certainly undefined code: you are dereferencing the Null pointer.
It's a different matter of QoI whether we want to support this anyway.
It's basically a different way to say offsetof, an area in which I believe
Nathan has considerable experience.
W.
--
What |Removed |Added
----------------------------------------------------------------------------
CC| |nathan at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c++/19605] [4.0 Regression] Wrong member offset in inherited classes
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
` (4 preceding siblings ...)
2005-01-26 4:12 ` bangerth at dealii dot org
@ 2005-01-29 0:01 ` mmitchel at gcc dot gnu dot org
5 siblings, 0 replies; 7+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2005-01-29 0:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From mmitchel at gcc dot gnu dot org 2005-01-29 00:00 -------
This is undefined behavior, and it is not worthwhile to try to make this work.
There are existing ways (offsetof and poiners-to-members) to accomplish what the
submitter wants to do.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19605
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-01-29 0:01 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-24 14:52 [Bug c++/19605] New: Wrong member offset in inherited classes peter at os dot inf dot tu-dresden dot de
2005-01-24 14:56 ` [Bug c++/19605] " pinskia at gcc dot gnu dot org
2005-01-24 15:02 ` [Bug c++/19605] [4.0 Regression] " pinskia at gcc dot gnu dot org
2005-01-24 15:04 ` pinskia at gcc dot gnu dot org
2005-01-24 15:12 ` fm3 at os dot inf dot tu-dresden dot de
2005-01-26 4:12 ` bangerth at dealii dot org
2005-01-29 0:01 ` mmitchel at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).