JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.CAST.BOOL : Conversion to Type bool

要旨

A value is cast or coerced to type bool.

Warnings of this class are not issued in the following cases.

プロパティ

クラス名 Conversion to Type bool
日本語クラス名 Conversion to Type bool
クラス分類 信頼性 (reliability)
ニーモニック LANG.CAST.BOOL
カテゴリー
AUTOSARC++14 AUTOSARC++14:A5-0-2 The condition of an if-statement and the condition of an iteration statement shall have type bool.
  AUTOSARC++14:M5-0-14 The first operand of a conditional-operator shall have type bool.
  AUTOSARC++14:M5-3-1 Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
MisraC++2008 MisraC++2008:5-0-13 The condition of an if-statement and the condition of an iteration-statement shall have type bool.
  MisraC++2008:5-0-14 The first operand of a conditional-operator shall have type bool.
  MisraC++2008:5-3-1 Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
MisraC++2023 MisraC++2023:7.0.2 There shall be no conversion to type bool
対応言語 C++ のみ利用可能です。 C は利用できません。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Conversion to Type bool"

class Expl {
    int m;
public:
    Expl( int x ) : m(x) {}
    explicit operator bool() const { return m > 0; }
};

class Impl {
    int m;
public:
    Impl( int x ) : m(x) {}
    operator bool() const { return m > 0; }
};

void conv2bool( int x, int *p ) {
    Expl e(x);
    Impl i(x);

    while (x) break;            // 'Conversion to Type bool' warning issued here
    while (!0) break;           // 'Conversion to Type bool' warning issued here
    while (p) break;                      // ok: converting a value of pointer type

    while (static_cast<bool>(i)) // 'Conversion to Type bool' warning issued here
                                 // (class Impl has operator bool() but it is not marked explicit)
        break;
    while (static_cast<bool>(e))         // ok: class Expl has explicit operator bool()
        break;
}

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

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

 

To report problems with this documentation, please visit https://support.codesecure.com/.