diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 777e32f93..ae962fdb1 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -418,10 +418,10 @@ bool isVariableChangedByFunctionCall(const Token *tok, const Settings *settings, const ::Scope *typeScope = tok->variable()->typeScope(); if (typeScope) { for (std::list::const_iterator it = typeScope->functionList.begin(); it != typeScope->functionList.end(); ++it) { - if (!it->isConstructor() || it->argCount() != argCount) + if (!it->isConstructor() || it->argCount() < argCount) continue; const Variable *arg = it->getArgumentVar(argnr); - if (arg && arg->isReference()) + if (arg && arg->isReference() && !arg->isConst()) return true; } return false; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index 91536a9b9..b650a9e65 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -1804,7 +1804,7 @@ private: code = "class C {\n" "public:\n" - " C(int &i);\n" + " C(int &i);\n" // non-const argument => might be changed "};\n" "int f() {\n" " int x=1;\n" @@ -1812,6 +1812,17 @@ private: " return x;\n" "}"; ASSERT_EQUALS(false, testValueOfX(code, 8U, 1)); + + code = "class C {\n" + "public:\n" + " C(const int &i);\n" // const argument => is not changed + "};\n" + "int f() {\n" + " int x=1;\n" + " C c(x);\n" + " return x;\n" + "}"; + ASSERT_EQUALS(true, testValueOfX(code, 8U, 1)); } void valueFlowForwardLambda() {