Repository navigation
Fix #15307: Internal error for invalid code inside unknown macro argument - #9112
ludviggunne wants to merge 2 commits into
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no problems. The new check in findGarbageCode() turns the internalError "Cannot find end of expression" on F(a, { ...; return 0 }) into an unknownMacro error that names the right macro. It does this at file scope, inside function bodies, with extra arguments after the block and with nested calls. It did not fire on valid code: GCC statement expressions, lambdas inside initializer lists, braced initializer arguments and if ({...}).
One behaviour change is intended. In C files, where the old code was silently accepted with no diagnostic, the same invalid code now also gets unknownMacro. For example void f(){ F(a, { float y; return }); } printed nothing on base and now gives unknownMacro.
Testing
- I built
cppcheckandtestrunnerin pr/ andcppcheckin base/. Both builds succeeded. ./testrunner TestTokenizer TestGarbage: 626 tests, 0 failures. The newunknownMacroBracedArgumenttest passes.- I compared PR and base on small C and C++ files in scratch/:
- Base gives
internalError: Cannot find end of expressionand the PR givesunknownMacrofor these C++ inputs:F(a, { float y = p.y; return 0 });F(a, { ... return 0 }, b);void f(){ G(a, { ...; return 0 }) }
- In C, base was silent on
F(a, {...; return 0}),F({...})andh(1, { int a; a })nested in a call. The PR now reports unknownMacro for them, and it names the innermost macro. - These give no diagnostic on either version:
x = ({ int a = 1; a });g(({ ... a }))andg(1, ({...}), 2)g({ [](){ return 1; }(), 2 })h(a, {1,2})for (auto x : {1,2})if ({ int a; a })F(a, [x]{...})F(a, {...; return 0;})F(a, {...; if(y){} })
- An unmatched paren still gives the same syntaxError as before.
- Base gives
- I ran PR and base cppcheck on every file in
test/cfg/*.c*andsamples/. The counts of unknownMacro, internalError and syntaxError were the same on both.
Automated review of 771daae by Claude. The pull request was built and tested locally.
No description provided.