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
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 8.0
Hardware: i686
OS: Linux
medium
low
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
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:
Environment:
Last Closed: 2003-02-19 16:10:40 UTC
Embargoed:


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:
Always

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
    {
    public:
        virtual ~BaseClass () {};
    };

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

    main() 
    {
        Test::Foo();
    };


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 
case.

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.