Skip to content

Commit ef91022

Browse files
Fix #13179 FP Access of moved variable in while loop (#8469)
1 parent 742df60 commit ef91022

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

lib/astutils.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2518,8 +2518,6 @@ bool isMutableExpression(const Token* tok)
25182518
if (tok->astOperand1() && Token::simpleMatch(tok, "["))
25192519
return isMutableExpression(tok->astOperand1());
25202520
if (const Variable* var = tok->variable()) {
2521-
if (var->nameToken() == tok)
2522-
return false;
25232521
if (var->isConst() && !var->isPointer() && (!var->isArray() || !var->isArgument()))
25242522
return false;
25252523
}

test/testother.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12651,6 +12651,24 @@ class TestOther : public TestFixture {
1265112651
" }\n"
1265212652
"}\n");
1265312653
ASSERT_EQUALS("[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\n", errout_str());
12654+
12655+
check("struct S {\n" // #13179
12656+
" operator bool() const { return !m.empty(); }\n"
12657+
" std::string m;\n"
12658+
"};\n"
12659+
"S get();\n"
12660+
"void set(S);\n"
12661+
"void f() {\n"
12662+
" while (S s = get()) {\n"
12663+
" set(std::move(s));\n"
12664+
" }\n"
12665+
"}\n"
12666+
"void g() {\n"
12667+
" while (S s{ get() }) {\n"
12668+
" set(std::move(s));\n"
12669+
" }\n"
12670+
"}\n");
12671+
ASSERT_EQUALS("", errout_str());
1265412672
}
1265512673

1265612674
void moveCallback()

0 commit comments

Comments
 (0)