Invalid this pointer on operators with anonymous unions.
Karl Nelson
kenelson@ece.ucdavis.edu
Mon Jul 26 12:03:00 GMT 1999
Problem description:
On all versions of egcs and gcc the following code will incorrectly
report the this pointer as the pointer of the parent and not the
child when an operator is called. The error seems only to occur
when the child is a member of an anonymous union. The error
does not occur on function calls, just operators. This is
a relatively urgent problem as several libraries I am writting
depend on proper behaviour of anonymous unions.
Affected platforms and versions:
HP, Sun, Linux, IRIX. (basically all)
gcc 2.8 - egcs 1.1.2 all tested bad.
Switchs needed to cause error:
None. Default behavior demonstrate error.
Program:
------------------------------------------------------------------
#include <iostream>
struct Bob;
struct Fred
{
Bob *b;
void emit() {cout << "this:" <<this << " obj:"<<b<<endl;}
void operator()() {cout << "this:" <<this << " obj:"<<b<<endl;}
};
struct Bob
{
int i;
int j;
union {
Bob *self;
Fred fred;
};
Bob():self(this) {}
};
main()
{
Bob bob;
bob.fred.emit();
bob.fred();
}
------------------------------------------------------------------
Sample Output:
(HP-UX 10.2 running egcs-2.91.57)
this:0x7b03ad30 obj:0x7b03ad28
this:0x7b03ad28 obj:0
These lines should match as operators and functions should be
identical.
--Karl Nelson
Gtk-- Co-Maintainer
More information about the Gcc-bugs
mailing list