diff --git a/lib/token.cpp b/lib/token.cpp index 3af76f047..3670fb7ec 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -2030,11 +2030,15 @@ static ValueIterator removeAdjacentValues(std::list& values, V { if (!isAdjacent(*x, **start)) return std::next(x); - auto it = std::adjacent_find(start, last, [](ValueIterator x, ValueIterator y) { return !isAdjacent(*x, *y); }); + auto it = std::adjacent_find(start, last, [](ValueIterator x, ValueIterator y) { + return !isAdjacent(*x, *y); + }); if (it == last) it--; (*it)->bound = x->bound; - std::for_each(start, it, [&](ValueIterator y) { values.erase(y); }); + std::for_each(start, it, [&](ValueIterator y) { + values.erase(y); + }); return values.erase(x); } diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index a7b269663..de78c2c12 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -374,7 +374,9 @@ static bool isZero(T x) template static R calculate(const std::string& s, const T& x, const T& y) { - auto wrap = [](T z) { return R{z}; }; + auto wrap = [](T z) { + return R{z}; + }; switch (MathLib::encodeMultiChar(s)) { case '+': return wrap(x + y); @@ -383,9 +385,11 @@ static R calculate(const std::string& s, const T& x, const T& y) case '*': return wrap(x * y); case '/': - return isZero(y) ? R{} : wrap(x / y); + return isZero(y) ? R{} : + wrap(x / y); case '%': - return isZero(y) ? R{} : wrap(MathLib::bigint(x) % MathLib::bigint(y)); + return isZero(y) ? R{} : + wrap(MathLib::bigint(x) % MathLib::bigint(y)); case '&': return wrap(MathLib::bigint(x) & MathLib::bigint(y)); case '|': @@ -397,9 +401,11 @@ static R calculate(const std::string& s, const T& x, const T& y) case '<': return wrap(x < y); case '<<': - return (y >= sizeof(MathLib::bigint) * 8) ? R{} : wrap(MathLib::bigint(x) << MathLib::bigint(y)); + return (y >= sizeof(MathLib::bigint) * 8) ? R{} : + wrap(MathLib::bigint(x) << MathLib::bigint(y)); case '>>': - return (y >= sizeof(MathLib::bigint) * 8) ? R{} : wrap(MathLib::bigint(x) >> MathLib::bigint(y)); + return (y >= sizeof(MathLib::bigint) * 8) ? R{} : + wrap(MathLib::bigint(x) >> MathLib::bigint(y)); case '&&': return wrap(!isZero(x) && !isZero(y)); case '||': @@ -4729,8 +4735,8 @@ ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, Math if (varTok->hasKnownIntValue()) return ValueFlow::Value{}; if (std::none_of(varTok->values().begin(), varTok->values().end(), [](const ValueFlow::Value& v) { - return v.isImpossible() && v.valueType == ValueFlow::Value::ValueType::INT; - })) { + return v.isImpossible() && v.valueType == ValueFlow::Value::ValueType::INT; + })) { return ValueFlow::Value{}; } const ValueFlow::Value* result = nullptr; diff --git a/lib/valueflow.h b/lib/valueflow.h index 3fde655a0..79a917d40 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -57,16 +57,14 @@ namespace ValueFlow { struct less { template - bool operator()(const T& x, const U& y) const - { + bool operator()(const T& x, const U& y) const { return x < y; } }; struct adjacent { template - bool operator()(const T& x, const U& y) const - { + bool operator()(const T& x, const U& y) const { return std::abs(x - y) == 1; } }; @@ -163,22 +161,19 @@ namespace ValueFlow { struct compareVisitor { struct innerVisitor { template - void operator()(bool& result, Compare compare, T x, U y) const - { + void operator()(bool& result, Compare compare, T x, U y) const { result = compare(x, y); } }; template - void operator()(bool& result, const Value& rhs, Compare compare, T x) const - { + void operator()(bool& result, const Value& rhs, Compare compare, T x) const { visitValue(rhs, std::bind(innerVisitor{}, std::ref(result), std::move(compare), x, std::placeholders::_1)); } }; template - bool compareValue(const Value& rhs, Compare compare) const - { + bool compareValue(const Value& rhs, Compare compare) const { bool result = false; visitValue( *this, diff --git a/test/testvalueflow.cpp b/test/testvalueflow.cpp index ec4949350..92287c6c3 100644 --- a/test/testvalueflow.cpp +++ b/test/testvalueflow.cpp @@ -5049,7 +5049,7 @@ private: "}\n"; ASSERT_EQUALS("", isKnownContainerSizeValue(tokenValues(code, "str . empty", ValueFlow::Value::ValueType::CONTAINER_SIZE), 3)); - + code = "int f() {\n" " std::array a = {};\n" " return a.front();\n" @@ -5225,7 +5225,9 @@ private: " return x + 0;\n" "}"; values = tokenValues(code, "+", &s); - values.remove_if([](const ValueFlow::Value& v) { return v.isImpossible(); }); + values.remove_if([](const ValueFlow::Value& v) { + return v.isImpossible(); + }); ASSERT_EQUALS(2, values.size()); ASSERT_EQUALS(0, values.front().intvalue); ASSERT_EQUALS(100, values.back().intvalue);