Skip to content

Fix #15167 FN constVariable with typedef - #8990

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

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

Conversation

@chrchr-github

Copy link
Copy Markdown
Collaborator

No description provided.

@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 new condition still skips a variable whose * comes from a typedef, such as typedef int* P; P p; or P a[2];. It now reports arrays whose element type is a typedef but not a pointer typedef, which is the FN in #15167. All the new warnings I got are valid: const can be added in each case and it compiles. I found no new false positives with pointer typedefs, function-pointer typedefs, array typedefs or typedefs of arrays of pointers.

Testing

  • I built cppcheck and testrunner in pr/, and cppcheck in base/.
  • ./testrunner TestOther: 0 failures.
  • I ran the cppcheck of the PR on test/cfg/windows.cpp with --library=windows --platform=win64 --inline-suppr --check-library --enable=style,information --inconclusive --error-exitcode=1. It exited with 0, so the suppression that the PR changes from TODO to active is now matched.
  • I compared the constVariable output of base and PR on every file in test/cfg/*.c*, without libraries. There was no difference.
  • I wrote scratch tests (t1.cpp, t2.cpp) and compared base with the PR:
    • New warnings, all correct:
      • typedef int A[2]; A a = {0,0}; return a[0];
      • typedef int I; I a[2][2] = {}; return a[0][0];
      • typedef char CA[4]; CA a[2] = {}; return a[0][0];
    • Still no warning, as expected:
      • pointer typedefs: P a[2], P const p, const P p, P* pp, and typedef int* const CP
      • function-pointer and struct-pointer typedefs (FP fs[1], PS a[1])
      • typedef P PA[2] and typedef int* PA2[2] when the pointees are written
      • typedef arrays that are modified through I* p = a, through I& r = a[0], or passed as I (&)[2]
      • typedef arrays whose elements are written

Automated review of 63bf235 by Claude. The pull request was built and tested locally.

@dmcppcheck

Copy link
Copy Markdown
Contributor

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

Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8990/
packages: 100
Differing warnings: 7 (+7 -0)
AI review: 7 improvement (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8990/2026-11-03_07-13-16-63bf235ec60c-review.txt)
Timing: +0.0% (http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-8990/2026-11-03_07-13-16-63bf235ec60c_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.

@chrchr-github

Copy link
Copy Markdown
Collaborator Author

The regressions found by AI are either covered by https://trac.cppcheck.net/ticket/15170 or stem from a preexisting varid issue caused by unknown macros: void f(rtx a ATTRIBUTE_UNUSED);

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