Skip to content

Commit

Permalink
clang-tidy bugprone-use-after-move (CleverRaven#33557)
Browse files Browse the repository at this point in the history
* Enable bugprone-use-after-move

Enable this clang-tidy check and deal with associated warnings.

Mostly these were suppressions for things in the tests that are
specifically testing move constructor semantics, but one case was a
genuine latent bug.

* Fix mismatched declaration name

This error seems to have crept into master.
  • Loading branch information
jbytheway authored and misterprimus committed Sep 21, 2019
1 parent c753343 commit 930d7e7
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ readability-*,\
-bugprone-misplaced-widening-cast,\
-bugprone-narrowing-conversions,\
-bugprone-unused-return-value,\
-bugprone-use-after-move,\
-cert-err34-c,\
-cert-flp30-c,\
-cert-msc30-c,\
Expand Down
12 changes: 7 additions & 5 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,15 @@ dealt_projectile_attack player::throw_item( const tripoint &target, const item &
proj_effects.insert( "TANGLE" );
}

Creature *critter = g->critter_at( target, true );
const dispersion_sources dispersion = throwing_dispersion( thrown, critter,
blind_throw_from_pos.has_value() );
const itype *thrown_type = thrown.type;

// Put the item into the projectile
proj.set_drop( std::move( thrown ) );
if( thrown.has_flag( "CUSTOM_EXPLOSION" ) ) {
proj.set_custom_explosion( thrown.type->explosion );
if( thrown_type->item_tags.count( "CUSTOM_EXPLOSION" ) ) {
proj.set_custom_explosion( thrown_type->explosion );
}

// Throw from the player's position, unless we're blind throwing, in which case
Expand All @@ -703,9 +708,6 @@ dealt_projectile_attack player::throw_item( const tripoint &target, const item &
// This should generally have values below ~20*sqrt(skill_lvl)
const float final_xp_mult = range_factor * damage_factor;

Creature *critter = g->critter_at( target, true );
const dispersion_sources dispersion = throwing_dispersion( thrown, critter,
blind_throw_from_pos.has_value() );
auto dealt_attack = projectile_attack( proj, throw_from, target, dispersion, this );

const double missed_by = dealt_attack.missed_by;
Expand Down
1 change: 1 addition & 0 deletions tests/colony_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ TEST_CASE( "colony basics", "[colony]" )
// Move test
CHECK( test_colony_2.size() == 400 );

// NOLINTNEXTLINE(bugprone-use-after-move)
test_colony.insert( &ten );

// Insert to post-moved-colony test
Expand Down
3 changes: 3 additions & 0 deletions tests/list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ TEST_CASE( "list basics", "[list]" )

SECTION( "swap() and max_size()" ) {
cata::list<int *> test_list_2;
// NOLINTNEXTLINE(bugprone-use-after-move)
test_list_2 = test_list;

CHECK( test_list_2.size() == 400 );
Expand Down Expand Up @@ -951,6 +952,7 @@ TEST_CASE( "list emplace, move, copy, and reverse iterate", "[list]" )
}

CHECK( passed );
// NOLINTNEXTLINE(bugprone-use-after-move)
CHECK( test_list.empty() );
}

Expand All @@ -974,6 +976,7 @@ TEST_CASE( "list emplace, move, copy, and reverse iterate", "[list]" )
}

CHECK( passed );
// NOLINTNEXTLINE(bugprone-use-after-move)
CHECK( test_list_2.empty() );
}

Expand Down
1 change: 1 addition & 0 deletions tests/string_formatter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ TEST_CASE( "string_formatter" )
const std::string expected = "b" + long_string + "b";
// moving into string_format should *not* consume the string.
test_for_expected( expected, "b%sb", std::move( long_string ) );
// NOLINTNEXTLINE(bugprone-use-after-move)
CHECK( long_string.size() == 100000 );
}

Expand Down

0 comments on commit 930d7e7

Please sign in to comment.