This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions
- From: "us15 at os dot inf dot tu-dresden dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 May 2004 21:39:49 -0000
- Subject: [Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The code below outputs the addresses of member variables of class "myclass"
using a table of pointers to member variables and using an instance of
"myclass". I'd expect both methods to produce the same result, however, the
addresses of member variables x and y are wrong when applying the member
pointers to object "foo".
Compiler version:
Reading specs from /usr/lib/gcc/i486-slackware-linux/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --prefix=/usr --enable-shared
--enable-threads=posix --enable-__cxa_atexit --disable-checking --with-gnu-ld
--verbose --target=i486-slackware-linux --host=i486-slackware-linux
Thread model: posix
gcc version 3.4.0
Example code to demonstrate the problem:
#include <stdio.h>
class myclass
{
public:
union
{
unsigned state[5];
struct
{
unsigned a;
unsigned b;
union
{
unsigned nums[2];
struct
{
unsigned x, y;
};
};
unsigned c;
};
};
};
unsigned
myclass::*
members[] = {
&myclass::a,
&myclass::b,
&myclass::x,
&myclass::y,
&myclass::c,
};
myclass
foo;
int
main (void)
{
printf ("a -> %p %p\n", &(foo.*members[0]), &foo.a);
printf ("b -> %p %p\n", &(foo.*members[1]), &foo.b);
printf ("x -> %p %p\n", &(foo.*members[2]), &foo.x); // differs
printf ("y -> %p %p\n", &(foo.*members[3]), &foo.y); // differs
printf ("c -> %p %p\n", &(foo.*members[4]), &foo.c);
return 0;
}
--
Summary: Incorrect member pointer offsets in anonymous
structs/unions
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: us15 at os dot inf dot tu-dresden dot de
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: n/a
GCC host triplet: i486-slackware-linux
GCC target triplet: i486-slackware-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15471