Operands shall not be of an inappropriate essential type
Operands shall not be of an inappropriate essential type.
An essential type category defines the essential type of an object or expression.
| Essential type category | Standard types |
|---|---|
Essentially Boolean |
You can also define types that are
essentially Boolean using the option |
Essentially character | char |
Essentially enum | named enum |
Essentially signed | signed char, signed short,
signed int, signed long, signed long
long |
Essentially unsigned | unsigned char, unsigned short,
unsigned int, unsigned long,
unsigned long long |
Essentially floating | float, double, long
double |
For more information on analysis options, see the documentation for Polyspace® Code Prover™ or Polyspace Code Prover Server™.
For operands of some operators, you cannot use certain essential types. In the table below, each row represents an operator/operand combination. If the essential type column is not empty for that row, there is a MISRA restriction when using that type as the operand. The number in the table corresponds to the rationale list after the table.
| Operation | Essential type category of arithmetic operand | ||||||
|---|---|---|---|---|---|---|---|
| Operator | Operand | Boolean | character | enum | signed | unsigned | floating |
[ ] | integer | 3 | 4 | 1 | |||
+ (unary) | 3 | 4 | 5 | ||||
- (unary) | 3 | 4 | 5 | 8 | |||
+ - | either | 3 | 5 | ||||
* / | either | 3 | 4 | 5 | |||
% | either | 3 | 4 | 5 | 1 | ||
< > <= >= | either | 3 | |||||
== != | either | ||||||
! && || | any | 2 | 2 | 2 | 2 | 2 | |
<< >> | left | 3 | 4 | 5,6 | 6 | 1 | |
<< >> | right | 3 | 4 | 7 | 7 | 1 | |
~ & | ^ | any | 3 | 4 | 5,6 | 6 | 1 | |
?: | 1st | 2 | 2 | 2 | 2 | 2 | |
?: | 2nd and 3rd | ||||||
An expression of essentially floating type for these operands is a constraint violation.
When an operand is interpreted as a Boolean value, use an expression of essentially Boolean type.
When an operand is interpreted as a numeric value, do not use an operand of essentially Boolean type.
When an operand is interpreted as a numeric value, do not use an operand of essentially character type. The numeric values of character data are implementation-defined.
In an arithmetic operation, do not use an operand of essentially enum type. An enum object uses an implementation-defined integer type. An operation involving an enum object can therefore yield a result with an unexpected type.
Perform only shift and bitwise operations on operands of essentially unsigned type. When you use shift and bitwise operations on essentially signed types, the resulting numeric value is implementation-defined.
To avoid undefined behavior on negative shifts, use an essentially unsigned right-hand operand.
For the unary minus operator, do not use an operand of essentially unsigned type. The implemented size of int determines the signedness of the result.
Note that for a bit-field type, if the bit-field is implemented as:
A Boolean, the bit-field is essentially Boolean.
Signed or unsigned type, the bit-field is essentially signed or unsigned respectively.
The type of the bit-field is the smallest type that can represent the bit-field.
For instance, the type stmp here is essentially 8 bits
integer:
typedef signed int mybitfield;
typedef struct { mybitfield f1 : 1; } stmp;
The operand_name operand of the operator_name operator
is of an inappropriate essential type category category_name.
If you expect a rule violation but do not see it, refer to the documentation of Polyspace Code Prover or Polyspace Code Prover Server.
| Group: The Essential Type Model |
| Category: Required |
| AGC Category: Advisory |