Skip to content

Fix #15244, #15245 syntaxError and unsimplified function bodies in simplifyVarDecl - #9052

Open
tsobczynski wants to merge 2 commits into
cppcheck-opensource:mainfrom
tsobczynski:fix-trailing-return-specifiers
Open

tsobczynski wants to merge 2 commits into
cppcheck-opensource:mainfrom
tsobczynski:fix-trailing-return-specifiers

Conversation

@tsobczynski

Copy link
Copy Markdown

Two fixes in Tokenizer::simplifyVarDecl, one commit each.

  • #15244: isTrailingReturnType now 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.
  • #15245: the K&R parameter pass no longer steps onto tokEnd when it skips a parenthesised group, which made the loop run past the end of its range. Test: vardecl38.

Both tests fail without the fixes. testrunner passes in full. selfcheck.sh, built with ENABLE_CHECK_INTERNAL and USE_MATCHCOMPILER=Verify, reports no new findings.

🤖 Generated with Claude Code

tsobczynski and others added 2 commits November 19, 2026 16:26
…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>
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.

1 participant