This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/9494: Unnecessary copyconstructor call on exception throw


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]