File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2627,6 +2627,14 @@ bool isNullOperand(const Token *expr)
26272627
26282628bool isGlobalData (const Token *expr, bool cpp)
26292629{
2630+ // function call that returns reference => assume global data
2631+ if (expr && expr->str () == " (" && expr->valueType () && expr->valueType ()->reference != Reference::None) {
2632+ if (expr->isBinaryOp ())
2633+ return true ;
2634+ if (expr->astOperand1 () && precedes (expr->astOperand1 (), expr))
2635+ return true ;
2636+ }
2637+
26302638 bool globalData = false ;
26312639 bool var = false ;
26322640 visitAstNodes (expr,
Original file line number Diff line number Diff line change @@ -173,6 +173,7 @@ class TestUnusedVar : public TestFixture {
173173 TEST_CASE (localvarStruct9);
174174 TEST_CASE (localvarStruct10);
175175 TEST_CASE (localvarStruct11); // 10095
176+ TEST_CASE (localvarStruct12); // #10495
176177 TEST_CASE (localvarStructArray);
177178 TEST_CASE (localvarUnion1);
178179
@@ -4509,6 +4510,16 @@ class TestUnusedVar : public TestFixture {
45094510 ASSERT_EQUALS (" " , errout.str ());
45104511 }
45114512
4513+ void localvarStruct12 () { // #10495
4514+ functionVariableUsage (" struct S { bool& Ref(); };\n "
4515+ " \n "
4516+ " void Set() {\n "
4517+ " S s;\n "
4518+ " s.Ref() = true;\n "
4519+ " }" );
4520+ ASSERT_EQUALS (" " , errout.str ());
4521+ }
4522+
45124523 void localvarStructArray () {
45134524 // extracttests.start: struct X {int a;};
45144525
You can’t perform that action at this time.
0 commit comments