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++/7707: GCC 3.1.1 Optimization incomplete/incorrect : leaks temporary object


>Number:         7707
>Category:       c++
>Synopsis:       GCC 3.1.1 Optimization incomplete/incorrect : leaks temporary object
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 23 16:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Konova Solutions Inc.
>Release:        GCC 3.1.1
>Organization:
>Environment:
RedHat Linux 7.3
Dual Intel Pentium III 833 MHz
GCC compiled with:
--prefix=/usr/gcc-3.1.1 --enable-threads=posix --enable-languages=c,c++
>Description:
g++ seems not to optimize temporary objects copy correctly and results in a memory leak. The cpp file attached provides a example of how g++ fails to destruct a temporary object.

The output of the example shows that 2 temporary objects are created (using copy ctor) while only one of them is destructed.

A temporary object is created on the stack in method 
operator+(const foo&, const foo&). The result of the operator+ is passed to another method taking a const foo as parameter. Doing so, g++ calls the copy constructor. 

It is up to the compiler to actually call the copy ctor or not. g++ does not seem to optimize this copy, but then fails to destroy the object.

The attachment contains the cpp and ii files.
>How-To-Repeat:

>Fix:
Modifing the leakAFoo method to take a const foo& instead.

g++ is still to blame. Either the optimization is incomplete, or some logic is erronous when destroying  temporary objects.
>Release-Note:
>Audit-Trail:
>Unformatted:


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