MISRA C++:2008 Rule 4-5-1
Expressions with type bool shall not be used as operands to built-in operators other than the assignment operator =, the logical operators &&, ||, !, the equality operators == and !=, the unary & operator, and the conditional operator.
説明
ルール定義
Expressions with type bool shall not be used as operands to built-in operators other than the assignment operator =, the logical operators &&, ||, !, the equality operators == and !=, the unary & operator, and the conditional operator. 1
根拠
ルールに記載されている演算子以外の演算子では、bool 型のオペランドを使用しても意味のある結果が生成されません。bool 型のオペランドをこのような演算子で使用すると、プログラミング エラーを示す可能性があります。たとえば、論理演算子 || の使用を意図していたが、ビット演算子 | を代わりに使用した場合です。
Polyspace 実装
次の演算子以外の演算子のオペランドとして boolean 型が使用されている場合、Polyspace® はこのルールの違反を報告します。
=&&||!==!=単項の
&および?
トラブルシューティング
ルール違反が想定されるものの、Polyspace から報告されない場合は、コーディング規約違反が想定どおりに表示されない理由の診断を参照してください。
例
チェック情報
| グループ: Standard Conversions |
| カテゴリ: 必要 |
バージョン履歴
R2013b で導入1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.