Skip to content

Fix #15310: internalError with shadowing typedef - #9116

Open
ludviggunne wants to merge 2 commits into
cppcheck-opensource:mainfrom
ludviggunne:15310-shadow-typedef
Open

ludviggunne wants to merge 2 commits into
cppcheck-opensource:mainfrom
ludviggunne:15310-shadow-typedef

Conversation

@ludviggunne

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. For a self-referencing typedef inside any { scope (function, class or namespace), the PR now falls back to the old simplifier instead of throwing internalError. On every shadowing case I tried, the output is correct where base reported internalError, and none of my tests gave a regression, crash or hang. At global scope it still throws as before. The backward scan only runs when a self-referencing name is found, so it adds no cost to the normal path.

Testing

  • Build: make -j8 cppcheck testrunner in pr/ and make -j8 cppcheck in base/ both built without errors.
  • Unit tests: ./testrunner passed with 0 failures for TestSimplifyTypedef (216 tests, including the new simplifyTypedef165), TestSimplifyUsing, TestTokenizer and TestGarbage.
  • Fuzz files: the PR's cppcheck -q ran on every file in test/cli/fuzz-crash, fuzz-crash_c and fuzz-timeout with a 20 s timeout per file. None crashed, hung or returned non-zero.
  • My own inputs: run with cppcheck -q --debug, PR against base:
    • struct T{}; void f(){ typedef T* T; { T y = 0; T z[2]; } }: base gives internalError, the PR gives T * y; … T * z[2]; (correct).
    • typedef const U* U; in a function, followed by a null dereference: base gives internalError and the null dereference is never reported; the PR reports nullPointer.
    • void f(){ typedef T* T; typedef T* T; T p; }: the PR gives T * * p; (correct).
    • void k(){ typedef void (*T)(T); T fp; }: the PR gives void (*fp)(T); (correct).
    • typedef T* T; in a namespace, a class and a struct (struct S { typedef S* S; S p; };), and a typedef shadowing an earlier local typedef: all handled by the PR, all internalError in base.
    • extern "C" { typedef T* T; T p; }: internalError in both base and the PR.
    • typedef T T[3]; and typedef T T::*T;: syntaxError in both base and the PR.
    • typedef V<T> T;, typedef struct T T;, typedef decltype(T) T;: same output as base.
    • void f(){ typedef unsigned T T; T p; }: base gives internalError, the PR gives unsigned int T p ;. The code is invalid C++, so I'm not reporting it.

Automated review of 42910b8 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