File tree Expand file tree Collapse file tree 2 files changed +36
-0
lines changed
Expand file tree Collapse file tree 2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -1359,6 +1359,14 @@ void CheckUnusedVar::checkFunctionVariableUsage()
13591359 if (tok->previous () && tok->previous ()->variable () && tok->previous ()->variable ()->nameToken ()->scope ()->type == ScopeType::eUnion)
13601360 continue ;
13611361
1362+ if (expr->valueType () &&
1363+ expr->valueType ()->type == ValueType::RECORD &&
1364+ !expr->valueType ()->pointer &&
1365+ expr->valueType ()->typeScope &&
1366+ expr->valueType ()->typeScope ->definedType &&
1367+ !symbolDatabase->isRecordTypeWithoutSideEffects (expr->valueType ()->typeScope ->definedType ))
1368+ continue ;
1369+
13621370 FwdAnalysis fwdAnalysis (*mSettings );
13631371 const Token* scopeEnd = ValueFlow::getEndOfExprScope (expr, scope, /* smallest*/ false );
13641372 if (fwdAnalysis.unusedValue (expr, start, scopeEnd)) {
Original file line number Diff line number Diff line change @@ -6681,6 +6681,34 @@ class TestUnusedVar : public TestFixture {
66816681 " C c(12);\n "
66826682 " }" );
66836683 ASSERT_EQUALS (" " , errout_str ());
6684+
6685+ // #14643
6686+ functionVariableUsage (" class S { S(int); };\n "
6687+ " void f() { S s = 0; }\n " );
6688+ ASSERT_EQUALS (" " , errout_str ());
6689+
6690+ // #10965
6691+ functionVariableUsage (" class A {\n "
6692+ " public:\n "
6693+ " A();\n "
6694+ " };\n "
6695+ " extern A cb();\n "
6696+ " void f() { const A c = cb(); }\n " );
6697+ ASSERT_EQUALS (" " , errout_str ());
6698+
6699+ // #11704
6700+ functionVariableUsage (" class S {\n "
6701+ " public:\n "
6702+ " S();\n "
6703+ " };\n "
6704+ " class C {\n "
6705+ " S &s();\n "
6706+ " void f() {\n "
6707+ " const S s1 = s(); // warning\n "
6708+ " const S s2; // no warning\n "
6709+ " }\n "
6710+ " };\n " );
6711+ ASSERT_EQUALS (" " , errout_str ());
66846712 }
66856713
66866714 void localVarSmartPtr () {
You can’t perform that action at this time.
0 commit comments