Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Problem with destructor in IC8.1

davswi
Beginner
399 Views

I have two classes:

struct

Class1

{

Class1()

{

LogAlert("call Class1()");

}

Class1(

const Class1 & _c

)

{

LogAlert("call Class1(const Class1 & _c)");

}

~Class1()

{

LogAlert("call ~Class1()");

}

};

struct

Class2

{

Class2()

{

LogAlert("call Class2()");

}

Class2(

const Class1 _c // without &

) : prm(_c)

{

LogAlert("call Class2(const Class1 & _c)");

}

~Class2()

{

LogAlert("call ~Class2()");

}

Class1 prm;

};

Class1 tmp;

Class2 cls(tmp);

In result i have:

call Class1()
call Class1(const Class1 & _c)
call Class1(const Class1 & _c)
call Class2(const Class1 & _c)
call ~Class2()
call ~Class1()
call ~Class1()

Where one call of destructor?

0 Kudos
2 Replies
Micah_Elliott
Beginner
399 Views
I put your two instantiations into a main() and changed your LogAlerts to printfs to make this work. I tried with old and new versions of 8.1 and I don't see any problem. My output from any compiler shows all four dtor calls: call Class1() call Class1(const Class1 & _c) call Class1(const Class1 & _c) call Class2(const Class1 & _c) call ~Class1() call ~Class2() call ~Class1() call ~Class1() What does "icc -V" tell you about your version? Do you have a standalone test case that works and demonstrates this?
0 Kudos
davswi
Beginner
399 Views

This problem show if"Enable C++ Exceptions (/EHsc)" is disable. But microsoft compiler work correct with this code.

0 Kudos
Reply