parent
2878c68ec0
commit
d2546d5252
|
@ -3844,6 +3844,13 @@ const Token* ValueFlow::getEndOfExprScope(const Token* tok, const Scope* default
|
|||
const Token* varEnd = getEndOfVarScope(var);
|
||||
if (!end || (smallest ? precedes(varEnd, end) : succeeds(varEnd, end)))
|
||||
end = varEnd;
|
||||
|
||||
const Token* top = var->nameToken()->astTop();
|
||||
if (top && Token::simpleMatch(top->tokAt(-1), "if (")) { // variable declared in if (...)
|
||||
const Token* elseTok = top->link()->linkAt(1);
|
||||
if (Token::simpleMatch(elseTok, "} else {") && tok->scope()->isNestedIn(elseTok->tokAt(2)->scope()))
|
||||
end = tok->scope()->bodyEnd;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ChildrenToVisit::op1_and_op2;
|
||||
|
|
|
@ -5446,6 +5446,37 @@ private:
|
|||
" return y;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("int f(int i) {\n" // #11788
|
||||
" if (int x = i) {\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" x = 12;\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
|
||||
functionVariableUsage("void f(int i) {\n"
|
||||
" if (int x = i) {\n"
|
||||
" while (x < 100) {\n"
|
||||
" if (x % 2 == 0) {\n"
|
||||
" x += 3;\n"
|
||||
" }\n"
|
||||
" else if (x % 3 == 0) {\n"
|
||||
" x += 5;\n"
|
||||
" }\n"
|
||||
" else {\n"
|
||||
" x += 7;\n"
|
||||
" }\n"
|
||||
" x += 6;\n"
|
||||
" }\n"
|
||||
" return x;\n"
|
||||
" }\n"
|
||||
" return i;\n"
|
||||
"}\n");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarOpAssign() {
|
||||
|
|
Loading…
Reference in New Issue