Bug 79042 - g++ crashes when locally defined class without virtual destructor is new'd
Summary: g++ crashes when locally defined class without virtual destructor is new'd
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: i686
OS: Linux
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
Depends On:
TreeView+ depends on / blocked
Reported: 2002-12-04 23:41 UTC by Steve Zastrow
Modified: 2007-04-18 16:48 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2003-02-19 16:10:40 UTC

Attachments (Terms of Use)

Description Steve Zastrow 2002-12-04 23:41:23 UTC
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-16 02:18:01 UTC
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 16:10:40 UTC
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.