メインコンテンツ

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

有効な boolean 型 (-boolean-types)

コーディング ルール チェッカーが実質的に boolean として扱うデータ型の指定

説明

コーディング ルール チェッカーが実質的に boolean として扱うデータ型を指定します。このデータ型はソースコード内で enum または typedef ステートメントで定義したときのみ実質的に boolean 型として指定可能です。

既定では、Polyspace® はこれらの boolean 型をサポートしています。

  • ソース ファイルの 1 つに stdbool.h を含めたら、C99 で _Bool と入力します。たとえば、マクロ true および false は実質的に Boolean 型とみなされます。

  • C11 と C++ のすべてのバージョンで bool と入力します。

このオプションを指定すると、Polyspace は、以下の型も実質的に boolean 型とみなします。

  • このオプションの入力として指定したデータ型。

  • マクロ true/TRUE/True および false/FALSE/False (それぞれ値 1 および 0 を持つ場合)。

オプションの設定

以下のいずれかの方法を使用してオプションを設定します。

  • Polyspace ユーザー インターフェイス (デスクトップ製品のみ): プロジェクト構成で [コーディング規約およびコード メトリクス] ノードを選択してから、このオプションの値を入力します。最初に有効にしなければならない他のオプションについては、依存関係を参照してください。

  • Polyspace Platform ユーザー インターフェイス (デスクトップ製品のみ): プロジェクト構成の [静的解析] タブで [欠陥とコーディング規約][チェッカー動作] ノードを選択してから、このオプションの値を入力します。最初に有効にしなければならない他のオプションについては、依存関係を参照してください。

  • コマンド ラインとオプション ファイル: オプション -boolean-types を使用します。コマンド ライン情報を参照してください。

このオプションを使用する理由

このオプションにより Polyspace は以下のコーディング ルールをチェックできます。

  • MISRA C™:2012

    ルール番号ルール ステートメント
    10.1Operands shall not be of an inappropriate essential type
    10.3The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category
    10.5The value of an expression should not be cast to an inappropriate essential type
    14.4The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.
    16.7A switch-expression shall not have essentially Boolean type.
  • MISRA C:2023

    ルール番号ルール ステートメント
    10.1Operands shall not be of an inappropriate essential type
    10.3The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category
    10.5The value of an expression should not be cast to an inappropriate essential type
    14.4The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.
    16.7A switch-expression shall not have essentially Boolean type.

たとえば、次のコードでは、boolean_T が有効な boolean として認識されないため、Polyspace は、MISRA C:2012 Rule 14.4 の違反を検出します。解析を再実行して、オプション -boolean-types boolean_T を指定した場合、Polyspace は、コードがルール 14.4 に準拠していると見なします。

typedef int boolean_T;

void func1(void);
void func2(void);

void func(boolean_T flag) {
    if(flag) // No misra2012 14.4 violation when you use -boolean-types
        func1();
    else
        func2();
}

設定

既定値なし

をクリックしてフィールドを追加します。Polyspace が boolean として扱うデータ型名を入力します。

依存関係

このオプションは、Polyspace ユーザー インターフェイスで次のいずれかのオプションが選択されている場合にのみ有効になります。

Polyspace Platform ユーザー インターフェイスのオプション [カスタム チェッカー ファイルを使用]

コマンド ライン情報

パラメーター: -boolean-types
値: type1[,type2[,...]]
既定値なし
例 (Bug Finder): polyspace-bug-finder -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t
例 (Bug Finder Server): polyspace-bug-finder-server -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t