Menu

false positive——incorrect enum parsing

2020-06-26
2020-10-19
  • houzhengtao

    houzhengtao - 2020-06-26
    constexpr   int   BASE = 7;
    
    enum enum_test {
        A = BASE + 10,
        B
    };
    
    int test()
    {
        return 100 / B;
    }
    

    error report :
    test_5.cpp:10:16: error: Division by zero. [zerodiv]
            return 100 / B;
                                     ^

    Incorrectly parse enum value B into 0 which is really 18.

     
  • Daniel Marjamäki

    Thanks! I believe this is covered by the ticket: https://trac.cppcheck.net/ticket/9647

     
  • houzhengtao

    houzhengtao - 2020-06-28

    Thanks for your reply!

     
  • houzhengtao

    houzhengtao - 2020-06-28

    This issue has brought us a lot of trouble, hoping to repair it as soon as possible. By the way, how is the problem going?

     
  • Daniel Marjamäki

    If you want to investigate the issue please feel free to do it. imho cppcheck source code is pretty easy to install and debug, there are no dependencies you have to install.

    If you want to speedup my bugfix feel free to look at: https://github.com/sponsors/danmar/

     
  • rikard

    rikard - 2020-10-19

    This false positive is fixed in the git repo and will be part of the next release. There is still room for improvements to set the correct values but t least wrong values will not be set.

     

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.