Main Content

Effective boolean types (-boolean-types)

(Removed) Specify data types that coding rule checker must treat as effectively Boolean

This option applies only to coding rules, which has been removed from Code Prover. Use Effective boolean types (-boolean-types) in Bug Finder instead. For more information, see Version History.

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.

Set Option

User interface (desktop products only): In your project configuration, the option is on the Coding Standards & Code Metrics node. See Dependencies for other options that you must also enable.

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™: 2004 and MISRA™ AC AGC

    Rule NumberRule Statement
    12.6Operands of logical operators, &&, ||, and !, should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to other operators.
    13.2Tests of a value against zero should be made explicit, unless the operand is effectively Boolean.
    15.4A switch expression should not represent a value that is effectively Boolean.

  • MISRA C: 2012

    Rule NumberRule Statement
    10.1Operands shall not be of an inappropriate essential type
    10.3The value of an expression shall not be assigned to an object with a narrower essential type or of a different essential type category
    10.5The value of an expression should not be cast to an inappropriate essential type
    14.4The controlling expression of an if statement and the controlling expression of an iteration-statement shall have essentially Boolean type.
    16.7A switch-expression shall not have essentially Boolean type.

For example, in the following code, unless you specify myBool as effectively Boolean, Polyspace detects a violation of MISRA C: 2012 rule 14.4.

typedef int myBool;

void func1(void);
void func2(void);

void func(myBool flag) {
    if(flag)
        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:

Command-Line Information

Parameter: -boolean-types
Value: type1[,type2[,...]]
No Default
Example (Bug Finder): polyspace-bug-finder -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t
Example (Code Prover): polyspace-code-prover -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t
Example (Bug Finder Server): polyspace-bug-finder-server -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t
Example (Code Prover Server): polyspace-code-prover-server -sources filename -misra2 required-rules -boolean-types boolean1_t,boolean2_t

Version History

expand all

R2024a: Removed from Code Prover

If you use the option -boolean-types in a Code Prover analysis, Polyspace issues a warning and the analysis ignores the option. The workflow for checking coding rule violation has been removed from Code Prover. To check for coding rule violations, use Bug Finder. For instance, at the command line, replace this command:

polyspace-code-prover -sources SRC -misra3 all -boolean-types boolean1_t
with this command:
polyspace-bug-finder -sources SRC -misra3 all -boolean-types boolean1_t
See Migrate Code Prover Workflows for Checking Coding Standards and Code Metrics to Bug Finder.