cppcheckmisra

Cppcheck, how inline-suppression works with MISRA add-on


I tried inline suppression with Cppcheck and MISRA add-on:

My example:

    // /* Send number of data */

Generate the error:

"misra-c2012-3.1" severity="style" msg="The character sequences /* and // shall not be used within a comment"

But if I use:

    // cppcheck-suppress  misra-c2012-3.1
    // /* Send number of data */

the error persists.

I tried the following ID syntax:

Each time, the error is raised.

I use the option --inline-suppr


Solution

  • It seems like you have found a bug. Your approach looks correct to me.

    For the following C code (here in the file misra_suppression_test.c) the suppression works:

    // cppcheck-suppress misra-c2012-2.7
    void misra_2_7_unused_param (int *param1, int unused_param)
    {
        *param1 = 42U;
    }
    

    Without --inline-suppr the violation is reported:

    $ ./cppcheck --enable=style --addon=misra misra_suppression_test.c
    Checking misra_suppression_test.c ...
    misra_suppression_test.c:2:6: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.7]
    void misra_2_7_unused_param (int *param1, int unused_param)
         ^
    

    With --inline-suppr the violation is no longer reported:

    $ ./cppcheck --enable=style --addon=misra --inline-suppr misra_suprpession_test.c
    Checking misra_suppression_test.c ...
    

    It looks like suppression is not working for rule 3.1 or so.