missingReturn; Fixed false negative for goto-label

This commit is contained in:
Daniel Marjamäki 2021-07-10 08:49:48 +02:00
parent 8f1cb2304f
commit 53955b48d2
2 changed files with 9 additions and 0 deletions

View File

@ -314,6 +314,8 @@ static const Token *checkMissingReturnScope(const Token *tok)
}
if (tok->isKeyword() && Token::Match(tok, "return|throw"))
return nullptr;
if (Token::Match(tok, "[;{}] %name% :"))
return tok;
if (Token::Match(tok, "; !!}") && !lastStatement)
lastStatement = tok->next();
}

View File

@ -1386,6 +1386,13 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("int foo(int x) {\n"
" if (x) goto out;\n"
" return 1;\n"
"out:\n"
"}");
ASSERT_EQUALS("[test.cpp:3]: (error) Found a exit path from function with non-void return type that has missing return statement\n", errout.str());
// switch
check("int f() {\n"
" switch (x) {\n"