Improve fix for #11383 FP selfAssignment: lambda capture (#4584)

This commit is contained in:
gerboengels 2022-11-18 19:44:32 +01:00 committed by GitHub
parent 4ce76d0b58
commit 3fdba645a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -2445,8 +2445,14 @@ void CheckOther::checkDuplicateExpression()
}
}
}
auto isInsideLambdaCaptureList = [](const Token* tok) {
const Token* parent = tok->astParent();
while (Token::simpleMatch(parent, ","))
parent = parent->astParent();
return isLambdaCaptureList(parent);
};
ErrorPath errorPath;
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>|+=|*=|<<=|>>=") && !isLambdaCaptureList(tok->astParent())) {
if (tok->isOp() && tok->astOperand1() && !Token::Match(tok, "+|*|<<|>>|+=|*=|<<=|>>=") && !isInsideLambdaCaptureList(tok)) {
if (Token::Match(tok, "==|!=|-") && astIsFloat(tok->astOperand1(), true))
continue;
const bool pointerDereference = (tok->astOperand1() && tok->astOperand1()->isUnaryOp("*")) ||

View File

@ -4853,7 +4853,8 @@ private:
check("struct S {\n" // #11383
" void f() {\n"
" auto l2 = [i = i]() { return i; };\n"
" int x = 42;"
" auto l2 = [i = i, x, y = 0]() { return i + x + y; };\n"
" }\n"
" int i;\n"
"};\n");