Menu

MISRA 15.6 False positive Do while

Julien
2021-08-30
2021-11-01
  • Julien

    Julien - 2021-08-30

    I have one minor issue with MISRA 15.6 rule :

    do
    {
        something();
    } while (condition) ;
    

    Works fine, but with a comment on do line :

    do // Comment
    {
        something();
    } while (condition) ;
    

    I get this 15.6 rule violation : shall be a compound-statement ... as if recognized as a while instead of a do while.
    It seems to be waiting for the braces around ;

     
  • Julien

    Julien - 2021-10-22

    Hi Daniel, should I keep post my issues here or is there a better place somewhere else ? I don't success accessing to TRAC.

    I have few other things to discuss about MISRA, I guess I have another false positive with the latest rules implemented on Cppcheck v2.6.

    Thank you

    Julien

     
    • Daniel Marjamäki

      I think it sounds better that you report it in trac directly. Can you create a htpasswd hash and send it to me?

       
  • Julien

    Julien - 2021-10-25
     

    Last edit: Julien 2021-10-26
  • Daniel Marjamäki

    can you please tweak the example code. I get this syntax error:

    10560.c:4:3: error: syntax error: keyword 'while' is not allowed in global scope [syntaxError]

     
  • Julien

    Julien - 2021-10-26

    Please try with this code :

    void MyFunc(void)
    {
        uint8_t value = 0U;
        do // Test
        {
            value++;
        }
        while (value < 2U);
    }
    

    src\main.c:330:5: style: Required ... [misra-c2012-15.6]
    while (value < 2U);
    ^

    For information, when I add/remove the comment I have to delete temporary files in cppcheck-build-dir. As a single comment change does not retrigger the analysis and so previous results are used.

     
    • Daniel Marjamäki

      Thanks! I can reproduce. I have created https://trac.cppcheck.net/ticket/10583

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.