From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16784 invoked by alias); 23 Aug 2002 23:06:01 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 16765 invoked by uid 71); 23 Aug 2002 23:06:00 -0000 Resent-Date: 23 Aug 2002 23:06:00 -0000 Resent-Message-ID: <20020823230600.16764.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org, lletourneau@konova.com Resent-Reply-To: gcc-gnats@gcc.gnu.org, plaflamme@konova.com Received: (qmail 15408 invoked by uid 61); 23 Aug 2002 23:01:36 -0000 Message-Id: <20020823230136.15407.qmail@sources.redhat.com> Date: Fri, 23 Aug 2002 16:36:00 -0000 From: plaflamme@konova.com Reply-To: plaflamme@konova.com To: gcc-gnats@gcc.gnu.org Cc: lletourneau@konova.com X-Send-Pr-Version: gnatsweb-2.9.3 (1.1.1.1.2.31) X-GNATS-Notify: lletourneau@konova.com Subject: c++/7707: GCC 3.1.1 Optimization incomplete/incorrect : leaks temporary object X-SW-Source: 2002-08/txt/msg00513.txt.bz2 List-Id: >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: