Skip to content

Commit 655a8b2

Browse files
committed
Fix false positive 'passedByValue' when address of argument is used
1 parent db6f4f4 commit 655a8b2

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/checkother.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,9 @@ static bool canBeConst(const Variable *var)
13851385
if (!argVar|| (!argVar->isConst() && argVar->isReference()))
13861386
return false;
13871387
}
1388+
} else if (parent->str() == "&" && !parent->astOperand2()) {
1389+
// TODO: check how pointer is used
1390+
return false;
13881391
} else if (parent->isConstOp())
13891392
;
13901393
else if (parent->isAssignmentOp()) {

test/testother.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,12 @@ class TestOther : public TestFixture {
15571557
"}");
15581558
ASSERT_EQUALS("", errout.str());
15591559

1560+
check("void foo(std::string* str);\n"
1561+
"void f(std::string str) {\n"
1562+
" foo(&str);\n"
1563+
"}");
1564+
ASSERT_EQUALS("", errout.str());
1565+
15601566
check("void foo(int& i1, const std::string& str, int& i2);\n"
15611567
"void f(std::string str) {\n"
15621568
" foo((a+b)*c, str, x);\n"

0 commit comments

Comments
 (0)