value flow: added bailout for conditional return/continue/break when number_of_if is bigger than 0
This commit is contained in:
parent
7e43498bcc
commit
be082a8e4a
|
@ -504,6 +504,16 @@ static void valueFlowAfterAssign(TokenList *tokenlist, ErrorLogger *errorLogger,
|
|||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
// noreturn scopes..
|
||||
if (number_of_if > 0 &&
|
||||
(Token::findmatch(start, "return|continue|break", end) ||
|
||||
(Token::Match(end,"} else {") && Token::findmatch(end, "return|continue|break", end->linkAt(2))))) {
|
||||
if (settings->debugwarnings)
|
||||
bailout(tokenlist, errorLogger, tok2, "variable " + var->nameToken()->str() + ". noreturn conditional scope.");
|
||||
break;
|
||||
}
|
||||
|
||||
if (Token::findmatch(start, "++|-- %varid%", end, varid) ||
|
||||
Token::findmatch(start, "%varid% ++|--|=", end, varid)) {
|
||||
if (number_of_if == 0 &&
|
||||
|
|
|
@ -547,6 +547,14 @@ private:
|
|||
"}";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 5U, 1));
|
||||
|
||||
code = "void f(){\n"
|
||||
" int x = 0;\n"
|
||||
" if (a>=0) { x = getx(); }\n"
|
||||
" if (x==0) { return; }\n"
|
||||
" return 123 / x;\n"
|
||||
"}\n";
|
||||
ASSERT_EQUALS(false, testValueOfX(code, 5U, 0));
|
||||
|
||||
// multivariables
|
||||
code = "void f(int a) {\n"
|
||||
" int x = a;\n"
|
||||
|
|
Loading…
Reference in New Issue