Repository navigation
Fix #15244, #15245 syntaxError and unsimplified function bodies in simplifyVarDecl - #9052
tsobczynski wants to merge 2 commits into
Conversation
|
The three failing jobs ( |
…r precedes a trailing return type
isTrailingReturnType accepted only `) . type`, so a function or lambda
with a cv or ref qualifier, noexcept, noexcept(...), throw(...),
mutable, constexpr, consteval or static before `->` had its body taken
for a braced initializer, and simplifyVarDecl did not simplify it.
Inside such a body, findLambdaEndScope then accepted a structured
binding like `[p, c]{f()}` as a lambda.
Step back over those specifiers and return the parameter list's `)`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… parenthesis
In the K&R parameter pass, simplifyVarDecl skips a parenthesised group
and steps past its `)`. When that `)` is the last token before tokEnd,
the step lands on tokEnd and the loop increment then steps past it, so
the loop runs to the end of the token list and raises a syntax error.
findLambdaEndScope takes `[2]{(1)}` in `new int[2]{(1)}` for a lambda,
which produces such a range.
Don't step onto tokEnd.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
f19f0e1 to
deaedb0
Compare
|
Rebased onto |
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no problems in this PR. isTrailingReturnType now steps back over cv and ref qualifiers, noexcept/noexcept(...), throw(...), mutable, constexpr, consteval and static. With that, function and lambda bodies are simplified correctly, and the structured binding case auto [p, c]{f()} is no longer mistaken for a lambda. The K&R fix stops the loop from stepping past tokEnd, and new int[2]{(1)} no longer causes a syntaxError. A lambda with no parameter list, such as [] mutable -> int {}, is still not simplified, but that was already the case before and has a TODO in the code. Running base and PR on several test/cfg files and samples gave the same results.
Testing
- I built
cppcheckandtestrunnerin pr/ andcppcheckin base/. ./testrunner TestTokenizer TestVarID TestSymbolDatabase TestGarbage TestSimplifyTokens: 0 failures. vardecl37 and vardecl38 pass.- I wrote scratch files and ran
cppcheck --debug-normal --std=c++23on them with both builds:- All of these now get simplified bodies and variable ids:
() const& -> int,throw() -> int,noexcept(noexcept(f())) -> int,[]() constexpr|static|consteval -> int,[]() mutable noexcept -> R { auto [p, c]{f()}; ... },const & noexcept -> intas a member function, and-> decltype(...)/-> std::vector<int>. With base, the file got a syntax error, so it had no variable ids at all. new int[2]{(1)},new int[2]{(1),(2)}andint x{[](){return 1;}()}inside a function body are now handled with no syntax error.- Code that could have given a false match on the new specifier skipping gives the same output in base and PR: C designated initializers such as
{ .a = (x) & 1, .b = { 2 } }, and a K&R function with casts and parentheses. [] mutable -> int { int a = 1, b = 2; ... }(no parameter list) is still not simplified. This was already the case before the PR and has a TODO in the code.
- All of these now get simplified bodies and variable ids:
- I ran
cppcheck --enable=all --inconclusive --check-level=exhaustivewith both builds on test/cfg/std.cpp, qt.cpp, boost.cpp, std.c and samples/*. The output was identical.
Automated review of deaedb0 by Claude. The pull request was built and tested locally.
|
Test results for commit deaedb0 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-16-170-140-253.eu-north-1.compute.amazonaws.com/pr-9052/ 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. |
Two fixes in
Tokenizer::simplifyVarDecl, one commit each.isTrailingReturnTypenow steps back over the specifiers that can stand between the parameter list and->(cv and ref qualifiers,noexcept,noexcept(...),throw(...),mutable,constexpr,consteval,static). Before, a function or lambda with one of them had its body treated as a braced initializer, so the body was not simplified. Test:vardecl37.tokEndwhen it skips a parenthesised group, which made the loop run past the end of its range. Test:vardecl38.Both tests fail without the fixes.
testrunnerpasses in full.selfcheck.sh, built withENABLE_CHECK_INTERNALandUSE_MATCHCOMPILER=Verify, reports no new findings.🤖 Generated with Claude Code