JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.TYPE.IOT : Inappropriate Operand Type

Summary

An operand of inappropriate type is used.

A warning of this class will be issued if one or more of the following constraints is not met. The constraints are based on the notion of essential type category as described in MISRA C:2012 Guidelines for the use of the C language in critical systems.

Operator Operand Essential Type Category Must Be
[] index essentially enum, essentially signed, or essentially unsigned
unary + only essentially signed, essentially unsigned, essentially real floating, or essentially complex floating
unary - only essentially signed, essentially real floating, or essentially complex floating
binary +, - either essentially character, essentially signed, essentially unsigned, essentially real floating, or essentially complex floating
++, -- only essentially character, essentially signed, essentially unsigned, or essentially real floating
*, / either essentially signed, essentially unsigned, essentially real floating, or essentially complex floating
% either essentially signed or essentially unsigned
<, <=, >=, > either essentially character, essentially enum, essentially signed, essentially unsigned, or essentially real floating
==, != either essentially Boolean, essentially character, essentially enum, essentially signed, essentially unsigned
!, &&, || any essentially Boolean
<<, >> left essentially unsigned
<<, >> right essentially unsigned
~, ^, &, | any essentially unsigned
?: 1st essentially Boolean
?: 2nd, 3rd any essential type

Properties

Class Name Inappropriate Operand Type
Significance style
Mnemonic LANG.TYPE.IOT
Categories
MisraC2025 MisraC2025:10.1 Operands shall not be of an inappropriate essential type
MisraC2023 MisraC2023:10.1 Operands shall not be of an inappropriate essential type
Misra2012 Misra2012:10.1 Operands shall not be of an inappropriate essential type
Misra2004 Misra2004:6.1 The plain char type shall be used only for storage and use of character values
  Misra2004:6.2 signed and unsigned char type shall be used only for the storage and use of numeric values
  Misra2004:12.6 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 ?:)
  Misra2004:12.7 Bitwise operators shall not be applied to operands whose underlying type is signed
  Misra2004:12.9 The unary minus operator shall not be applied to an expression whose underlying type is unsigned
AUTOSARC++14 AUTOSARC++14:A4-5-1 Expressions with type enum or enum class shall not be used as operands to built-in and overloaded operators other than the subscript operator [ ], the assignment operator =, the equality operators == and ! =, the unary & operator, and the relational operators <, <=, >, >=.
  AUTOSARC++14:M4-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.
  AUTOSARC++14:M4-5-3 Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator =, the equality operators == and ! =, and the unary & operator.
  AUTOSARC++14:M5-0-11 The plain char type shall only be used for the storage and use of character values.
  AUTOSARC++14:M5-0-12 Signed char and unsigned char type shall only be used for the storage and use of numeric values.
  AUTOSARC++14:M5-0-14 The first operand of a conditional-operator shall have type bool.
  AUTOSARC++14:M5-0-20 Non-constant operands to a binary bitwise operator shall have the same underlying type.
  AUTOSARC++14:M5-0-21 Bitwise operators shall only be applied to operands of unsigned underlying type.
  AUTOSARC++14:M5-3-1 Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
  AUTOSARC++14:M5-3-2 The unary minus operator shall not be applied to an expression whose underlying type is unsigned.
MisraC++2008 MisraC++2008: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.
  MisraC++2008:4-5-2 Expressions with type enum shall not be used as operands to built-in operators other than the subscript operator [ ] , the assignment operator = , the equality operators == and != , the unary & operator, and the relational operators < , <= , > , >= .
  MisraC++2008:4-5-3 Expressions with type (plain) char and wchar_t shall not be used as operands to built-in operators other than the assignment operator = , the equality operators == and != , and the unary & operator.
  MisraC++2008:5-0-11 The plain char type shall only be used for the storage and use of character values.
  MisraC++2008:5-0-12 signed char and unsigned char type shall only be used for the storage and use of numeric values.
  MisraC++2008:5-0-14 The first operand of a conditional-operator shall have type bool.
  MisraC++2008:5-0-20 Non-constant operands to a binary bitwise operator shall have the same underlying type.
  MisraC++2008:5-0-21 Bitwise operators shall only be applied to operands of unsigned underlying type.
  MisraC++2008:5-3-1 Each operand of the ! operator, the logical && or the logical || operators shall have type bool.
  MisraC++2008:5-3-2 The unary minus operator shall not be applied to an expression whose underlying type is unsigned.
MisraC++2023 MisraC++2023:7.0.3 The numerical value of a character shall not be used
  MisraC++2023:7.0.4 The operands of bitwise operators and shift operators shall be appropriate
  MisraC++2023:8.3.1 The built-in unary - operator should not be applied to an expression of unsigned type
CERT-C CERT-C:EXP46-C Do not use a bitwise operator with a Boolean-like operand
  CERT-C:INT07-C Use only explicitly signed or unsigned char type for numeric values
  CERT-C:INT13-C Use bitwise operators only on unsigned operands
  CERT-C:STR04-C Use plain char for characters in the basic character set
JSF++ JSF++:164.1 The left-hand operand of a right-shift operator shall not have a negative value.
  JSF++:165 The unary minus operator shall not be applied to an unsigned expression.
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default, and require the unnormalized C ASTs for the project. To enable them, add the following WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Operand Type"
Note that retaining the unnormalized ASTs will increase the disk space used to store the project representation, and may make the analysis take longer.

Example

int TYPE_IOT(int arr[10], int i){
    int x;

    if (i >= 10 || i < 0)                  /* suitable operand types for >=, <, || */ 
        return i;

    x = arr[i];                            /* suitable operand type for [] */
    if (x<0){return x;}
    x = arr[i==5];   /* 'Inappropriate Operand Type' warning issued here */
    if (x<0){return x;}
    x = i * 'a';     /* 'Inappropriate Operand Type' warning issued here */
    return x;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.