Menu

cppcheck bug, incorrectLogicOperator, incorrect enum value calculated

2020-02-20
2020-02-21
  • James Foley

    James Foley - 2020-02-20

    cppcheck 1.90 is reporting an incorrect incorrectLogicOperator warning. The value of EE_E is incorrect.


    enum_val_3.cpp:17:27: warning: Logical conjunction always evaluates to false: eeStart < num && num <= 3. [incorrectLogicOperator]
    return ((eeStart < num) && (num <= EE_E));


    #include <iostream>
    
    using namespace std;
    
    const unsigned eeStart = 1000;
    
    enum MyEnum 
    {
      EE_A = eeStart+1,
      EE_B, EE_C, EE_D, EE_E,
    };
    
    bool myEnumCheck(unsigned num)
    {
      return ((eeStart < num) && (num <= EE_E));
    }
    
    
    int main()
    {
      cout << "v1 is " << myEnumCheck(1003) << endl;
      cout << "v2 is " <<  myEnumCheck(99) << endl;
      cout << "Done" << endl;
      return 0;
    }
    
     
  • Daniel Marjamäki

    Thanks! I created this ticket: https://trac.cppcheck.net/ticket/9647

     

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.