Skip to content

Remove valueFlowArrayBool() (redundancy with valueFlowImpossibleValues()) - #8905

Open
chrchr-github wants to merge 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_sibling
Open

chrchr-github wants to merge 6 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_sibling

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@chrchr-github chrchr-github changed the title Refactor: use astSibling() Remove valueFlowArrayBool() (redundancy with valueFlowImpossibleValues()) Sep 29, 2026
@danmar

danmar commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

This is an AI review. Take it with a grain of salt and feel free to reject it by resolving the comment.

The removal looks safe to me. I built the PR and compared it with main on a set of array-to-bool cases (if (buf), if (!buf), bool b = buf;, buf && x, while (buf), buf ? 1 : 2, struct member arrays s->a / s.a) and on samples/, test/cfg/ and a couple of lib/ files with --check-level=exhaustive. The warnings are identical.

One suggestion: valueFlowArrayBool() had explicit handling for a pointer whose tok-value is an array (the isTokValue branch). That case still works after this PR, but I could not find a test covering it in testcondition.cpp. Maybe add a regression test so this doesn't silently break later, for example:

check("void f() {\n"
      "    char buf[10];\n"
      "    char *p = buf;\n"
      "    if (!p) {}\n"
      "}\n");
ASSERT_EQUALS("[test.cpp:4:9]: (style) Condition '!p' is always false [knownConditionTrueFalse]\n", errout_str());

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants