C and C++ Binaries


LANG.STRUCT.USEASSIGN : 代入式の副作用

要旨

代入演算子が部分式で使われています。その結果、式が:

このワーニングクラスは、以下の場合には発生しません。

プロパティ

クラス名 Assignment Result in Expression
日本語クラス名 代入式の副作用
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.USEASSIGN
カテゴリー
MisraC2023 MisraC2023:13.4 The result of an assignment operator should not be used
Misra2012 Misra2012:13.4 The result of an assignment operator should not be used
Misra2004 Misra2004:13.1 Assignment operators shall not be used in expressions that yield a Boolean value
AUTOSARC++14 AUTOSARC++14:M6-2-1 Assignment operators shall not be used in sub-expressions.
MisraC++2008 MisraC++2008:6-2-1 Assignment operators shall not be used in sub-expressions.
MisraC++2023 MisraC++2023:8.18.2 The result of an assignment operator should not be used
CWE CWE:481 Assigning instead of Comparing
CERT-C CERT-C:EXP45-C Do not perform assignments in selection statements
JSF++ JSF++:160 An assignment expression shall be used only as the expression in an expression statement.
JPL JPL:19 Do not use expressions with side effects.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Assignment Result in Expression"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

int g;
int f(int i);

int lang_struct_useassign(int *a){
    int x;
    int y;
    int vla[g=32];        /* 'Assignment Result in Expression' warning issued here */

    y = x = 1;            /* 'Assignment Result in Expression' warning issued here */

    f(x+=3);              /* 'Assignment Result in Expression' warning issued here */

    if (x=3){             /* 'Assignment Result in Expression' warning issued here
                           * ('Redundant Condition' also issued)
                           */
        x = y++;                            /* postincrement result */
    }
                
    if ((x==x) || (x=3)){ /* 'Assignment Result in Expression' warning issued here
                           * (even though subexpression will never be executed:
                           * 'Unreachable Conditional' and 'Redundant Condition' warnings also issued)
                           */
    x = ++x;              /* 'Assignment Result in Expression' warning issued here */
    }
    x += (y += x, y);                          /* comma operand */
    return x;
}

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

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