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++ only]
A member function f() is not declared const, and all of the following are true.
If f() modifies only static class data, or does not access any non-static class data, a warning of this class will not be issued: a Member Function Could Be static warning will be issued instead (if enabled).
| Class Name | Member Function Could Be const | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | |||||||||
| Mnemonic | LANG.TYPE.MFCBCONST | |||||||||
| Categories |
|
|||||||||
| Availability | Available for C and C++. |
|||||||||
| Enabling | Checks for this warning class are disabled by default,
and require the unnormalized
C ASTs for the project. To enable them, add the following
WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
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;
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.