Fixed #6261 (false positive: Variable used in ternary expression within function argument list)

This commit is contained in:
Daniel Marjamäki 2017-07-01 11:03:49 +02:00
parent 4827751b04
commit db01ea1408
2 changed files with 16 additions and 1 deletions

View File

@ -691,7 +691,7 @@ static void useFunctionArgs(const Token *tok, Variables& variables)
// TODO: Match function args to see if they are const or not. Assume that const data is not written. // TODO: Match function args to see if they are const or not. Assume that const data is not written.
if (!tok) if (!tok)
return; return;
if (Token::Match(tok, "[,+]")) { if (Token::Match(tok, "[,+?:]")) {
useFunctionArgs(tok->astOperand1(), variables); useFunctionArgs(tok->astOperand1(), variables);
useFunctionArgs(tok->astOperand2(), variables); useFunctionArgs(tok->astOperand2(), variables);
} else if (tok->variable() && tok->variable()->isArray()) { } else if (tok->variable() && tok->variable()->isArray()) {

View File

@ -102,6 +102,7 @@ private:
TEST_CASE(localvar47); // ticket #6603 TEST_CASE(localvar47); // ticket #6603
TEST_CASE(localvar48); // ticket #6954 TEST_CASE(localvar48); // ticket #6954
TEST_CASE(localvar49); // ticket #7594 TEST_CASE(localvar49); // ticket #7594
TEST_CASE(localvar50); // ticket #6261 : dostuff(cond ? buf1 : buf2)
TEST_CASE(localvaralias1); TEST_CASE(localvaralias1);
TEST_CASE(localvaralias2); // ticket #1637 TEST_CASE(localvaralias2); // ticket #1637
TEST_CASE(localvaralias3); // ticket #1639 TEST_CASE(localvaralias3); // ticket #1639
@ -2018,6 +2019,20 @@ private:
ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); ASSERT_EQUALS("[test.cpp:16]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str());
} }
void localvar50() { // #6261
functionVariableUsage("void foo() {\n"
" char buf1[10];\n"
" dostuff(cond?buf1:buf2);\n"
"}");
ASSERT_EQUALS("", errout.str());
functionVariableUsage("void foo() {\n"
" char buf1[10];\n"
" dostuff(cond?buf2:buf1);\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvaralias1() { void localvaralias1() {
functionVariableUsage("void foo()\n" functionVariableUsage("void foo()\n"
"{\n" "{\n"