Fixed #3857 (false negative: (style) Variable 'var' is assigned a value that is never used)
This commit is contained in:
parent
8195a76035
commit
858d9a18a7
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue