ValueFlow: Better errorpath for increment/decrement

This commit is contained in:
Daniel Marjamäki 2017-08-25 22:15:52 +02:00
parent bab2b26d10
commit b1b8e5270a
2 changed files with 5 additions and 0 deletions

View File

@ -1837,6 +1837,8 @@ static bool valueFlowForward(Token * const startToken,
it->intvalue += (inc ? 1 : -1);
if (pre)
setTokenValue(op, *it, settings);
const std::string info(tok2->str() + " is " + std::string(inc ? "incremented" : "decremented") + "', new value is " + it->infoString());
it->errorPath.push_back(ErrorPathItem(tok2, info));
}
}

View File

@ -1067,6 +1067,9 @@ private:
"}";
ASSERT_EQUALS(false, testValueOfX(code, 4U, 9));
ASSERT_EQUALS(true, testValueOfX(code, 4U, 8));
ASSERT_EQUALS("2,Assignment 'x=9', assigned value is 9\n"
"3,x is decremented', new value is 8\n",
getErrorPathForX(code, 4U));
code = "void x() {\n"
" int x = value ? 6 : 0;\n"