Article View: gnu.g++.bug
Article #1668Bug with bitwise copying of classes.
From: "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
Technical Details
Message-ID:
<8901251444.aa26036@PARIS.ICS.UCI.EDU>Path:
arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!xanth!nic.MR.NET!indri!csd4.milw.wisc.edu!mailrus!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%siam.ics.uci.eduShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!telly!ddsw1!lll-winken!uunet!xanth!nic.MR.NET!indri!csd4.milw.wisc.edu!mailrus!tut.cis.ohio-state.edu!PARIS.ICS.UCI.EDU!schmidt%siam.ics.uci.edu
From: schmidt%siam.ics.uci.edu@PARIS.ICS.UCI.EDU ("Douglas C. Schmidt")
Newsgroups: gnu.g++.bug
Subject: Bug with bitwise copying of classes.
Message-ID: <8901251444.aa26036@PARIS.ICS.UCI.EDU>
Date: 25 Jan 89 22:41:41 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 53