MISRA C++:2023 Rule 7.0.1
Description
Rule Definition
There shall be no conversion from type
bool
.
Rationale
Logical errors can occur when a boolean value is implicitly converted to another type.
These converted values can then be used in contexts where they were not intended to be used,
leading to subtle bugs that can be difficult to diagnose. Additionally, this rule helps
identify scenarios where a bitwise operator such as |
or
&
has been accidentally used instead of a logical operator such as
||
or &&
because using bitwise operators
instead of logical operators can result in conversions from type
bool
.
Polyspace Implementation
The rule checker reports a violation when you perform a conversion from type
bool
, including integer promotion or arithmetic conversions. An
exception occurs when assigning a boolean to a bit-field of length 1. In this case, a
false
value is converted to 0
and a
true
value is converted to 1
.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Standard Conversions |
Category: Required |
Version History
Introduced in R2024b