Skip to content

Commit bf113a8

Browse files
committed
Fix #11300 FP accessMoved with write access (inconclusive)
1 parent db9f970 commit bf113a8

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

lib/astutils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,10 @@ static ExprUsage getFunctionUsage(const Token* tok, int indirect, const Settings
34703470
bool hasIndirect = false;
34713471
const bool isuninitbad = settings.library.isuninitargbad(ftok, argnr + 1, indirect, &hasIndirect);
34723472
if (isuninitbad && (!addressOf || isnullbad))
3473-
return ExprUsage::Used;
3473+
return ExprUsage::Used;
3474+
const Library::ArgumentChecks::Direction dir = settings.library.getArgDirection(ftok, argnr + 1, indirect);
3475+
if (dir == Library::ArgumentChecks::Direction::DIR_OUT)
3476+
return ExprUsage::NotUsed;
34743477
}
34753478
return ExprUsage::Inconclusive;
34763479
}

test/testother.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ class TestOther : public TestFixture {
304304
TEST_CASE(moveForRange);
305305
TEST_CASE(moveTernary);
306306
TEST_CASE(movePointerAlias);
307+
TEST_CASE(moveOutparam);
307308

308309
TEST_CASE(funcArgNamesDifferent);
309310
TEST_CASE(funcArgOrderDifferent);
@@ -12730,6 +12731,19 @@ class TestOther : public TestFixture {
1273012731
ASSERT_EQUALS("[test.cpp:5:8]: (warning) Access of moved variable '.'. [accessMoved]\n", errout_str());
1273112732
}
1273212733

12734+
void moveOutparam()
12735+
{
12736+
check("void f(std::vector<std::string>& v) {\n" // #11300
12737+
" std::string l;\n"
12738+
" while (std::getline(std::cin, l)) {\n"
12739+
" if (!l.empty()) {\n"
12740+
" v.emplace_back(std::move(l));\n"
12741+
" }\n"
12742+
" }\n"
12743+
"}\n");
12744+
ASSERT_EQUALS("", errout_str());
12745+
}
12746+
1273312747
void funcArgNamesDifferent() {
1273412748
check("void func1(int a, int b, int c);\n"
1273512749
"void func1(int a, int b, int c) { }\n"

0 commit comments

Comments
 (0)