gcc 2.95.2 (g++), member pointer to non-static member array element
Tuukka Tikkanen
tic0@vip.fi
Fri Jul 28 08:36:00 GMT 2000
(Seems like the bug submission address in documentation is out of date, so
I'll just blatantly toss this report on to gcc@gcc.gnu.org and hope
maintainers catch it there.)
Hello,
it seems 2.95.2 (and older egcs 1.1.2) release has an interesting bug and
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 c2;
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;
// (another)
cp = &Foo::c2;
someFoo.*cp = 13;
// Following still OK... no subscription
cp = Foo::a;
someFoo.*cp = 69;
// Now the compiler does a bad thing(tm) and misinterprets
// the expression to mean taking address (illegal) instead
// of taking offset.
cp = &Foo::a[5];
someFoo.*cp = 0;
}
--- cut here ---
g++ bug.C -o bug
bug.C: In function `int main(int, char **)':
bug.C:5: member `Foo::a' is non-static but referenced as a static member
bug.C:21: at this point in file
gcc version 2.95.2 19991024 (release)
More information about the Gcc
mailing list