c++ bug: PXCBase virtual destructor should be defined

c++ bug: PXCBase virtual destructor should be defined

Portrait de PAVEL S. (Intel)

PCSDK\include\pxcbase.h class PXCBase

///@bug class PXCBase virtual destructor should be defined
class PXCDerivativeClass
 : public PXCBase 
{
public:
 ~PXCDerivativeClass();
 ...
};
...
PXCBase *p = new PXCDerivativeClass;
delete p; ///@bug PXCDerivativeClass::~PXCDerivativeClass() is skipped here
...

5 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.
Portrait de David Lu (Intel)

We will investigate and it will be fixed in future release. Thanks! David

Portrait de Xintian Wu (Intel)

Any interface defined as PXCBase should be implemented with PXCBaseImpl. In your case, this is

class PXCDerivativeClass: public PXCBase {
public:
virtual void PXCAPI Function1(void)=0;
};

class PXCDerivativeClassImpl: public PXCBaseImpl {
public:
~PXCDerivativeClassImpl(void) {}
virtual void PXCAPI Function1(void) {}
};

Please see sdkmanual-modules.pdf for more details.

Portrait de Xintian Wu (Intel)

Sorry, the second class should be as follows:

class PXCDerivativeClassImpl: public PXCBaseImpl {
public:
~PXCDerivativeClassImpl(void) {}
virtual void PXCAPI Function1(void) {}
};

Portrait de PAVEL S. (Intel)

Non-portable compiler feature is used: virtual methods table pointer still valid after trivial MSVC destructor.

See ISO/IEC IS 14882 Programming languages - C++

5.3.5 Delete [expr.delete]

Claim 1

The delete-expression operator destroys a most derived object (1.8) or array created by a new-expression.

Claim 3

In the first alternative (delete object), if the static type of the operand is different from its dynamic type, the static type shall be a base class of the operand's dynamic type and the static type shall have a virtual destructor or the behavior is undefined.

12.4 Destructors [class.dtor]

Claim 14

Once a destructor is invoked for an object, the object no longer exists; the behavior is undefined if the destructor is invoked for an object whose lifetime has ended (3.8).

Connectez-vous pour laisser un commentaire.