File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1359,13 +1359,19 @@ 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 ;
1362+ if (const ValueType *vt = expr->valueType ()) {
1363+ if (vt->type == ValueType::RECORD &&
1364+ !vt->pointer &&
1365+ vt->typeScope &&
1366+ vt->typeScope ->definedType &&
1367+ !symbolDatabase->isRecordTypeWithoutSideEffects (vt->typeScope ->definedType ))
1368+ continue ;
1369+
1370+ if (vt->type == ValueType::SMART_POINTER &&
1371+ vt->smartPointerType &&
1372+ !symbolDatabase->isRecordTypeWithoutSideEffects (vt->smartPointerType ))
1373+ continue ;
1374+ }
13691375
13701376 FwdAnalysis fwdAnalysis (*mSettings );
13711377 const Token* scopeEnd = ValueFlow::getEndOfExprScope (expr, scope, /* smallest*/ false );
Original file line number Diff line number Diff line change @@ -6767,6 +6767,13 @@ class TestUnusedVar : public TestFixture {
67676767 " p = nullptr;\n "
67686768 " }\n " );
67696769 ASSERT_EQUALS (" " , errout_str ());
6770+
6771+ functionVariableUsage (" struct S { S(); };\n " // #14160
6772+ " void f() {\n "
6773+ " auto p = std::make_unique<S>();\n "
6774+ " auto q = std::make_unique<U>();\n "
6775+ " }\n " );
6776+ ASSERT_EQUALS (" " , errout_str ());
67706777 }
67716778
67726779 // ticket #3104 - false positive when variable is read with "if (NOT var)"
You can’t perform that action at this time.
0 commit comments