Skip to content

Fix #15062 Wrong varid for shadowed member in initializer list after braced init list argument (FP uninitMemberVar, selfInitialization, functionStatic) - #8885

Merged
danmar merged 3 commits into
cppcheck-opensource:mainfrom
autoantwort:fix-varid-initlist-braced-arg
Oct 4, 2026
Merged

danmar merged 3 commits into
cppcheck-opensource:mainfrom
autoantwort:fix-varid-initlist-braced-arg

Conversation

@autoantwort

Copy link
Copy Markdown
Contributor

In setVarIdPass1 a { inside a constructor initializer list was only treated as part of an argument when preceded by %name%|>|>>|(. For a braced init list that is not the first argument (x(f(0, {0}))) or a nested one (x(f(0, {{1}, 2}))), the { was taken as the start of the constructor body. The parameter scope was then not left correctly: a following p(p) got the parameter's varid for the member, and the parameter varid leaked into later functions such as int T::g() { return *p; }.

This caused false positives uninitMemberVar, selfInitialization and functionStatic.

The fix also accepts , and { before the {, and } after the matching }.

🤖 Generated with Claude Code

…braced init list argument (FP uninitMemberVar, selfInitialization, functionStatic)

In setVarIdPass1 a '{' inside a constructor initializer list was only
recognized as part of an argument if it was preceded by a name, '>',
'>>' or '('. A braced init list that is not the first argument, e.g.
x(f(0, {0})), or a nested one, e.g. x(f(0, {{1}, 2})), was treated as
the start of the constructor body. As a result the parameter scope was
not left correctly, so the member in a following p(p) got the varid of
the parameter, and the parameter varid leaked into later functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread lib/tokenize.cpp
autoantwort and others added 2 commits October 3, 2026 17:41
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This reverts commit b20b47c. It treated `new T[n]{...}` in an initializer
list as a lambda body; the lambda case will be fixed in a separate PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danmar
danmar merged commit 746b3a7 into cppcheck-opensource:main Oct 4, 2026
71 checks passed
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