Menu

False positive: duplicateCondition

CHR
2020-09-08
2020-09-08
  • CHR

    CHR - 2020-09-08

    Cppcheck 2.1 warns about a duplicate condition, even if the state of the object has changed in between:

    struct Foo {
        int i{};
        void nonconst() { ++i; }
        int GetI() const { return i; }  
        void doIt() {
            if (GetI() == 0)
                nonconst();
            if (GetI() == 0) // style: The if condition is the same as the previous if condition
                nonconst();
            }
    };
    
    int main() {
        Foo f;
        f.doIt();
        return 0;
    }
    
     
  • Daniel Marjamäki

    Thanks! I can reproduce with cppcheck-2.0 but I can't reproduce with cppcheck-HEAD. So I hope this is fixed.

     
  • CHR

    CHR - 2020-09-08

    That would be nice! Currently, I am unable to test with HEAD myself.

     

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.