[Bug c++/11069] New: C++ Standard Violation (15.3.3)

afu@fugmann.dhs.org gcc-bugzilla@gcc.gnu.org
Mon Jun 2 21:56:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11069

           Summary: C++ Standard Violation (15.3.3)
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: major
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: afu@fugmann.dhs.org
                CC: gcc-bugs@gcc.gnu.org

When thowing an object it seems that the type of the variable thrown is used and
not the type of the object thrown in the catch block. This menas that exception
are not caught correctly, and that it is impossible to destruct the thrown
object correctly.

To reproduce the bug, compile and run the following program:
#include <iostream>
using namespace std;

class Exception
{
public:
    Exception() {
	cout << "Constructor called" << endl;
    }
    
    virtual ~Exception() {
	cout << "Destructor called" << endl;
    }    
};

class ExtendedException: public Exception
{  
public:
    ExtendedException(): Exception() {
	cout << "EE Constructor called" << endl;
    }
    
    ~ExtendedException() {
	cout << "EE Destructor called" << endl;
    }
};

int main()
{
    try {
	Exception *e = new ExtendedException();
	throw (*e);
    } 
    catch (ExtendedException &ee) {
	cout << "Caught ExtendedException" << endl;
    }
    
    catch (Exception &e) {
	cout << "Caught Exception" << endl;
    }
}

Expected result:
 Constructor called
 EE Constructor called
 Caught ExtendedException
 EE Destructor called
 Destructor called

Got result:
 Constructor called
 EE Constructor called
 Caught Exception
 Destructor called

Changing the type of *e to ExtendedException produces the expected result.



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the Gcc-bugs mailing list