diff --git a/lib/checkother.cpp b/lib/checkother.cpp index 9a8b8dd7e..827d8f656 100644 --- a/lib/checkother.cpp +++ b/lib/checkother.cpp @@ -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("*")) || diff --git a/test/testother.cpp b/test/testother.cpp index 071b9a08f..8a060de4c 100644 --- a/test/testother.cpp +++ b/test/testother.cpp @@ -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");