C and C++


LANG.TYPE.MFCBSTATIC : static宣言可能なメンバ関数

要旨

[C++のみ]

メンバ関数f()static宣言されておらず、加えて下記に挙げる全てが真となっています。

Member Function Could be constも併せて確認して下さい。

プロパティ

クラス名 Member Function Could Be static
日本語クラス名 static宣言可能なメンバ関数
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.MFCBSTATIC
カテゴリー
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.
対応言語 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 static"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

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;
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。