This diagnostic rule is based on the software development guidelines developed by MISRA (Motor Industry Software Reliability Association).
This diagnostic rule is only relevant for C. The values used in expressions should have appropriate essential types.
The MISRA standard defines the following essential type model, in which a variable may have a type:
There are no pointers in this model.
In C language, there are no restrictions on operations with basic types, but some of these operations may have unspecified/undefined behavior or make no sense at all. For example:
Implicit castings to essential Boolean may also be dangerous, as not all decimals can be represented in the binary number system.
void Foo(float f, _Bool other_expr)
{
If (f || other_expr) ....
}
The following table gives intersections of operands and operations types, which shouldn't be composed in expressions. These intersections are marked with the 'X' sign.
An example of the code for which the analyzer will issue relevant warnings:
void Foo(float f, _Bool b, int a[], enum E e)
{
if (~a[(e ? 1 : 2) >> (-b * f --> +b) << signed(-24U)]) ....;
}
Exception: expression of a signed type with a positive value can be used as the right-hand operand of a shift operator (>>, <<).
void foo(signed vi, unsigned _)
{
assert(vi >= 0);
_ >> vi;
_ << vi;
}
This diagnostic is classified as:
|