Skip to content

Commit 3f85d61

Browse files
Goober5000claude
andauthored
use std::move() for local variables that are copied but not reused (scp-fs2open#7308)
* use std::move() for local variables that are copied but not reused Addresses ~140 Coverity "Variable copied when it could be moved" defects across 74 files. Every std::move() targets a local variable whose value is consumed by push_back, emplace, assignment, lambda capture, or a function call and is never read again afterward. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * clang: use std::make_shared * clang: use std::make_unique * address feedback --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0e1e055 commit 3f85d61

96 files changed

Lines changed: 250 additions & 258 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

code/actions/BuiltinActionDefinition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BuiltinActionDefinition : public ActionDefinition {
3030
// This should have been caught earlier
3131
Assertion(paramIter != parameterExpressions.cend(), "Could not find built-in parameter!");
3232

33-
return std::unique_ptr<Action>(new TAction(paramIter->second.template asTyped<ActionValueType>()));
33+
return std::make_unique<TAction>(paramIter->second.template asTyped<ActionValueType>());
3434
}
3535
};
3636

code/actions/expression/ActionExpression.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ ActionExpression ActionExpression::parseFromTable(ValueType expectedReturnType,
2424

2525
stuff_string(expressionText, F_NAME);
2626

27-
ExpressionParser parser(expressionText);
27+
ExpressionParser parser(std::move(expressionText));
2828

2929
auto expression = parser.parse(context);
3030

@@ -45,7 +45,7 @@ ActionExpression ActionExpression::parseFromTable(ValueType expectedReturnType,
4545
}
4646

4747
// Everything is valid
48-
return ActionExpression(expression);
48+
return ActionExpression(std::move(expression));
4949
}
5050

5151
Value ActionExpression::execute(const ProgramVariables& variables) const

code/actions/expression/ProgramVariables.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace expression {
66

77
ProgramVariablesDefinition& ProgramVariablesDefinition::addScope(const SCP_string& name)
88
{
9-
auto scope = std::unique_ptr<ProgramVariablesDefinition>(new ProgramVariablesDefinition());
9+
auto scope = std::make_unique<ProgramVariablesDefinition>();
1010

1111
auto scopePtr = scope.get();
1212

code/actions/types/MoveToSubmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ActionResult MoveToSubmodel::execute(ProgramLocals& locals) const
7070

7171
std::unique_ptr<Action> MoveToSubmodel::clone() const
7272
{
73-
return std::unique_ptr<Action>(new MoveToSubmodel(*this));
73+
return std::make_unique<MoveToSubmodel>(*this);
7474
}
7575

7676
} // namespace types

code/actions/types/ParticleEffectAction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ ActionResult ParticleEffectAction::execute(ProgramLocals& locals) const
6161
matrix orientation;
6262
vm_vector_2_matrix_norm(&orientation, &direction); // direction is normalized in SetDirectionAction::execute
6363

64-
source->setHost(make_unique<EffectHostObject>(locals.host.objp(), local_pos, orientation, true));
64+
source->setHost(std::make_unique<EffectHostObject>(locals.host.objp(), local_pos, orientation, true));
6565
source->finishCreation();
6666

6767
return ActionResult::Finished;
6868
}
6969

7070
std::unique_ptr<Action> ParticleEffectAction::clone() const
7171
{
72-
return std::unique_ptr<Action>(new ParticleEffectAction(*this));
72+
return std::make_unique<ParticleEffectAction>(*this);
7373
}
7474

7575
} // namespace types

code/actions/types/PlaySoundAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ ActionResult PlaySoundAction::execute(ProgramLocals& locals) const
5757
}
5858
std::unique_ptr<Action> PlaySoundAction::clone() const
5959
{
60-
return std::unique_ptr<Action>(new PlaySoundAction(*this));
60+
return std::make_unique<PlaySoundAction>(*this);
6161
}
6262
} // namespace types
6363
} // namespace actions

code/actions/types/SetDirectionAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ActionResult SetDirectionAction::execute(ProgramLocals& locals) const
3232

3333
std::unique_ptr<Action> SetDirectionAction::clone() const
3434
{
35-
return std::unique_ptr<Action>(new SetDirectionAction(*this));
35+
return std::make_unique<SetDirectionAction>(*this);
3636
}
3737

3838
} // namespace types

code/actions/types/SetPositionAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ActionResult SetPositionAction::execute(ProgramLocals& locals) const
2727

2828
std::unique_ptr<Action> SetPositionAction::clone() const
2929
{
30-
return std::unique_ptr<Action>(new SetPositionAction(*this));
30+
return std::make_unique<SetPositionAction>(*this);
3131
}
3232

3333
} // namespace types

code/actions/types/WaitAction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ ActionResult WaitAction::execute(actions::ProgramLocals& locals) const
4141
}
4242
std::unique_ptr<Action> WaitAction::clone() const
4343
{
44-
return std::unique_ptr<Action>(new WaitAction(*this));
44+
return std::make_unique<WaitAction>(*this);
4545
}
4646

4747
} // namespace types

code/ai/aiturret.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ bool turret_fire_weapon(int weapon_num,
20422042
}
20432043
//spawn particle effect
20442044
auto particleSource = particle::ParticleManager::get()->createSource(wip->muzzle_effect);
2045-
particleSource->setHost(make_unique<EffectHostTurret>(&Objects[parent_ship->objnum], turret->system_info->turret_gun_sobj, turret->turret_next_fire_pos, false));
2045+
particleSource->setHost(std::make_unique<EffectHostTurret>(&Objects[parent_ship->objnum], turret->system_info->turret_gun_sobj, turret->turret_next_fire_pos, false));
20462046
particleSource->setTriggerRadius(objp->radius * radius_mult);
20472047
particleSource->setTriggerVelocity(vm_vec_mag_quick(&objp->phys_info.vel));
20482048
particleSource->finishCreation();
@@ -2163,7 +2163,7 @@ void turret_swarm_fire_from_turret(turret_swarm_info *tsi)
21632163
if (Weapon_info[tsi->weapon_class].muzzle_effect.isValid()) {
21642164
//spawn particle effect
21652165
auto particleSource = particle::ParticleManager::get()->createSource(Weapon_info[tsi->weapon_class].muzzle_effect);
2166-
particleSource->setHost(make_unique<EffectHostTurret>(&Objects[tsi->parent_objnum], tsi->turret->system_info->turret_gun_sobj, tsi->turret->turret_next_fire_pos - 1, false));
2166+
particleSource->setHost(std::make_unique<EffectHostTurret>(&Objects[tsi->parent_objnum], tsi->turret->system_info->turret_gun_sobj, tsi->turret->turret_next_fire_pos - 1, false));
21672167
particleSource->setTriggerRadius(Objects[weapon_objnum].radius);
21682168
particleSource->finishCreation();
21692169
}

0 commit comments

Comments
 (0)