Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used)

This commit is contained in:
Daniel Marjamäki 2018-12-17 15:16:47 +01:00
parent 8195a76035
commit 858d9a18a7
2 changed files with 16 additions and 1 deletions

View File

@ -1166,7 +1166,7 @@ struct FwdAnalysis::Result FwdAnalysis::checkRecursive(const Token *expr, const
const Token *parent = tok;
bool other = false;
bool same = false;
while (Token::Match(parent->astParent(), ".|::|[")) {
while (Token::Match(parent->astParent(), "*|.|::|[")) {
parent = parent->astParent();
if (parent && isSameExpression(mCpp, false, expr, parent->astOperand1(), mLibrary, false, false, nullptr))
same = true;

View File

@ -5969,6 +5969,21 @@ private:
" memptr = 0;\n"
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'memptr' is reassigned a value before the old one has been used.\n", errout.str());
// Pointer function argument (#3857)
check("void f(float * var)\n"
"{\n"
" var[0] = 0.2f;\n"
" var[0] = 0.2f;\n" // <-- is initialized twice
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable 'var[0]' is reassigned a value before the old one has been used.\n", errout.str());
check("void f(float * var)\n"
"{\n"
" *var = 0.2f;\n"
" *var = 0.2f;\n" // <-- is initialized twice
"}");
ASSERT_EQUALS("[test.cpp:3] -> [test.cpp:4]: (style) Variable '*var' is reassigned a value before the old one has been used.\n", errout.str());
}
void redundantVarAssignment_struct() {