C and C++


LANG.TYPE.MOT : オペランド型のミスマッチ

要旨

(C90 および C99 標準に記述されている) 「通常の算術型変換」を行う演算子において、2つのオペランドが同じ 実質的な型ではありません。 このチェックは以下で適用されます。

例外 1: + および += 演算子に関して、片方のオペランドが文字型で、もう片方が符号付き整数型かもしくは 符号なし整数型の場合はワーニングは検出されません。

例外 2: - および -= 演算子に関して、LHS(左辺)オペランドが文字型で、RHS(右辺)オペランドが 符号付き整数型かもしくは 符号なし整数型の場合はワーニングは検出されません。

Exception 3: a warning of this class will not be issued if one operand has essentially real floating type and the other has essentially complex floating type. (For the ternary ?: operator, this exception applies to the second and third operands.)

このワーニングクラスは、クリティカルシステム向けのC言語ガイドラインMISRA C:2012実質的な型に記載されている概念に基づいています。

プロパティ

クラス名 Mismatched Operand Types
日本語クラス名 オペランド型のミスマッチ
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.MOT
カテゴリー
MisraC2023 MisraC2023:10.4 Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
Misra2012 Misra2012:10.4 Both operands of an operator in which the usual arithmetic conversions are performed shall have the same essential type category
Misra2004 Misra2004:6.1 The plain char type shall be used only for storage and use of character values
  Misra2004:6.2 signed and unsigned char type shall be used only for the storage and use of numeric values
  Misra2004:10.1 The value of an expression of integer type shall not be implicitly converted to a different underlying type if: (a) it is not a conversion to a wider integer type of the same signedness, or (b) the expression is complex, or (c) the expression is not constant and is a function argument, or (d) the expression is not constant and is a return expression
  Misra2004:10.2 The value of an expression of floating type shall not be implicitly converted to a different type if: (a) it is not a conversion to a wider floating type, or (b) the expression is complex, or (c) the expression is a function argument, or (d) the expression is a return expression
AUTOSARC++14 AUTOSARC++14:A1-1-1 All code shall conform to ISO/IEC 14882:2014 - Programming Language C++ and shall not use deprecated features.
  AUTOSARC++14:M5-0-3 A cvalue expression shall not be implicitly converted to a different underlying type.
  AUTOSARC++14:M5-0-5 There shall be no implicit floating-integral conversions.
  AUTOSARC++14:M5-0-11 The plain char type shall only be used for the storage and use of character values.
  AUTOSARC++14:M5-0-12 Signed char and unsigned char type shall only be used for the storage and use of numeric values.
MisraC++2008 MisraC++2008:5-0-3 A cvalue expression shall not be implicitly converted to a different underlying type.
  MisraC++2008:5-0-5 There shall be no implicit floating-integral conversions.
  MisraC++2008:5-0-11 The plain char type shall only be used for the storage and use of character values.
  MisraC++2008:5-0-12 signed char and unsigned char type shall only be used for the storage and use of numeric values.
MisraC++2023 MisraC++2023:4.1.2 Deprecated features should not be used
CERT-C CERT-C:FLP06-C Convert integers to floating point for floating-point operations
  CERT-C:STR04-C Use plain char for characters in the basic character set
JSF++ JSF++:162 Signed and unsigned values shall not be mixed in arithmetic or comparison operations.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Mismatched Operand Types"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

unsigned int TYPE_MOT(signed int s, unsigned int u, char c){
    char mychar;
    unsigned int i=0;

    mychar = c + u;                                     /* exception case 1 */
    if (mychar > 'a'){
        mychar -= s;                                    /* exception case 2 */
    }

    if (mychar > 'a'){
        i = u + s;         /* 'Mismatched Operand Types' warning issued here */ 
    }    
    if (u < c){            /* 'Mismatched Operand Types' warning issued here */        
        i = u==5 ? c : s;  /* 'Mismatched Operand Types' warning issued here */ 
    }
    return i;
}

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

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