Bug 76314 - GCC3.2 produces wrong code: Destructor called for non-constructed local object
Summary: GCC3.2 produces wrong code: Destructor called for non-constructed local object
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc   
(Show other bugs)
Version: 8.0
Hardware: i686 Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-10-19 20:10 UTC by Kristian Spangsege
Modified: 2007-04-18 16:47 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2004-10-03 10:16:27 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Kristian Spangsege 2002-10-19 20:10:56 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Description of problem:
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 :-)

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
$ 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
    if(true) return;
    A a;

int main()
  B b;
  return 0;

Actual Results:  I get the following output:


Expected Results:  I should have had no output:

Additional info:

The problem occurs on:
RedHat 8.0 (Full install) on dual Intel Pentium III
And various other hardware configs. with RedHat 8.0
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

I would be damned if this bug does not cause segfaults and other nasty behaviour
in some applications shipped with RedHat 8.0 that use
the lethal construct.

Comment 1 Need Real Name 2002-12-08 18:18:11 UTC
I have RedHat 8.0 on a Pentium IV and intel motherboard with 60 gig harddrive
and 256 meg memory.  I have transferred some fortran programs from another
RedHat 7.2 system where everything works fine.  The program starts, runs a while
with a lot of disk read/writes and then just crashes.  Maybe this is related?

Comment 2 Kristian Spangsege 2002-12-09 16:20:10 UTC
No, I don't think your Fortram problem is related.
The bug I describe above, was tracked down by mark@codesourcery.com <Mark
Mitchell> and is corrected in gcc3.2.1 was has recently been released.
Is I understand it the bug was exclusively related to the C++ frontend of gcc.

For details,check out:

Comment 3 Richard Henderson 2004-10-03 10:16:27 UTC
Indeed fixed.

Note You need to log in before you can comment on or make changes to this bug.