Menu

embed suppress comment into normal comment

F Schwa
2021-04-06
2021-04-07
  • F Schwa

    F Schwa - 2021-04-06

    Hi,

    currently we have a case where we would like to suppress a certain checker message but the lines of code in question already have a trailing comment. From what I can see, the suppress comment needs to be at the begining of the comment and the normal code comment can come after that.

    This way however, the "interesting" comment runs out of screen space.

    For us it would be nice if a suppress comment could be at any position within a normal comment.

    Command:

    cppcheck --inline-suppr --enable=all main.c
    

    working:

    int main(void)
    {
        int x; // cppcheck-suppress unusedVariable normal comment 
    }
    

    not working:

    int main(void)
    {
        int x; // normal comment cppcheck-suppress unusedVariable
    }
    

    Is there a reason for this being forbidden?

    Cheers

     
  • Daniel Marjamäki

    hm. I am not against it in principle I just like if there is somewhat strict syntax. do you have some suggestion how a user can clearly indicate that it should be a cppcheck suppression?

    if you grep for "TODO cppcheck-suppress" in cppcheck/test/cfg/ then you can see many cases where we want cppcheck to ignore the suppression because we have put the TODO before it.

     
  • F Schwa

    F Schwa - 2021-04-07

    Hi,

    thanks for your reply.

    To be honest, I have problems seeing from a quick glance what the reason for the TODO comments is.

    // cppcheck-suppress bufferAccessOutOfBounds
    // TODO cppcheck-suppress redundantCopy
    std::strcpy(a, "abcde");
    

    is the same as

    // cppcheck-suppress bufferAccessOutOfBounds
    std::strcpy(a, "abcde");
    

    right? Or is there a special meening to the TOD comment within the test suite?

    If it is not a TODO in its usual meaning, I probably would go with something like

    // cppcheck-suppress bufferAccessOutOfBounds
    // cppcheck-NO-suppress redundantCopy
    std::strcpy(a, "abcde");
    

    If it is however a TODO to remind code-readers that there are open points here, and those comments are not parsed in any way, I would probably do something like

    // cppcheck-suppress bufferAccessOutOfBounds
    // TODO suppress redundantCopy
    std::strcpy(a, "abcde");
    

    But, as I said, I have trouble understanding the intent of the code so there might be good reasons to have it as it is.

    When it comes to a strict syntax, it's the easier part to come up with some syntax. The problem is the comapatibility with the existing syntax. Parsers tend to get quite messy when allowing too many variations of suppression comments. So I refrain from randomly throwing in suggestion for a comment-embedded syntax here until I understand your case better. :)

    Cheers

     

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.