Fixed #10495 (False positive: unreadVariable when assigning to reference returned by method)

This commit is contained in:
Daniel Marjamäki 2021-09-24 07:30:17 +02:00
parent 3c1ae77962
commit 2ee920dc4e
2 changed files with 19 additions and 0 deletions

View File

@ -2627,6 +2627,14 @@ bool isNullOperand(const Token *expr)
bool isGlobalData(const Token *expr, bool cpp)
{
// function call that returns reference => assume global data
if (expr && expr->str() == "(" && expr->valueType() && expr->valueType()->reference != Reference::None) {
if (expr->isBinaryOp())
return true;
if (expr->astOperand1() && precedes(expr->astOperand1(), expr))
return true;
}
bool globalData = false;
bool var = false;
visitAstNodes(expr,

View File

@ -173,6 +173,7 @@ private:
TEST_CASE(localvarStruct9);
TEST_CASE(localvarStruct10);
TEST_CASE(localvarStruct11); // 10095
TEST_CASE(localvarStruct12); // #10495
TEST_CASE(localvarStructArray);
TEST_CASE(localvarUnion1);
@ -4509,6 +4510,16 @@ private:
ASSERT_EQUALS("", errout.str());
}
void localvarStruct12() { // #10495
functionVariableUsage("struct S { bool& Ref(); };\n"
"\n"
"void Set() {\n"
" S s;\n"
" s.Ref() = true;\n"
"}");
ASSERT_EQUALS("", errout.str());
}
void localvarStructArray() {
// extracttests.start: struct X {int a;};