diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 2a4de18b2c0..8712800a867 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -2518,8 +2518,6 @@ bool isMutableExpression(const Token* tok) if (tok->astOperand1() && Token::simpleMatch(tok, "[")) return isMutableExpression(tok->astOperand1()); if (const Variable* var = tok->variable()) { - if (var->nameToken() == tok) - return false; if (var->isConst() && !var->isPointer() && (!var->isArray() || !var->isArgument())) return false; } diff --git a/test/testother.cpp b/test/testother.cpp index bac5dfbdf7f..1b53a5795e1 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -12651,6 +12651,24 @@ class TestOther : public TestFixture { " }\n" "}\n"); ASSERT_EQUALS("[test.cpp:4:36]: (warning) Access of moved variable 'l'. [accessMoved]\n", errout_str()); + + check("struct S {\n" // #13179 + " operator bool() const { return !m.empty(); }\n" + " std::string m;\n" + "};\n" + "S get();\n" + "void set(S);\n" + "void f() {\n" + " while (S s = get()) {\n" + " set(std::move(s));\n" + " }\n" + "}\n" + "void g() {\n" + " while (S s{ get() }) {\n" + " set(std::move(s));\n" + " }\n" + "}\n"); + ASSERT_EQUALS("", errout_str()); } void moveCallback()