From be9d33c14232698ea43eb3999f177ced9e47612a Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Sep 2026 12:36:29 +0200 Subject: [PATCH 1/7] Update testother.cpp --- test/testother.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/testother.cpp b/test/testother.cpp index d115acc2163..acc2f1ec01a 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -14055,6 +14055,12 @@ class TestOther : public TestFixture { " g(b);\n" "}\n"); ASSERT_EQUALS("", errout_str()); + + check("void g(bool);\n" // #14303 + "void f() {\n" + " g(g);\n" + "}\n"); + ASSERT_EQUALS("[test.cpp:3:7]: (style) Pointer expression 'g' converted to bool is always true. [knownPointerToBool]\n", errout_str()); } void iterateByValue() { From bef5e675cb170948258382f2aa95bf05d04c28db Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Sep 2026 12:38:02 +0200 Subject: [PATCH 2/7] 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 b9ff731b0ce..f7e6f2f956b 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -4446,7 +4446,7 @@ void CheckOtherImpl::checkKnownPointerToBool() for (const Token* tok = functionScope->bodyStart; tok != functionScope->bodyEnd; tok = tok->next()) { if (!tok->hasKnownIntValue()) continue; - if (!astIsPointer(tok)) + if (!astIsPointer(tok) && !tok->function()) continue; if (Token::Match(tok->astParent(), "?|!|&&|%oror%|%comp%")) continue; From 916c809ae253bef03e5974ea2140e101c9a7b975 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Sep 2026 12:39:26 +0200 Subject: [PATCH 3/7] Update valueflow.cpp --- lib/valueflow.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index aa0b2c91c29..4769445df05 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1178,6 +1178,10 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett ValueFlow::Value value{0}; value.setImpossible(); setTokenValue(tok, std::move(value), settings); + } else if (tok->function()) { + ValueFlow::Value value{0}; + value.setImpossible(); + setTokenValue(tok, std::move(value), settings); } } } @@ -5162,7 +5166,7 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin } } else if (Token::Match(tok->astParent(), "?|&&|!|%oror%") || Token::Match(tok->astParent()->previous(), "if|while (") || - (astIsPointer(tok) && isUsedAsBool(tok, settings))) { + ((astIsPointer(tok) || tok->function()) && isUsedAsBool(tok, settings))) { std::vector result = infer(makeIntegralInferModel(), "!=", tok->values(), 0); if (result.size() != 1) continue; From a1eca649edf7bccf926a52e9faca03b47581cd13 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:01:48 +0200 Subject: [PATCH 4/7] Update testcondition.cpp [skip ci] --- test/testcondition.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index c7f39584939..eeb375882b3 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5503,6 +5503,13 @@ class TestCondition : public TestFixture { " std::size_t x;\n" "};\n"); ASSERT_EQUALS("", errout_str()); + + check("int g();\n" // #13441 + "void f() {\n" + " int (*p)() = g;\n" + " if (p == nullptr) {}\n" + "};\n"); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\n", errout_str()); } void alwaysTrueContainer() { From 526ce1cc27967d12bd941a8f4f5493f32d7db8c1 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Thu, 24 Sep 2026 13:02:43 +0200 Subject: [PATCH 5/7] Update valueflow.cpp --- lib/valueflow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 4769445df05..5b9fe94d04e 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -1178,7 +1178,7 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett ValueFlow::Value value{0}; value.setImpossible(); setTokenValue(tok, std::move(value), settings); - } else if (tok->function()) { + } else if (tok->function() && tok->scope()->isExecutable()) { ValueFlow::Value value{0}; value.setImpossible(); setTokenValue(tok, std::move(value), settings); From 03dc79f4544941d9a11fd04e6c4cf26a56c73637 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:16:28 +0200 Subject: [PATCH 6/7] Update testcondition.cpp [skip ci] --- test/testcondition.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/testcondition.cpp b/test/testcondition.cpp index eeb375882b3..2389d5a994f 100644 --- a/test/testcondition.cpp +++ b/test/testcondition.cpp @@ -5508,8 +5508,14 @@ class TestCondition : public TestFixture { "void f() {\n" " int (*p)() = g;\n" " if (p == nullptr) {}\n" + " if (g == nullptr) {}\n" + " auto q = g;\n" + " if (q == nullptr) {}\n" "};\n"); - ASSERT_EQUALS("[test.cpp:4:11]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\n", errout_str()); + ASSERT_EQUALS("[test.cpp:4:11]: (style) Condition 'p==nullptr' is always false [knownConditionTrueFalse]\n" + "[test.cpp:5:11]: (style) Condition 'g==nullptr' is always false [knownConditionTrueFalse]\n" + "[test.cpp:7:11]: (style) Condition 'q==nullptr' is always false [knownConditionTrueFalse]\n", + errout_str()); } void alwaysTrueContainer() { From 83d713103897fe194ce2ad02e727a2c819a11b66 Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Tue, 29 Sep 2026 17:17:09 +0200 Subject: [PATCH 7/7] Update valueflow.cpp --- lib/valueflow.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index 5b9fe94d04e..f61b9efff0b 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -5166,7 +5166,8 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin } } else if (Token::Match(tok->astParent(), "?|&&|!|%oror%") || Token::Match(tok->astParent()->previous(), "if|while (") || - ((astIsPointer(tok) || tok->function()) && isUsedAsBool(tok, settings))) { + (astIsPointer(tok) && isUsedAsBool(tok, settings)) || + tok->function()) { std::vector result = infer(makeIntegralInferModel(), "!=", tok->values(), 0); if (result.size() != 1) continue;