Fixed #8914 (False positive with unary_function argument)

This commit is contained in:
Daniel Marjamäki 2018-12-19 19:42:55 +01:00
parent ac15c56f49
commit e2c433a0f8
2 changed files with 32 additions and 1 deletions

View File

@ -1277,6 +1277,11 @@ bool FwdAnalysis::isGlobalData(const Token *expr) const
return ChildrenToVisit::none;
}
}
// Unknown argument type => it might be some reference type..
if (mCpp && tok->str() == "." && tok->astOperand1() && tok->astOperand1()->variable() && !tok->astOperand1()->valueType()) {
globalData = true;
return ChildrenToVisit::none;
}
if (Token::Match(tok, ".|["))
return ChildrenToVisit::op1;
return ChildrenToVisit::op1_and_op2;

View File

@ -4412,7 +4412,7 @@ private:
);
ASSERT_EQUALS("", errout.str());
// Unknown variable
// Unknown argument type
functionVariableUsage(
"void A::b(Date& result) {"
" result = 12;\n"
@ -4420,6 +4420,32 @@ private:
);
ASSERT_EQUALS("", errout.str());
{
// #8914
functionVariableUsage( // assume unknown argument type is reference
"void fun(Date result) {"
" result.x = 12;\n"
"}"
);
ASSERT_EQUALS("", errout.str());
functionVariableUsage( // there is no reference type in C
"void fun(Date result) {"
" result.x = 12;\n"
"}",
"test.c"
);
ASSERT_EQUALS("[test.c:1]: (style) Variable 'result.x' is assigned a value that is never used.\n", errout.str());
functionVariableUsage(
"struct Date { int x; };\n"
"void fun(Date result) {"
" result.x = 12;\n"
"}"
);
ASSERT_EQUALS("[test.cpp:2]: (style) Variable 'result.x' is assigned a value that is never used.\n", errout.str());
}
// Unknown struct type
functionVariableUsage(
"void fun() {"