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/6] 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/6] 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/6] 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; From fc4bebad3312091db1534a313fc3de7e32caf6ad Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:08:55 +0100 Subject: [PATCH 4/6] Update testother.cpp [skip ci] --- test/testother.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/testother.cpp b/test/testother.cpp index 285800779a4..71e13228b0c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -13823,11 +13823,17 @@ class TestOther : public TestFixture { "[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 + check("void f1(int x) {\n" // #15145 " if (x != 0)\n" " g(0 * x);\n" + "}\n" + "void f2(unsigned x) {\n" + " g(x >= 0);\n" + " if (x != 5)\n" + " g(x == 5);\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", + ASSERT_EQUALS("[test.cpp:6:9]: (style) Unsigned expression 'x' can't be negative so it is unnecessary to test it. [unsignedPositive]\n" + "[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()); } From d8ddb9b7c3c800df74c18c9f1c6d581724920a1b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:10:00 +0100 Subject: [PATCH 5/6] Update checkother.cpp [skip ci] --- lib/checkother.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 0af042f4616..05d87e9975b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4370,7 +4370,7 @@ void CheckOtherImpl::checkKnownArgument() for (const Token *tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) { if (!tok->hasKnownIntValue() || tok->isExpandedMacro()) continue; - if (Token::Match(tok, "++|--|%assign%")) + if (Token::Match(tok, "++|--|%assign%|%comp%")) continue; if (!Token::Match(tok->astParent(), "(|{|,")) continue; @@ -4395,10 +4395,6 @@ void CheckOtherImpl::checkKnownArgument() tok2 = tok2->astOperand2(); if (isVariableExpression(tok2)) continue; - if (tok->isComparisonOp() && - isSameExpression( - true, tok->astOperand1(), tok->astOperand2(), mSettings, true, true)) - continue; // ensure that there is a integer variable in expression with unknown value const Token* vartok = nullptr; visitAstNodes(tok, [&](const Token* child) { @@ -4406,7 +4402,9 @@ void CheckOtherImpl::checkKnownArgument() if (child->hasKnownIntValue()) return ChildrenToVisit::none; if (astIsIntegral(child, false) && !astIsPointer(child) && - (child->values().empty() || (child->values().front().isIntValue() && child->values().front().isImpossible()))) { + std::none_of(child->values().begin(), child->values().end(), [](const ValueFlow::Value& v) { + return v.isIntValue() && !v.isImpossible(); + })) { vartok = child; return ChildrenToVisit::done; } From 2f2568c15ea3fb3792448ac39e0e0850faccfc87 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 12 Nov 2026 13:16:53 +0100 Subject: [PATCH 6/6] Update checkother.cpp --- lib/checkother.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 8595c548d4c..7ec517c8cca 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4416,8 +4416,8 @@ void CheckOtherImpl::checkKnownArgument() return ChildrenToVisit::none; if (astIsIntegral(child, false) && !astIsPointer(child) && std::none_of(child->values().begin(), child->values().end(), [](const ValueFlow::Value& v) { - return v.isIntValue() && !v.isImpossible(); - })) { + return v.isIntValue() && !v.isImpossible(); + })) { vartok = child; return ChildrenToVisit::done; }