Fixed #3104 (unread despite modified and used in IF statement)

This commit is contained in:
Daniel Marjamäki 2011-09-11 08:19:35 +02:00
parent d93354a974
commit 9a97fbe022
2 changed files with 15 additions and 0 deletions

View File

@ -3667,6 +3667,10 @@ void Tokenizer::setVarId()
if (tok != _tokens && !Token::Match(tok, "[;{}(,] %type%") && !Token::Match(tok, "[;{}(,] ::"))
continue;
// Ticket #3104 - "if (NOT x)"
if (tok->str() == "(" && tok->next()->str() == "NOT")
continue;
if (_errorLogger)
_errorLogger->reportProgress(_files[0], "Tokenize (set variable id)", tok->progressValue());

View File

@ -124,6 +124,7 @@ private:
TEST_CASE(localvarClass);
TEST_CASE(localvarUnused);
TEST_CASE(localvarFunction); // ticket #1799
TEST_CASE(localvarIfNOT); // #3104 - if ( NOT var )
}
void checkStructMemberUsage(const char code[])
@ -2979,6 +2980,16 @@ private:
"}\n");
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'b' is assigned a value that is never used\n", errout.str());
}
// ticket #3104 - false positive when variable is read with "if (NOT var)"
void localvarIfNOT()
{
functionVariableUsage("void f() {\n"
" bool x = foo();\n"
" if (NOT x) { }\n"
"}");
ASSERT_EQUALS("", errout.str());
}
};
REGISTER_TEST(TestUnusedVar)