Fix #15084 Wrong varid for lambda in constructor initializer list - #8917
Open
autoantwort wants to merge 1 commit into
Open
autoantwort wants to merge 1 commit into
autoantwort wants to merge 1 commit 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>
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]{...}) are not taken as lambda captures.findTypeEnd()now also skips template brackets that are not linked yet (they are linked increateLinks2()aftersetVarId()), sofindLambdaEndScope()also works for trailing return types like-> std::vector<int>.Covered: plain lambdas, parameters (also shadowing a constructor parameter),
mutable,noexcept, trailing return types,[&]/[=], nested lambdas, braced member initializers. Template lambdas ([]<class T>(T v) {...}) are not handled becausefindLambdaEndScope()does not support them.Follow-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