diff --git a/lib/token.cpp b/lib/token.cpp index 31b3c959c..837f20491 100644 --- a/lib/token.cpp +++ b/lib/token.cpp @@ -1361,8 +1361,7 @@ std::pair Token::findExpressionStartEndTokens() co // find start node in AST tree const Token *start = top; - while (start->astOperand1() && - (start->astOperand2() || !start->isUnaryPreOp() || Token::simpleMatch(start, "( )") || start->str() == "{")) + while (start->astOperand1() && precedes(start->astOperand1(), start)) start = start->astOperand1(); // find end node in AST tree diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 3c33690d7..c72645b60 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -118,6 +118,7 @@ private: TEST_CASE(localvar56); TEST_CASE(localvar57); // #8974 - increment TEST_CASE(localvar58); // #9901 - increment false positive + TEST_CASE(localvar59); // #9737 TEST_CASE(localvarloops); // loops TEST_CASE(localvaralias1); TEST_CASE(localvaralias2); // ticket #1637 @@ -2479,6 +2480,14 @@ private: ASSERT_EQUALS("[test.cpp:3]: (style) Variable 'x' is assigned a value that is never used.\n", errout.str()); } + void localvar59() { // #9737 + functionVariableUsage("Response foo() {\n" + " const std::vector cmanifest = z;\n" + " return {.a = cmanifest, .b =0};\n" + "}"); + ASSERT_EQUALS("", errout.str()); + } + void localvarloops() { // loops functionVariableUsage("void fun() {\n"