Fixed #10095 (False positive: unreadVariable)
This commit is contained in:
parent
58dad23444
commit
a55b0c332a
|
@ -2832,6 +2832,8 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
|||
bool same = tok->astParent() && isSameExpression(mCpp, false, expr, tok, mLibrary, true, false, nullptr);
|
||||
while (!same && Token::Match(parent->astParent(), "*|.|::|[|(|%cop%")) {
|
||||
parent = parent->astParent();
|
||||
if (parent->str() == "(" && !parent->isCast())
|
||||
break;
|
||||
if (parent && isSameExpression(mCpp, false, expr, parent, mLibrary, true, false, nullptr)) {
|
||||
same = true;
|
||||
if (mWhat == What::ValueFlow) {
|
||||
|
@ -2841,7 +2843,8 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
|
|||
mValueFlow.push_back(v);
|
||||
}
|
||||
}
|
||||
if (Token::Match(parent, ". %var%") && parent->next()->varId() && exprVarIds.find(parent->next()->varId()) == exprVarIds.end()) {
|
||||
if (Token::Match(parent, ". %var%") && parent->next()->varId() && exprVarIds.find(parent->next()->varId()) == exprVarIds.end() &&
|
||||
isSameExpression(mCpp, false, expr->astOperand1(), parent->astOperand1(), mLibrary, true, false, nullptr)) {
|
||||
other = true;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -172,6 +172,7 @@ private:
|
|||
TEST_CASE(localvarStruct8);
|
||||
TEST_CASE(localvarStruct9);
|
||||
TEST_CASE(localvarStruct10);
|
||||
TEST_CASE(localvarStruct11); // 10095
|
||||
TEST_CASE(localvarStructArray);
|
||||
TEST_CASE(localvarUnion1);
|
||||
|
||||
|
@ -4496,6 +4497,18 @@ private:
|
|||
ASSERT_EQUALS("[test.cpp:5]: (style) Variable 's.x' is assigned a value that is never used.\n", errout.str());
|
||||
}
|
||||
|
||||
void localvarStruct11() { // #10095
|
||||
functionVariableUsage("struct Point { int x; int y; };\n"
|
||||
"Point scale(Point *p);\n"
|
||||
"\n"
|
||||
"int foo() {\n"
|
||||
" Point p;\n"
|
||||
" p.x = 42;\n"
|
||||
" return scale(&p).y;\n"
|
||||
"}");
|
||||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void localvarStructArray() {
|
||||
// extracttests.start: struct X {int a;};
|
||||
|
||||
|
|
Loading…
Reference in New Issue