Fixed #9737 (False positive: unreadVariable)

This commit is contained in:
Daniel Marjamäki 2020-10-25 20:32:45 +01:00
parent 05514950af
commit 34c8334882
2 changed files with 10 additions and 2 deletions

View File

@ -1361,8 +1361,7 @@ std::pair<const Token *, const Token *> 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

View File

@ -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<char> cmanifest = z;\n"
" return {.a = cmanifest, .b =0};\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarloops() {
// loops
functionVariableUsage("void fun() {\n"