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]

c++/617: g++ uses double memory space when no copy constructor is defined



>Number:         617
>Category:       c++
>Synopsis:       g++ uses double memory space when no copy constructor is defined
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Oct 06 07:26:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     vanessa conchodon
>Release:        version 2.95.2 20000220 (Debian GNU/Linux)
>Organization:
>Environment:
PC with Pentium III processor
under Debian GNU/Linux
>Description:
(sorry, my english is not my mother language and i've
 no dictionnary at my office. hope you'll understand 
 my bug report !)

I 've created a class 'thing' and written a function 'fct'
with a 'thing b' as parameter.
When no copy constructor is defined, i've observed 2 calls
to thing destructor at the end of function 'fct'.
That means that for one parameter, two copies are done.
But only one is used in fct (i've modified b to see that).

Results of file 'thing.cpp' :
-------------------------------------------------------------
    + usual const. - object addr :0xbffffb88

******** BEFORE FCT *******
>How-To-Repeat:
compile file 'thing.cpp' 
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
 >> fct call
     - Object Destr. - object : addr 0xbffffb54 - valeur : 2
     - Object Destr. - object : addr 0xbffffb84 - valeur : 5
 ******** AFTER FCT *******
 
     - Object Destr. - object : addr 0xbffffb88 - valeur : 5
 ------------------------------------------------------------
 
 When i 've wtritten 'fct' with 2 parameters (thing b, thing c)
 i've observed 4 calls to destructor !
 
 But when i defined a copy constructor, only one
 call to destructor was done. 
 
 I know that we must write a copy constructor when
 we create a class, but i've forgotten for one class
 and i'm very surprised that default copy constructor
 uses double memory space.
 
 I've tried to compile my file on different systems
 (thing.cpp) :
 - on HP-UX and PC under Linux (Mandrake 7.0, Debian Potato)
   with g++ (different versions), i've obtained the same 
   results (2 destructor calls for on parameter)
 - on Windows with Borland C++ or MS Visual C++,
   only one call was done.
 
 Where is the bug ?
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="thing.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="thing.cpp"

I2luY2x1ZGUgPGlvc3RyZWFtLmg+CgovLyBBIENMQVNTICdUSElORycgSVMgQ1JFQVRFRAoKY2xh
c3MgdGhpbmcKCXsKCSAgaW50IG5iOwoKCSAgcHVibGljIDoKCgkgIC8vIENPTlNUUlVDVE9SCgkg
ICB0aGluZyhpbnQgbikKCSAgIHsgCgkgICAgIG5iID0gbjsKCSAgICAgY291dCA8PCAiICAgICsg
dXN1YWwgY29uc3QuIC0gb2JqZWN0IGFkZHIgOiIgPDwgdGhpcyAgPDwgIlxuIjsKCSAgIH0gCgoJ
ICAgLyoKCSAgIC8vIENPUFkgQ09OU1RSVUNUT1IKCSAgIC8vIFdoZW4gaXQgaXMgZGVmaW5lZCAo
dW5jb21tZW50ZWQpLCB0aGUgcHJvYmxlbSBvZiBkb3VibGUKCSAgIC8vIG1lbW9yeSBzcGFjZSBk
b2VzJ250IGV4aXN0CgkgICB0aGluZyhjb25zdCB0aGluZyAmIFQpCgkgICB7IAoJICAgICBuYiA9
IFQubmI7CgkgICAgIGNvdXQgPDwgIiAgICArIENPUFkgY29uc3QuIC0gb2JqZWN0IGFkZHIgOiIg
PDwgdGhpcyAgPDwgIlxuIjsKCSAgIH0gCgkgICAqLwoKCSAgIC8vIERFU1RSVUNUT1IKCSAgIH50
aGluZygpCgkgICB7IAoJICAgICBjb3V0IDw8ICIgICAgLSBPYmplY3QgRGVzdHIuIC0gb2JqZWN0
IDogYWRkciAiIDw8IHRoaXMgCgkgICAgICAgICAgPDwgIiAtIHZhbGV1ciA6ICIgPDwgbmIgPDwi
XG4iOwoJICAgfQoKCgkgICAvLyBBRkZFQ1RBVElPTgoJICAgdm9pZCBteV9hZmZlY3QoaW50IG4p
CgkgICAgewoJICAgICAgbmIgPSBuOwoJICAgIH0KCgkgICAvLyBQUklOVAoJICAgdm9pZCBteV9w
cmludCgpCgkgICAgewoJICAgICAgY291dCA8PCAidmFsdWUgOiAiIDw8IG5iIDw8ICJcbiI7Cgkg
ICAgfQogICAgICAgICB9OwoKdm9pZCBmY3QodGhpbmcgYikKewogY291dCA8PCAiPj4gZmN0IGNh
bGxcbiI7CiBiLm15X2FmZmVjdCgyKTsKfQoKbWFpbigpCnsKICB0aGluZyBhKDUpOwoKICBjb3V0
IDw8ICJcbioqKioqKioqIEJFRk9SRSBGQ1QgKioqKioqKlxuIjsKICBmY3QoYSk7CiAgY291dCA8
PCAiKioqKioqKiogQUZURVIgRkNUICoqKioqKipcblxuIjsKfQoKCi8qKiogV0hBVCBJUyBXUklU
VEVOIE9OIE1ZIFNDUkVFTiBXSEVOIEVYRUNVVEVEIDoKCjxCRUdJTj4KCiAgICArIHVzdWFsIGNv
bnN0LiAtIG9iamVjdCBhZGRyIDoweGJmZmZmYjg4CgoqKioqKioqKiBCRUZPUkUgRkNUICoqKioq
KioKPj4gZmN0IGNhbGwKICAgIC0gT2JqZWN0IERlc3RyLiAtIG9iamVjdCA6IGFkZHIgMHhiZmZm
ZmI2NCAtIHZhbGV1ciA6IDIKICAgIC0gT2JqZWN0IERlc3RyLiAtIG9iamVjdCA6IGFkZHIgMHhi
ZmZmZmI4NCAtIHZhbGV1ciA6IDUKKioqKioqKiogQUZURVIgRkNUICoqKioqKioKCiAgICAtIE9i
amVjdCBEZXN0ci4gLSBvYmplY3QgOiBhZGRyIDB4YmZmZmZiODggLSB2YWxldXIgOiA1Cgo8RU5E
PgoKKioqLwo=

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