Fix 10574: ValueFlow: conditional values in constructor initializer list (#3556)
This commit is contained in:
parent
c057dcce0f
commit
771188238c
|
@ -127,6 +127,11 @@ struct ReverseTraversal {
|
||||||
i = tok->index();
|
i = tok->index();
|
||||||
if (tok == start || (tok->str() == "{" && (tok->scope()->type == Scope::ScopeType::eFunction ||
|
if (tok == start || (tok->str() == "{" && (tok->scope()->type == Scope::ScopeType::eFunction ||
|
||||||
tok->scope()->type == Scope::ScopeType::eLambda))) {
|
tok->scope()->type == Scope::ScopeType::eLambda))) {
|
||||||
|
const Function* f = tok->scope()->function;
|
||||||
|
if (f && f->isConstructor()) {
|
||||||
|
if (const Token* initList = f->constructorMemberInitialization())
|
||||||
|
traverse(tok->previous(), tok->tokAt(initList->index() - tok->index()));
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Token::Match(tok, "return|break|continue"))
|
if (Token::Match(tok, "return|break|continue"))
|
||||||
|
|
|
@ -81,6 +81,7 @@ private:
|
||||||
TEST_CASE(valueFlowBeforeConditionSwitch);
|
TEST_CASE(valueFlowBeforeConditionSwitch);
|
||||||
TEST_CASE(valueFlowBeforeConditionTernaryOp);
|
TEST_CASE(valueFlowBeforeConditionTernaryOp);
|
||||||
TEST_CASE(valueFlowBeforeConditionForward);
|
TEST_CASE(valueFlowBeforeConditionForward);
|
||||||
|
TEST_CASE(valueFlowBeforeConditionConstructor);
|
||||||
|
|
||||||
TEST_CASE(valueFlowAfterAssign);
|
TEST_CASE(valueFlowAfterAssign);
|
||||||
TEST_CASE(valueFlowAfterSwap);
|
TEST_CASE(valueFlowAfterSwap);
|
||||||
|
@ -1753,6 +1754,30 @@ private:
|
||||||
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123));
|
ASSERT_EQUALS(true, testValueOfX(code, 4U, 123));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void valueFlowBeforeConditionConstructor()
|
||||||
|
{
|
||||||
|
const char* code;
|
||||||
|
|
||||||
|
code = "struct Fred {\n"
|
||||||
|
" Fred(int *x)\n"
|
||||||
|
" : i(*x) {\n" // <- dereference x
|
||||||
|
" if (!x) {}\n" // <- check x
|
||||||
|
" }\n"
|
||||||
|
" int i;\n"
|
||||||
|
"};\n";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
|
||||||
|
code = "struct Fred {\n"
|
||||||
|
" Fred(int *x)\n"
|
||||||
|
" : i(*x), j(0) {\n" // <- dereference x
|
||||||
|
" if (!x) {}\n" // <- check x
|
||||||
|
" }\n"
|
||||||
|
" int i;\n"
|
||||||
|
" int j;\n"
|
||||||
|
"};\n";
|
||||||
|
ASSERT_EQUALS(true, testValueOfX(code, 3U, 0));
|
||||||
|
}
|
||||||
|
|
||||||
void valueFlowAfterAssign() {
|
void valueFlowAfterAssign() {
|
||||||
const char *code;
|
const char *code;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue