This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/6555: Copy constructor is called before the object (being copied) is initialized



>Number:         6555
>Category:       c++
>Synopsis:       Copy constructor is called before the object (being copied) is initialized
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Sat May 04 02:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     relf@os2.ru
>Release:        gcc 3.0.3
>Organization:
>Environment:
IBM OS/2 Warp 4.52
>Description:
In the attached program first used constructor of class A is copy constructor, i.e. copy constructor is called before any class objects are initialized (so it tries to copy uninitialized object).

The program prints which constuctor of A is called, and the output look like:

Constructor A(const A&)
Constructor A(const A&)
Constructor A(const A&)
Constructor A()
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="bug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="bug.cpp"

I2luY2x1ZGUgPGlvc3RyZWFtPg0KI2luY2x1ZGUgPG1hcD4NCg0KdXNpbmcgbmFtZXNwYWNlIHN0
ZDsNCg0KdGVtcGxhdGUgPGludCBudW0+DQpjbGFzcyBBDQp7DQpwdWJsaWM6DQogICAgaW50IHZh
bHVlW251bV07DQogICAgc3RhdGljIEEgdW5pdDsNCg0KICAgIEEoKQ0KICAgIHsNCiAgICAgICAg
Y291dCA8PCAiQ29uc3RydWN0b3IgQSgpXG4iOw0KICAgICAgICB2YWx1ZVswXSA9IDE7DQogICAg
fQ0KDQogICAgQShjb25zdCBBJiB4KQ0KICAgIHsNCiAgICAgICAgY291dCA8PCAiQ29uc3RydWN0
b3IgQShjb25zdCBBJilcbiI7DQogICAgICAgIHZhbHVlWzBdID0geC52YWx1ZVswXTsNCiAgICB9
DQp9Ow0KDQp0ZW1wbGF0ZSA8aW50IG51bT4NCkE8bnVtPiBBPG51bT46OnVuaXQ7DQoNCmNsYXNz
IGNtcEEzDQp7DQpwdWJsaWM6DQogICAgYm9vbCBvcGVyYXRvciAoKSAoY29uc3QgQTwzPiYgeCwg
Y29uc3QgQTwzPiYgeSkNCiAgICB7DQogICAgICAgIHJldHVybiB4LnZhbHVlWzBdPD15LnZhbHVl
WzBdOw0KICAgIH0NCn07DQoNCmNsYXNzIEINCnsNCnB1YmxpYzoNCiAgICBtYXA8QTwzPixpbnQs
Y21wQTM+IHNvbWU7DQogICAgQigpDQogICAgew0KICAgICAgICBzb21lLmluc2VydCggcGFpcjxB
PDM+LGludD4oQTwzPjo6dW5pdCw4OCkgKTsNCiAgICB9DQp9Ow0KDQpCIHRlc3Q7DQoNCmludCBt
YWluKCkNCnsNCiAgICByZXR1cm4gMDsNCn0NCg==


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]