Variable usage: fixed false positive reported in #1729

This commit is contained in:
Robert Reif 2010-07-08 08:42:34 +02:00 committed by Daniel Marjamäki
parent 2d6dfa57e1
commit 566b4b4beb
2 changed files with 26 additions and 0 deletions

View File

@ -903,6 +903,12 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
next = start + 5 + offset;
}
// check for var ? ...
else if (Token::Match(tok->tokAt(start), "%var% ?"))
{
next = start;
}
// no cast
else
{
@ -937,6 +943,13 @@ static int doAssignment(Variables &variables, const Token *tok, bool dereference
variables.alias(varid1, varid2, replace);
}
else if (tok->tokAt(next + 1)->str() == "?")
{
if (var2->_type == Variables::reference)
variables.readAliases(varid2);
else
variables.read(varid2);
}
}
}
else if (var1->_type == Variables::reference)

View File

@ -70,6 +70,7 @@ private:
TEST_CASE(localvar22); // ticket #1811
TEST_CASE(localvar23); // ticket #1808
TEST_CASE(localvar24); // ticket #1803
TEST_CASE(localvar25); // ticket #1729
TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639
@ -1232,6 +1233,18 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvar25() // ticket #1729
{
functionVariableUsage("int main() {\n"
" int ppos = 1;\n"
" int pneg = 0;\n"
" const char*edge = ppos? \" +\" : pneg ? \" -\" : \"\";\n"
" printf(\"This should be a '+' -> %s\n\", edge);\n"
" return 0;\n"
"}\n");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1()
{
functionVariableUsage("void foo()\n"