missingReturn; Fixed false negative for goto-label
This commit is contained in:
parent
8f1cb2304f
commit
53955b48d2
|
@ -314,6 +314,8 @@ static const Token *checkMissingReturnScope(const Token *tok)
|
||||||
}
|
}
|
||||||
if (tok->isKeyword() && Token::Match(tok, "return|throw"))
|
if (tok->isKeyword() && Token::Match(tok, "return|throw"))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
if (Token::Match(tok, "[;{}] %name% :"))
|
||||||
|
return tok;
|
||||||
if (Token::Match(tok, "; !!}") && !lastStatement)
|
if (Token::Match(tok, "; !!}") && !lastStatement)
|
||||||
lastStatement = tok->next();
|
lastStatement = tok->next();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1386,6 +1386,13 @@ private:
|
||||||
"}");
|
"}");
|
||||||
ASSERT_EQUALS("", errout.str());
|
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
|
// switch
|
||||||
check("int f() {\n"
|
check("int f() {\n"
|
||||||
" switch (x) {\n"
|
" switch (x) {\n"
|
||||||
|
|
Loading…
Reference in New Issue