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 |
[C++のみ]
メンバ関数 f() は const宣言されておらず、加えて下記に挙げる全てが真となっています。
もしf() が static(静的)クラスデータのみ変更する、若しくはいかなる non-static(非静的)クラスデータにアクセスしないということであれば、本ワーニングクラスの警告は発行されません。: Member Function Could Be static が代わりに発行されます(そのワーニングクラス検出が有効化されている場合)。
| クラス名 | Member Function Could Be const | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | const宣言可能なメンバ関数 | |||||||||
| クラス分類 | スタイル (style) | |||||||||
| ニーモニック | LANG.TYPE.MFCBCONST | |||||||||
| カテゴリー |
|
|||||||||
| 対応言語 | C および C++ で利用可能です。 |
|||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST
が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと
RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="Member Function Could Be const" |
class MyClass {
public:
MyClass(void){ myint=5; my_static_int=10; }
int cbconst(int i){ // 'Member Function Could Be const' warning issued here
return myint;
}
int marked_const(int i) const { // ok: declared const
return myint + 1;
}
int cbconst_uncalled(int i){ // inline and not called, so no warning of this class is issued
return myint;
}
int modify_member(int i){ // ok: modifies a (non-static) member
myint += i;
return myint;
}
// modifies a static member:
// - a warning of this class is NOT issued
// - a 'Member Function Could Be static' warning is issued (if enabled)
int modify_static_member(int i){
my_static_int += i;
return my_static_int;
}
int noninline_cbconst(int i);
private:
int myint;
static int my_static_int;
};
int MyClass::noninline_cbconst(int i){ // 'Member Function Could Be const' warning issued here
return myint + i;
}
// inline member functions can only trigger warnings of this class if they are used in the analyzed code
int use_MyClass( void ){
MyClass mc;
int rv=0;
rv = mc.cbconst(rv);
rv = mc.marked_const(rv);
rv = mc.modify_member(rv);
rv = mc.modify_static_member(rv);
return rv;
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。
To report problems with this documentation, please visit https://support.codesecure.com/.