Skip to content

Commit

Permalink
Improve fix for #11383 FP selfAssignment: lambda capture (danmar#4584)
Browse files Browse the repository at this point in the history
  • Loading branch information
gerboengels authored Nov 18, 2022
1 parent 4ce76d0 commit 3fdba64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/checkother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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("*")) ||
Expand Down
3 changes: 2 additions & 1 deletion test/testother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4853,7 +4853,8 @@ class TestOther : public TestFixture {

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");
Expand Down

0 comments on commit 3fdba64

Please sign in to comment.