C and C++


LANG.STRUCT.SCOPE.LOCAL : ローカルスコープの可能性

要旨

ローカルスコープでのみ使用されている変数が、より大きなスコープで定義されています。

設定ファイルパラメータ SCOPE_CHECK_SUGGESTS_LOCAL_STATICNo に設定されている場合、ローカルスコープの可能性のワーニングは検出されません。 その代わり、ローカルスコープの可能性がある変数のうち、グローバルスコープとして定義されたものは(ファイルスコープの可能性) としてレポートされ、ファイルスコープとして定義されたものはレポートされません。

プロパティ

クラス名 Scope Could Be Local Static
日本語クラス名 ローカルスコープの可能性
クラス分類 スタイル (style)
ニーモニック LANG.STRUCT.SCOPE.LOCAL
カテゴリー
MisraC2023 MisraC2023:8.7 Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
  MisraC2023:8.8 The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage
  MisraC2023:8.9 An object should be declared at block scope if its identifier only appears in a single function
Misra2012 Misra2012:8.7 Functions and objects should not be defined with external linkage if they are referenced in only one translation unit
  Misra2012:8.8 The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage
  Misra2012:8.9 An object should be declared at block scope if its identifier only appears in a single function
Misra2004 Misra2004:8.7 Objects shall be defined at block scope if they are only accessed from within a single function
  Misra2004:8.10 All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required
  Misra2004:8.11 The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage
AUTOSARC++14 AUTOSARC++14:M3-4-1 An identifier declared to be an object or type shall be defined in a block that minimizes its visibility.
MisraC++2008 MisraC++2008:3-4-1 An identifier declared to be an object or type shall be defined in a block that minimizes its visibility.
CWE CWE:1126 Declaration of Variable with Unnecessarily Wide Scope
CERT-C CERT-C:DCL19-C Minimize the scope of variables and functions
JSF++ JSF++:136 Declarations should be at the smallest feasible scope.
POW10 POW10:6 Declare data objects at the smallest possible level of scope.
JPL JPL:13 Declare data objects at smallest possible level of scope.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Scope Could Be Local Static"

int myint = 5;  /* 'Scope Could Be Local Static' warning issued here */

/* ... */                       /* code that does not use myint */

int modify_int(int i){
    return i + myint;
}

/* ... */                       /* code that does not use myint */

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

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