diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 89ba23d8c..b2fba947e 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -3113,6 +3113,15 @@ void CheckOther::checkKnownArgument() tok2 = tok2->astOperand2(); if (isVariableExpression(tok2)) continue; + // ensure that there is a integer variable in expression with unknown value + bool intvar = false; + visitAstNodes(tok, [&intvar](const Token *child) { + if (child->varId() && child->valueType() && child->valueType()->isIntegral() && child->values().empty()) + intvar = true; + return ChildrenToVisit::op1_and_op2; + }); + if (!intvar) + continue; // ensure that function name does not contain "assert" std::string funcname = tok->astParent()->previous()->str(); std::transform(funcname.begin(), funcname.end(), funcname.begin(), [](int c) { diff --git a/test/testother.cpp b/test/testother.cpp index d575a0838..7b8d23b27 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -8835,6 +8835,13 @@ private: " ASSERT((int)((x & 0x01) >> 7));\n" "}\n"); ASSERT_EQUALS("", errout.str()); + + // #9905 - expression that does not use integer calculation at all + check("void foo() {\n" + " const std::string heading = \"Interval\";\n" + " std::cout << std::setw(heading.length());\n" + "}"); + ASSERT_EQUALS("", errout.str()); } void checkComparePointers() {