Thread View: gnu.g++.bug
1 messages
1 total messages
Started by "Douglas C. Schmidt"
Wed, 25 Jan 1989 22:41
Bug with bitwise copying of classes.
Author: "Douglas C. Schmidt"
Date: Wed, 25 Jan 1989 22:41
Date: Wed, 25 Jan 1989 22:41
53 lines
1547 bytes
1547 bytes
Hi,
I believe the following is a rather subtle and pernicious bug with
g++ 1.32. According to the USENIX Lime book, pages 10-11, assignment
in C++ is now defined as memberwise assignment of non-static members
and base class objects, rather than bitwise copy. Therefore, the
following program appears to be in error:
----------------------------------------
#include <stream.h>
#include <String.h>
class Foobar // note that no explicit assigment is defined
{
public:
String foo;
Foobar (String a)
{
foo = a;
}
Foobar (void)
{
}
#ifdef FIXBUG
operator = (Foobar &f)
{
foo = f.foo;
}
#endif
};
main ()
{
Foobar foo ("foo::hello");
Foobar bar;
bar = foo; // this is making an improper bit-wise copy here
cout << bar.foo << "\n";
cout << "(bar.foo == foo.foo) == " << (bar.foo == foo.foo) << "\n";
foo.foo = "new::hello";
cout << bar.foo << "\n"; // yow, there's an improper alias here!
}
----------------------------------------
Doug
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads