C and C++


LANG.TYPE.IAT : 不適切な型への代入

要旨

オブジェクトV に式E の値が代入されたとき、

例外 1: このクラスのワーニングは初期化子 {0} を使用している場合は検出されません。

例外 2: このクラスのワーニングは、 式の値が符号なし整数型で表現可能で、符号付き整数型の整数定数式から 符号なし整数型 への代入の場合は検出されません。

Exception 3: a warning of this class will not be issued for an assignment of an expression of essentially real floating type to a location of essentially complex floating type, provided that the corresponding real type of the location is not narrower than the type of the expression.

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

プロパティ

クラス名 Inappropriate Assignment Type
日本語クラス名 不適切な型への代入
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.IAT
カテゴリー
MisraC2023 MisraC2023:10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category
Misra2012 Misra2012:10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different 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: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-6 An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
  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-6 An implicit integral or floating-point conversion shall not reduce the size of the underlying type.
  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.
CERT-C CERT-C:FLP34-C Ensure that floating-point conversions are within range of the new type
  CERT-C:FLP36-C Preserve precision when converting integral values to floating-point type
  CERT-C:STR04-C Use plain char for characters in the basic character set
JSF++ JSF++:180 Implicit conversions that may result in a loss of information shall not be used.
  JSF++:184 Floating point numbers shall not be converted to integers unless such a conversion is a specified algorithmic requirement or is necessary for a hardware interface.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Assignment Type"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

void use_values(short int s, float fl, unsigned int u);

void TYPE_IAT(long long int lli, int i){
    short int si = lli;   /* 'Inappropriate Assignment Type' warning issued here */
    float f = i;          /* 'Inappropriate Assignment Type' warning issued here */
    struct {double x; double y;} pt = {0};                  /* {0} initializer */
    unsigned int x = 4;                                     /* signed constant 4 fits in an unsigned int */

    use_values(si, f, x);
}

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

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