This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9494: Unnecessary copyconstructor call on exception throw
- From: takis at lumumba dot luc dot ac dot be
- To: gcc-gnats at gcc dot gnu dot org
- Cc: panagiotis dot issaris at mech dot kuleuven dot ac dot be
- Date: 29 Jan 2003 08:04:23 -0000
- Subject: c++/9494: Unnecessary copyconstructor call on exception throw
- Reply-to: takis at lumumba dot luc dot ac dot be
>Number: 9494
>Category: c++
>Synopsis: Unnecessary copyconstructor call on exception throw
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Wed Jan 29 08:06:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Panagiotis Issaris
>Release: 2.95.3,2.95.4, 3.2.1
>Organization:
>Environment:
Slackware, Debian GNU/Linux
>Description:
When throwing exceptions and they are catched by reference, the copy constructor is called. The output of the execution of the included C++ sourcecode, shows:
C Human
Catch
D Human
When compiled using the Intel C++ 7.0 compiler while all recent versions of GCC generate code which calls the copy constructor:
C Human
CC Human
D Human
Catch
D Human
>How-To-Repeat:
Compile the following sourcecode. The resulting executable will use the copy constructor while (I and Intel C++ 7.0 think) it shouldn't.
#include <iostream>
using namespace std;
class Human
{
public:
Human()
{
cout << "C Human" << endl;
}
~Human()
{
cout << "D Human" << endl;
}
Human(const Human &c)
{
cout << "CC Human" << endl;
}
};
int main()
{
try {
throw Human();
}
catch(Human &e)
{
cout << "Catch" << endl;
}
return 0;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: