This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/8287: GCC3.2: Destructor called for non-constructed local object
- From: kristian dot spangsege at framfab dot dk
- To: gcc-gnats at gcc dot gnu dot org
- Cc: brian dot kristiansen at oracle dot com
- Date: 19 Oct 2002 19:09:58 -0000
- Subject: c++/8287: GCC3.2: Destructor called for non-constructed local object
- Reply-to: kristian dot spangsege at framfab dot dk
>Number: 8287
>Category: c++
>Synopsis: GCC3.2: Destructor called for non-constructed local object
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sat Oct 19 12:16:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Kristian Spangsege
>Release: gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)
>Organization:
>Environment:
RedHat 8.0 (Full install) on dual Intel Pentium III
And various other hardware configs. with RedHat 8.0
>Description:
In the "top-level" scope of a destructor for some class B a local object of class A will have its destructor called even if it was never initialized by its constructor due to a return statement appearing before the declaration of the local object.
The problem does not occur if the local object and the earlier return statement is placed in and ordinary method. Also the problem disappears if the entire destructor body of B is put within an otherwise redundant scope, similarly if only the declaration of the local object is put into a new scope.
The problem also does not occur with GCC-2.96.
The problem obviously results in core dumps unless one of the mentioned work-arounds are applied. But this is close to impossible when porting large applications from earlier versions of gcc.
(I'm utterly amazed about the fact that RedHad has managed to release its RedHat 8.0 entirely base on gcc3.2, when gcc3.2 has susch a lethal bug within it)
Btw. it took me 3 days of reducing 50000 lines of code to around 20 before I was even close to realizing what the bug was.
Go fix it :-)
>How-To-Repeat:
$ g++ test.C
$ ./a.out
And "test.C" is:
#include <iostream>
struct A
{
A() { std::cerr << "c\n"; }
~A() { std::cerr << "d\n"; }
};
struct B
{
~B()
{
if(true) return;
A a;
}
};
int main()
{
B b;
return 0;
}
>Fix:
Apply one of the work-arounds mentioned in "Description".
>Release-Note:
>Audit-Trail:
>Unformatted: