JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.
If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.
If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.
| CodeSonar® 9.2p0 | CONFIDENTIAL | CodeSecure Inc |
An object of derived polymorphic class type C is deleted through a pointer to its base class type B, but B has a non-virtual destructor.
| クラス名 | delete with Non-Virtual Destructor | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | delete with Non-Virtual Destructor | |||||||||||||||
| クラス分類 | 信頼性 (reliability) | |||||||||||||||
| ニーモニック | LANG.STRUCT.DNVD | |||||||||||||||
| カテゴリー |
|
|||||||||||||||
| 対応言語 | C++ のみ利用可能です。 C は利用できません。 |
|||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST
が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと
RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="delete with Non-Virtual Destructor" |
namespace lang_struct_dnvd {
class BaseNoExplDtor {
virtual void f();
public:
BaseNoExplDtor(){};
};
class BaseExplDtor {
virtual void f();
public:
BaseExplDtor(){};
~BaseExplDtor(){};
};
class BaseExplVirtualDtor {
virtual void f();
public:
BaseExplVirtualDtor(){};
virtual ~BaseExplVirtualDtor(){};
};
class BaseNotPolymorphic {
void f();
public:
BaseNotPolymorphic();
~BaseNotPolymorphic();
};
class DerivedNoExplDtor : public BaseNoExplDtor { };
class DerivedExplDtor : public BaseExplDtor { };
class DerivedExplVirtualDtor : public BaseExplVirtualDtor { };
class DerivedNotPolymorphic : public BaseNotPolymorphic { };
class MultiDerived : public BaseNoExplDtor,
public BaseExplDtor,
public BaseExplVirtualDtor {};
void useDerivedClasses(){
BaseNoExplDtor *noexpldtor = new DerivedNoExplDtor();
BaseExplDtor *expldtor = new DerivedExplDtor();
BaseExplVirtualDtor *vdtor = new DerivedExplVirtualDtor();
BaseNotPolymorphic *notpolymorphic = new DerivedNotPolymorphic();
BaseNoExplDtor *noexpldtor_multi = new MultiDerived();
BaseExplDtor *expldtor_multi = new MultiDerived();
BaseExplVirtualDtor *vdtor_multi = new MultiDerived();
delete noexpldtor; // 'delete with Non-Virtual Destructor' warning issued here
delete expldtor; // 'delete with Non-Virtual Destructor' warning issued here
delete vdtor; // ok: BaseExplVirtualDtor declares a virtual destructor
delete notpolymorphic; // ok: BaseNotPolymorphic and DerivedNotPolymorphic have no virtual functions so are not polymorphic
delete noexpldtor_multi; // 'delete with Non-Virtual Destructor' warning issued here
delete expldtor_multi; // 'delete with Non-Virtual Destructor' warning issued here
// ('Misaligned Object' warning also issued)
delete vdtor_multi;
}
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.