Skip to main content

IAR Embedded Workbench for RISC-V 3.40

MISRAC2004-12.6_b

In this section:
Synopsis

(Advisory) Expressions that are effectively boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, and ?:).

Enabled by default

No

Severity/Certainty

Low/Low

lowlow.png
Full description

Uses of arithmetic operators on Boolean operands were found. This check is identical to MISRAC++2008-4-5-1.

Coding standards
MISRA C:2004 12.6

(Advisory) The operands of logical operators (&&, ||, and !) should be effectively boolean. Expressions that are effectively boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, and ?:).

MISRA C++ 2008 4-5-1

(Required) 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.

Code examples

The following code example fails the check and will give a warning:

void func(bool b)
{
  bool x;
  bool y;
  y = x % b;
}

The following code example passes the check and will not give a warning about this issue:

typedef char	boolean_t;	/* Compliant: Boolean-by-enforcement */

void example(void)
{
    boolean_t d;
    boolean_t c = 1;
    boolean_t b = 0;
    boolean_t a = 1;

    d = ( c && a ) && b;

}
void func()
{
  bool x;
  bool y;
  y = x && y;
}