Skip to content

Fix #15222 FN constParameterPointer (parameters declared in macro) - #9032

Open
chrchr-github wants to merge 3 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15222
Open

chrchr-github wants to merge 3 commits into
cppcheck-opensource:mainfrom
chrchr-github:chr_15222

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@dmcppcheck

Copy link
Copy Markdown
Contributor

Test results for commit 4d43809 (tools/test-my-pr.py, main compared to this PR):

Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9032/
packages: 100
Differing warnings: 77 (+76 -1)
AI review: 50 improvement (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9032/2026-11-16_07-01-53-4d4380993141-review.txt)
Timing: +0.7% (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9032/2026-11-16_07-01-53-4d4380993141_timing.html)

Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong.

@dmcppcheck dmcppcheck left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI review

I found no problems. The set comparator now orders by token index (precedes) instead of by file, line and column. This fixes the case where several variables that come from one macro expansion share a location and were treated as equal keys, so all but one were dropped. Token indexes are assigned once at the end of simplifyTokenList1 (and in the clang import), before the symbol database is created, so each variable's name token has a unique index here. I checked parameters and locals declared in macros, repeated macro invocations, ordinary code and template functions. All of them gave the expected results.

Testing

I built cppcheck and testrunner in pr/, and cppcheck in base/.

  • ./testrunner TestOther: 255 tests, 0 failures.
  • I ran cppcheck -q --enable=style from both builds on a scratch file with these cases:
    • The PR's case: #define DECL_ARGS S *p, S *q / void f(DECL_ARGS). The PR reports p and q. Base reported only one of them.
    • Locals declared in a macro: #define LOC S *a = g(); S *b = g();. The PR now reports both constVariablePointer warnings.
    • A function-defining macro invoked twice on one line: both parameters are reported.
    • Ordinary parameters: unchanged, both reported.
    • Template functions: one that only reads through the pointer and one that writes through it. Base and PR give the same output.

Over the two scratch files, the PR reports 8 style warnings and base reports 6. The 2 extra warnings are the intended new detections.


Automated review of 4d43809 by Claude. The pull request was built and tested locally.

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.

2 participants