Menu

duplicateValueTernary false positive

2 days ago
2 days ago
  • Nikita Leontiev

    Nikita Leontiev - 2 days ago

    cppcheck 2.18.0 generates duplicateValueTernary false positive for the following code:

    class Base
    {
    };
    
    class A : public Base
    {
    };
    
    class B : public Base
    {
    };
    
    int main(int argc, const char *[])
    {
        A *a = new A();
        B *b = new B();
        Base *p = argc?static_cast<Base*>(a):static_cast<Base*>(b);
        (void)(p);
        delete a;
        delete b;
        return 0;
    }
    
    test\main.cpp:17:38: style: Same value in both branches of ternary operator. [duplicateValueTernary]
     Base *p = argc?static_cast<Base*>(a):static_cast<Base*>(b);
                                         ^
    

    No false positive when lines 15,16 are:

    A *a = new A;
    B *b = new B;
    
     
  • CHR

    CHR - 2 days ago

    Thanks for reporting, ticket is here: https://trac.cppcheck.net/ticket/14300

     

Log in to post a comment.