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]

Legal code rejection: member pointer to non-static member array element



This is a (updated) repost, since the bug never got into gnats nor it's
fixed in 20010103 snapshot.

In fact things have gone even worse since 2.95.2 - older releases accepted
assigning to member pointer from Classname::arrayname but latest snapshot
doesn't allow even that anymore! Now only A reverse kind (g++ used to allow
assigning member offset into non-member pointer when member was an array) of
bug has been fixed and propably that broke line 17 in source below.

Thanks,

Tuukka

-----Original Message-----
From: Tuukka Tikkanen [mailto:tic0@vip.fi]
Sent: Friday, July 28, 2000 6:42 PM
To: gcc-bugs@gcc.gnu.org
Subject: FW: gcc 2.95.2 (g++), member pointer to non-static member array
element

Hello,

G++ does not allow taking member pointer (offset) of member array element,
since
it assumes "&Class::member[]" means taking address (normal) instead of
checking whatever the value is used as member pointer.

Getting this to work would be very useful (and standard conforming :), since
I use it to map textual input names (user input) to class members and in
some cases member array elements.

Tuukka

--- demonstration source ---
class Foo {
public:
  char c1;
  char a[10];
};

int main(int argc, char *argv[])
{
  char Foo::* cp;
  Foo someFoo;

  // Non-array members are OK
  cp = &Foo::c1;
  someFoo.*cp = 42;

  // Following still OK with 2.95.2, fails on latest snapshot
  cp = Foo::a;
  someFoo.*cp = 69;

  // Now the compiler does a bad thing(tm) and misinterprets
  // the expression to mean taking address instead of taking
  // offset (=non-member pointer instead of member pointer).
  cp = &Foo::a[5];
  someFoo.*cp = 0;
}
--- cut here ---

g++     bug.C   -o bug
bug.C: In function `int main(int, char **)':
bug.C:4: member `Foo::a' is non-static but referenced as a static member
bug.C:17: at this point in file      <-- does not happen with 2.95.2
bug.C:4: member `Foo::a' is non-static but referenced as a static member
bug.C:23: at this point in file


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