Effective boolean types (-boolean-types
)
Specify data types that coding rule checker must treat as effectively Boolean
Description
Specify data types that the coding rule checker must treat as effectively Boolean. You can
specify a data type as effectively Boolean only if you have defined it through an
enum
or typedef
statement in your source
code.
By default, Polyspace® supports these boolean types:
Type
_Bool
in C99 once you includestdbool.h
in one of your source files. The macrostrue
andfalse
are considered effectively Boolean.Type
bool
in C11 and for all versions of C++.
If you specify this option, Polyspace considers these additional types as effectively Boolean:
The data types you specify as input to this option.
Macros
true
/TRUE
/True
andfalse
/FALSE
/False
if they have values1
and0
respectively.
Set Option
Set the option using one of these methods:
Polyspace user interface (desktop products only): In your project configuration, select the Coding Standards & Code Metrics node and then enter values for this option. See Dependencies for other options you must enable first.
Polyspace Platform user interface (desktop products only): In your project configuration, on the Static Analysis tab, select the Defects and Coding Standards > Checkers Behavior node and then enter values for this option. See Dependencies for other options you must enable first.
Command line and options file: Use the option
-boolean-types
. See Command-Line Information.
Why Use This Option
Use this option to allow Polyspace to check the following coding rules:
MISRA C™: 2012
Rule Number Rule Statement 10.1 Operands shall not be of an inappropriate essential type 10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category 10.5 The value of an expression should not be cast to an inappropriate essential type 14.4 The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. 16.7 A switch-expression shall not have essentially Boolean type. MISRA C: 2023
Rule Number Rule Statement 10.1 Operands shall not be of an inappropriate essential type 10.3 The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category 10.5 The value of an expression should not be cast to an inappropriate essential type 14.4 The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type. 16.7 A switch-expression shall not have essentially Boolean type.
For example, in the following code, Polyspace detects a violation of MISRA C: 2012 rule 14.4 because boolean_T
is not recognized
as effective boolean. If you rerun the analysis and specify option
-boolean-types boolean_T
, Polyspace considers that the code is compliant with rule 14.4.
typedef int boolean_T; void func1(void); void func2(void); void func(boolean_T flag) { if(flag) // No misra2012 14.4 violation when you use -boolean-types func1(); else func2(); }
Settings
No Default
Click to add a field. Enter
a type name that you want Polyspace to treat as Boolean.
Dependencies
This option is enabled only if you select one of these options in the Polyspace user interface:
Or the option Use custom checkers file
in the Polyspace Platform user interface.
Command-Line Information
Parameter: -boolean-types |
Value:
|
No Default |
Example (Bug Finder): polyspace-bug-finder
-sources |
Example (Bug Finder Server):
polyspace-bug-finder-server -sources |