From a2c9ccf07d5cebf282a00992e5d3b0d359af89c3 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:45:25 +0100 Subject: [PATCH 1/3] Update checkother.cpp --- lib/checkother.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 1589b3b7dea..fc0eb616def 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; } From 246b6e64767a864e9d028d7d5317c677d026b2fb Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 28 Oct 2026 09:47:17 +0100 Subject: [PATCH 2/3] Update testother.cpp --- test/testother.cpp | 7 +++++++ 1 file changed, 7 insertions(+) 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 From e04ce1dd92d1c80d2d4601d906d6aab25d339211 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 28 Oct 2026 11:35:33 +0100 Subject: [PATCH 3/3] Update checkother.cpp --- lib/checkother.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index fc0eb616def..0af042f4616 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4405,7 +4405,7 @@ void CheckOtherImpl::checkKnownArgument() if (Token::Match(child, "%var%|.|[")) { if (child->hasKnownIntValue()) return ChildrenToVisit::none; - if (astIsIntegral(child, false) && !astIsPointer(child) && + if (astIsIntegral(child, false) && !astIsPointer(child) && (child->values().empty() || (child->values().front().isIntValue() && child->values().front().isImpossible()))) { vartok = child; return ChildrenToVisit::done;