Bug 79042 - g++ crashes when locally defined class without virtual destructor is new'd
g++ crashes when locally defined class without virtual destructor is new'd
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
i686 Linux
medium Severity low
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-12-04 18:41 EST by Steve Zastrow
Modified: 2007-04-18 12:48 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2003-02-19 11:10:40 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Steve Zastrow 2002-12-04 18:41:23 EST
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Description of problem:
I've been able to get g++ to crash when a method of a class is called that 
new's an instance of a class that is defined within the method, and where this 
locally defined class does not have a destructor and the class it is derived 
from has a virtual destructor.

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

How reproducible:

Steps to Reproduce:
1. Put the following code into a file named "test.cpp" (this is small enough 
that I thought I could include it here):

    class BaseClass
        virtual ~BaseClass () {};

    class Test
        static void Foo()
            class LocalClass: public BaseClass 
                // ~LocalClass() {};
            new LocalClass;


2. Compile it as follows:

    g++ -Wall -g -O -c -w -D_REENTRANT -Wunused -fsigned-char 
    -fsigned-bitfields test.cpp

Actual Results:  The following message was displayed:

    test.cpp: In method `Test::Foo ()::LocalClass::~LocalClass ()':
    test.cpp:24: Internal error: Segmentation fault.
    Please submit a full bug report.
    See <URL:http://bugzilla.redhat.com/bugzilla/> for instructions.

Expected Results:  The code should have compiled without errors.

Additional info:

The workaround for this problem is to write a destructor for LocalClass.  While 
this fixes the problem, it is completely unnecessary to have a destructor in my 
Comment 1 Alan Cox 2002-12-15 21:18:01 EST
This works in 8.0 / gcc 3.2 unoptimised
If you optimise it this triggers an infinite loop in the compiler..
Comment 2 Jakub Jelinek 2003-02-19 11:10:40 EST
Cannot reproduce this with gcc-3.2.2-1 from rawhide.

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