Skip to content

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

Open
autoantwort wants to merge 1 commit into
cppcheck-opensource:mainfrom
autoantwort:fix-varid-initlist-braced-arg
Open

autoantwort wants to merge 1 commit 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>
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