diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1589b3b7dea..0af042f4616 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4405,7 +4405,8 @@ void CheckOtherImpl::checkKnownArgument() if (Token::Match(child, "%var%|.|[")) { if (child->hasKnownIntValue()) return ChildrenToVisit::none; - if (astIsIntegral(child, false) && !astIsPointer(child) && child->values().empty()) { + if (astIsIntegral(child, false) && !astIsPointer(child) && + (child->values().empty() || (child->values().front().isIntValue() && child->values().front().isImpossible()))) { vartok = child; return ChildrenToVisit::done; } diff --git a/test/testother.cpp b/test/testother.cpp index e285d8d8bd0..285800779a4 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -13822,6 +13822,13 @@ class TestOther : public TestFixture { "[test.cpp:5:18]: (style) Argument 'true||x' to function dostuff is always 1. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n" "[test.cpp:6:15]: (style) Argument 'x*0' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n" "[test.cpp:7:15]: (style) Argument '0*x' to function dostuff is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n", errout_str()); + + check("void f(int x) {\n" // #15145 + " if (x != 0)\n" + " g(0 * x);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:13]: (style) Argument '0*x' to function g is always 0. Constant literal calculation disable/hide variable expression 'x'. [knownArgumentHiddenVariableExpression]\n", + errout_str()); } void knownArgumentTernaryOperator() { // #10374