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 value of class type C is assigned to a variable of type B, where B is a base class of C.
In such an assignment, any additional member data that is present in class C but not in class B is not copied into the variable. The resolutions of any subsequent method calls on the variable may also be confusing for human readers.
Use configuration file parameter OBJSLICE_WARN_NEW_MEMBER_ONLY=Yes to specifies whether or not warnings should be restricted to the case where class C contains data members that are not present in class B (and so will be "sliced off" in the assignment).
| クラス名 | Object Slicing | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | Object Slicing | ||||||||||||||||||||||||
| クラス分類 | スタイル (style) | ||||||||||||||||||||||||
| ニーモニック | LANG.CAST.OBJSLICE | ||||||||||||||||||||||||
| カテゴリー |
|
||||||||||||||||||||||||
| 対応言語 | C++ のみ利用可能です。 C は利用できません。 |
||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Object Slicing" |
namespace lang_cast_objslice {
static int g = 0;
class Base {
public:
Base(){b=++g;}
int b;
void f(void){}
};
class Derived: public Base {
public:
Derived(){d=1;};
int d;
void g(void){}
};
class DerivedNoFields: public Base {};
void useBase(Base inb){}
void makeAssignments(void){
Base baseobj;
Derived derivedobj;
DerivedNoFields derivednofieldsobj;
useBase(baseobj); // ok: baseobj is a Base
useBase(derivedobj); // 'Object Slicing' warning issued here
useBase(derivednofieldsobj); // 'Object Slicing' warning issued here only if OBJSLICE_WARN_NEW_MEMBER_ONLY=No
baseobj=derivedobj; // 'Object Slicing' warning issued here
useBase(baseobj); // ok: baseobj is a Base
baseobj=derivednofieldsobj; // 'Object Slicing' warning issued here only if OBJSLICE_WARN_NEW_MEMBER_ONLY=No
useBase(baseobj); // ok: baseobj is a Base
}
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.