Menu

False positive: Opposite inner 'if' condition leads to a dead code block.

2024-10-09
2024-10-09
  • Jean Porcherot

    Jean Porcherot - 2024-10-09

    This code generates what is likelly a false positive:

    #include <string>
    
    #define TYPE_1 "a"
    #define TYPE_2 "b"
    #define TYPE_3 "c"
    
    void Restore( const std::string& channel )
    {
        if ( channel == TYPE_1 )
        {
    
        }
        else if ( channel == TYPE_2 || channel == TYPE_3 )
        {
            // common code for TYPE_2 and TYPE_3
    
            if ( channel == TYPE_2 ) // reporting "warning : Opposite inner 'if' condition leads to a dead code block."
            {
                // specific code for TYPE_2
            }
            else if ( channel == TYPE_3 )
            {
                // specific code for TYPE_3
            }
        }
    }
    
     

    Last edit: Jean Porcherot 2024-10-09
  • CHR

    CHR - 2024-10-09

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

     

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.