Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/checkunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,14 @@ void CheckUnusedVar::checkFunctionVariableUsage()
if (tok->previous() && tok->previous()->variable() && tok->previous()->variable()->nameToken()->scope()->type == ScopeType::eUnion)
continue;

if (expr->valueType() &&
expr->valueType()->type == ValueType::RECORD &&
!expr->valueType()->pointer &&
expr->valueType()->typeScope &&
expr->valueType()->typeScope->definedType &&
!symbolDatabase->isRecordTypeWithoutSideEffects(expr->valueType()->typeScope->definedType))
continue;

FwdAnalysis fwdAnalysis(*mSettings);
const Token* scopeEnd = ValueFlow::getEndOfExprScope(expr, scope, /*smallest*/ false);
if (fwdAnalysis.unusedValue(expr, start, scopeEnd)) {
Expand Down
4 changes: 4 additions & 0 deletions test/testunusedvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6681,6 +6681,10 @@ class TestUnusedVar : public TestFixture {
" C c(12);\n"
"}");
ASSERT_EQUALS("", errout_str());

functionVariableUsage("class S { S(int); };\n"
Comment thread
danmar marked this conversation as resolved.
"void f() { S s = 0; }\n");
ASSERT_EQUALS("", errout_str());
}

void localVarSmartPtr() {
Expand Down
Loading