diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 31154e5d4..83c30a245 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -407,6 +407,18 @@ static void setTokenValue(Token* tok, const ValueFlow::Value &value) } } + // ! + else if (parent->str() == "!") { + std::list::const_iterator it; + for (it = tok->values.begin(); it != tok->values.end(); ++it) { + if (it->tokvalue) + continue; + ValueFlow::Value v(*it); + v.intvalue = !v.intvalue; + setTokenValue(parent, v); + } + } + // Array element else if (parent->str() == "[" && parent->astOperand1() && parent->astOperand2()) { std::list::const_iterator value1, value2; diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index dd8a54c12..83ce94876 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -265,6 +265,15 @@ private: ASSERT_EQUALS(2, values.front().intvalue); ASSERT_EQUALS(3, values.back().intvalue); + // ! + code = "void f(int x) {\n" + " a = !x;\n" + " if (x==0) {}\n" + "}"; + values = tokenValues(code,"!"); + ASSERT_EQUALS(1U, values.size()); + ASSERT_EQUALS(1, values.back().intvalue); + // function call => calculation code = "void f(int x) {\n" " a = x + 8;\n"