Fix false positive 'passedByValue' when address of argument is used

This commit is contained in:
Daniel Marjamäki 2018-06-23 23:25:06 +02:00
parent db6f4f4a3b
commit 655a8b21b6
2 changed files with 9 additions and 0 deletions

View File

@ -1385,6 +1385,9 @@ static bool canBeConst(const Variable *var)
if (!argVar|| (!argVar->isConst() && argVar->isReference()))
return false;
}
} else if (parent->str() == "&" && !parent->astOperand2()) {
// TODO: check how pointer is used
return false;
} else if (parent->isConstOp())
;
else if (parent->isAssignmentOp()) {

View File

@ -1557,6 +1557,12 @@ private:
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(std::string* str);\n"
"void f(std::string str) {\n"
" foo(&str);\n"
"}");
ASSERT_EQUALS("", errout.str());
check("void foo(int& i1, const std::string& str, int& i2);\n"
"void f(std::string str) {\n"
" foo((a+b)*c, str, x);\n"