C and C++


LANG.CAST.ARRAY.POINTER : 配列からポインタへの減衰

要旨

配列型を持つ識別子が関数の引数として渡され、ポインタへ減衰しています。

See also Array Parameter.

プロパティ

クラス名 Array to Pointer Decay
日本語クラス名 配列からポインタへの減衰
クラス分類 スタイル (style)
ニーモニック LANG.CAST.ARRAY.POINTER
カテゴリー
AUTOSARC++14 AUTOSARC++14:M5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer.
  AUTOSARC++14:A18-1-1 C-style arrays shall not be used.
MisraC++2008 MisraC++2008:5-2-12 An identifier with array type passed as a function argument shall not decay to a pointer.
MisraC++2023 MisraC++2023:7.11.2 An array passed as a function argument shall not decay to a pointer
JSF++ JSF++:183 Every possible measure should be taken to avoid type casting.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Array to Pointer Decay"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

int ptr_arg(int *p);
int no_dimensionality(int a[5]);
int dimensionality_preserved(int (&a)[5]);

int lang_cast_array_pointer() {
   int retval=0;
   int myarr[5];

   retval += ptr_arg(myarr);                  /* 'Array to Pointer Decay' warning issued here */
   retval += no_dimensionality(myarr);        /* 'Array to Pointer Decay' warning issued here */
   retval += dimensionality_preserved(myarr);                       /* ok: myarr does not decay to a pointer */

   return retval;
}

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

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