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 |
A virtual member function is called from a destructor.
This can lead to unexpected and potentially dangerous behavior. During execution of a base class B's destructor, when not in an even deeper base class's destructor, any virtual calls through the this pointer will resolve as if B is the dynamic type (most derived type) of this.
For inline destructors, a warning will only be issued if the destructor is invoked at least once.
| クラス名 | Virtual Call in Destructor | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | Virtual Call in Destructor | ||||||||||||||||||
| クラス分類 | 信頼性 (reliability) | ||||||||||||||||||
| ニーモニック | LANG.STRUCT.VCALL_IN_DTOR | ||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||
| 対応言語 | C++ のみ利用可能です。 C は利用できません。 |
||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Virtual Call in Destructor" |
namespace lang_struct_vcall_in_dtor {
// Code with implicit inline destructor invocation.
class BaseExplicit {
virtual void virtual_cleanup(void) {}
public:
~BaseExplicit() {
this->virtual_cleanup(); // 'Virtual Call in Destructor' warning issued here.
// This call to virtual_cleanup() will always invoke BaseExplicit::virtual_cleanup(),
// which is probably not what the author intends.
}
};
class DerivedExplicit : BaseExplicit {
int *iptr;
virtual void virtual_cleanup(void) override {delete iptr;}
public:
DerivedExplicit() {iptr = new int;}
};
void use_base_explicit(BaseExplicit *be){
delete be; // Explicit invocation of inline destructor.
}
// Code with implicit destructor invocation.
class BaseImplicit {
virtual void virtual_cleanup(void) {}
public:
~BaseImplicit() {
this->virtual_cleanup(); // Two 'Virtual Call in Destructor' warnings issued here.
// - one for the virtual call in BaseImplicit::~BaseImplicit()
// - one for the virtual call in DerivedImplicit::~DerivedImplicit()
}
};
class DerivedImplicit : BaseImplicit {
int *iptr;
virtual void virtual_cleanup(void) override {delete iptr;}
public:
DerivedImplicit() {iptr = new int; *iptr=5;}
int value(void){return *iptr;}
};
int use_derived_implicit(void){
DerivedImplicit di;
return di.value();
// Implicit invocation of inline DerivedImplicit destructor
// (and then BaseImplicit destructor) when di goes out of scope.
}
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.