Fixed #10495 (False positive: unreadVariable when assigning to reference returned by method)
This commit is contained in:
parent
3c1ae77962
commit
2ee920dc4e
|
@ -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,
|
||||
|
|
|
@ -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;};
|
||||
|
||||
|
|
Loading…
Reference in New Issue