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 and C++


LANG.TYPE.MFCBSTATIC : Member Function Could Be static

Summary

[C++ only]

A member function f() is not declared static, and all of the following are true.

See also Member Function Could be const.

Properties

Class Name Member Function Could Be static
Significance style
Mnemonic LANG.TYPE.MFCBSTATIC
Categories
AUTOSARC++14 AUTOSARC++14:M9-3-3 If a member function can be made static then it shall be made static, otherwise if it can be made const then it shall be made const.
MisraC++2008 MisraC++2008:9-3-3 If a member function can be made static then it shall be made static, otherwise if it can be made const then it shall be made const.
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 static"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

class MyClass {
public:
    MyClass(void){ myint=5;my_static_int=10; }

    int literal(int i){                 // 'Member Function Could Be static' warning issued here
        return 5;
    }

    int cbconst(int i){                                // ok: accesses non-static data member myint
                                                       // ('Member Function Could be const' warning will be issued if enabled)
      my_static_int += 2;
      return myint;
    }

    int cbstatic(int i){                // 'Member Function Could Be static' warning issued here
      my_static_int += i;
      return my_static_int;
    }

    static int marked_static(int i){                   // ok: declared static
      my_static_int += i;
      return my_static_int;
    }

    int cbstatic_uncalled(int i){                      // inline and not called, so no warning of this class is issued
       my_static_int += i;
       return my_static_int;
    }

    int noninline_cbstatic(int i);
private:
       int myint;
       static int my_static_int;
};

int MyClass::noninline_cbstatic(int i){ // 'Member Function Could Be static' warning issued here
    my_static_int += i;
    return my_static_int;
}

int use_MyClass( void ){
    MyClass mc;
    int i=0;
    int rv;
    rv = mc.literal(i);
    rv = rv + mc.cbconst(0);
    rv = rv +  mc.cbstatic(i);
    rv = rv + mc.marked_static(i);
    return rv;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.