diff --git a/lib/astutils.cpp b/lib/astutils.cpp index 1a77296ee..cdf5e9d26 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -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, diff --git a/test/testunusedvar.cpp b/test/testunusedvar.cpp index 9a66aa984..4247af5cb 100644 --- a/test/testunusedvar.cpp +++ b/test/testunusedvar.cpp @@ -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;};