Article View: gnu.g++.bug
Article #1242Default copy constructor broken
From: Andrew Harrison
Date: Fri, 11 Dec 1992 18:07
Date: Fri, 11 Dec 1992 18:07
66 lines
1603 bytes
1603 bytes
The following program would seem to indicate that the default copy
constructor mechanism is broken in gcc. It was tested with 2.2.2 and 2.3.2
on sun 4 sunos4.2. The default copy constructor for Compound should
in turn call the copy constructor for Item, but it does not.
The output is
Item()
Compound()
Pre foo
foo
~Compound()
~Item()
Post foo
~Compound()
~Item()
The output should be something like (produced from ATT 2.1)
Item()
Compound()
Pre foo
Item(const Item& i) <------ missing above
foo
Post foo
~Compound()
~Item()
~Compound()
~Item()
#include <iostream.h>
class Item {
public:
Item() { cerr << "Item()\n"; }
Item(const Item& i) { cerr << "Item(const Item& i)\n"; }
~Item() { cerr << "~Item()\n"; }
};
class Compound {
Item i;
public:
Compound() { cerr << "Compound()\n"; }
// Compound(const Compound& i) { cerr << "Compound(const Compound& i)\n"; }
~Compound() { cerr << "~Compound()\n"; }
void msg(char *s) { cerr << s; }
};
void foo(Compound a)
{
a.msg("foo\n");
}
main()
{
Compound a;
cerr << "Pre foo\n";
foo(a);
cerr << "Post foo\n";
}
Technical Details
Message-ID:
<9212111007.aa13841@q2.ics.uci.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!binky.ics.uci.edu!harrisonShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!binky.ics.uci.edu!harrison From: harrison@binky.ics.uci.edu (Andrew Harrison) Subject: Default copy constructor broken Message-ID: <9212111007.aa13841@q2.ics.uci.edu> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Fri, 11 Dec 1992 18:07:23 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 68