Menu

assertWithSideEffect and function confusion

2020-06-12
2020-06-13
  • Sébastien Gallou

    Hello,

    CppCheck warns me (assertWithSideEffect) about this code :
    assert(fct());

    With fct defined as follow :
    int fct() { return 3; }
    int fct() const { return 3; }

    It seems that CppCheck uses the non-const definition of fct. If I
    comment out the non-const definition, the CppCheck warning disappears.

    What is the right way to fix this warning ?

    Thanks,

     
  • Daniel Marjamäki

    not sure what the right fix is.. if you feel that your code should work fine then maybe you could elaborate a bit and we can try to fix the false positive.

    I assume that Cppcheck parser is right to "call" the non-const fct() function by default? If the Cppcheck parser picked the wrong function then obviously we should fix that.

     

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.