Menu

wrong "missing return" findings

Martin
2021-07-08
2021-07-12
  • Martin

    Martin - 2021-07-08

    Hi,

    for the following code wrong "missing return" findings are created:
    "Found a exit path from function with non-void return type that has missing return statement"

    auto foo4() -> void
    {
        asset.close();
    }
    
    virtual ~FL() {};
    

    Also, for these kinds of code examples such wrong findings are created; however I don't know yet why in this specific "artificial code" they don't show up. So here my question is: are "implicit returns" like assert/throw taken into consideration? Sometimes that does not seem to be the case.

    int foo()
    {
        switch(bar)
        {
            case ABC: assert(false); break;
        }
        return 0;
    }
    
    int foo2()
    {
        switch(bar)
        {
            case ABC: return 1; break;
        }
        return 0;
    }
    
    int foo3()
    {
        switch(bar)
        {
            case ABC: throw 1; break;
        }
        return 0;
    }
    

    Best regards,
    Martin

     
  • Daniel Marjamäki

    So here my question is: are "implicit returns" like assert/throw taken into consideration? Sometimes that does not seem to be the case.

    Implicit returns are also considered. If the "return 0" is removed, the warning is written for the "break;".. if that break; is reached in any way then there will be undefined behavior.

    since it's pretty common to write extra redundant breaks in switch statements, as in your code, I think it would be good to add a special heuristic for this.

     
  • Martin

    Martin - 2021-07-12

    Thanks for fixing the first issues!

    Here's another (at least in our code, common) example:

    void VNCCALL foo()
    {
       int a=3;
    }
    

    VNCCALL is a macro that cppcheck doesn't seem to be able to resolve, I don't know why; it is (somewhere else) defined as:

    #define VNCCALL __stdcall
    

    So the real problem seems to be that cppcheck can't find the macro definition there, but it assumes something about this unknown token that leads to an FP regarding "missing return statement".
    What would you suggest?

     
  • CHR

    CHR - 2021-07-12

    There is a ticket for this issue here.

     
  • Martin

    Martin - 2021-07-12

    Ok .... then I'll just add one more (to be honest, obscure-looking) example:

    void virtual foo(const ::a::b::c::d::e::bar& ){};
    

    "void virtual" instead of "virtual void" seems to be allowed according to: https://en.cppreference.com/w/cpp/language/declarations "Declaration specifiers (decl-specifier-seq) is a sequence of the following whitespace-separated specifiers, in any order: ..."

     

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.