Fix #15084 Wrong varid for lambda in constructor initializer list - #8917
Open
autoantwort wants to merge 2 commits into
Open
autoantwort wants to merge 2 commits into
autoantwort wants to merge 2 commits into
Conversation
The lambda body in an initializer list was taken as the start of the constructor body, so following members got the parameter varid, lambda parameters leaked into the rest of the initializer list and the parameter varid leaked into later functions (FP uninitMemberVar, selfInitialization, functionStatic, constParameterPointer). The lambda is now parsed like a lambda in executable code. findTypeEnd() also finds the end of unlinked template brackets so that findLambdaEndScope() works for trailing return types like std::vector<int> before createLinks2(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hanged
`new (p) T*[n]{...}` and `new decltype(x)*[n]{...}` in an initializer list
were taken as lambdas. Revert the findTypeEnd() change to keep the PR small,
lambdas with templates in the trailing return type keep the old behaviour.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
https://trac.cppcheck.net/ticket/15084
In
setVarIdPass1()the body of a lambda in a constructor initializer list was taken as the start of the constructor body, so the following members got the parameter's varid, lambda parameters leaked into the rest of the initializer list and the parameter varid leaked into later functions (FPuninitMemberVar,selfInitialization,functionStatic,unusedStructMember,constParameterPointer):A lambda in an initializer list (detected with
findLambdaEndScope()) is now parsed like a lambda in executable code in its own scope, and the initializer list continues after it. Array sizes ofnewexpressions (new T[n]{...},new T*[n]{...},new (p) T*[n]{...}) are not taken as lambda captures.Covered: plain lambdas, parameters (also shadowing a constructor parameter),
mutable,noexcept, trailing return types,[&]/[=], nested lambdas, braced member initializers.Not handled (unchanged behaviour, to keep this PR small):
-> std::vector<int>),findLambdaEndScope()can't find their end beforecreateLinks2())or>((int)[p]{...}(),a > [p]{...}()), as they can't be told apart from a subscript herestd::string{"a"}.size() + [p]{...}()), the{of the temporary already ends the initializer list handlingFollow-up of the review of #8885.
This PR was created by Claude Code (an AI coding agent) on behalf of @autoantwort.
🤖 Generated with Claude Code