This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/15471] New: Incorrect member pointer offsets in anonymous structs/unions


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]