Skip to content

Commit

Permalink
clang-tidy bugprone-use-after-move (#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 ZhilkinSerg committed Aug 26, 2019
1 parent 5d0737e commit 19f0f67
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 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
2 changes: 1 addition & 1 deletion src/dialogue.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct talk_effect_fun_t {
void set_bulk_trade_accept( bool is_trade, bool is_npc = false );
void set_npc_gets_item( bool to_use );
void set_add_mission( std::string mission_id );
void set_u_buy_monster( const std::string &monster_id, int cost, int count, bool pacified,
void set_u_buy_monster( const std::string &monster_type_id, int cost, int count, bool pacified,
const translation &name );

void operator()( const dialogue &d ) const {
Expand Down
12 changes: 7 additions & 5 deletions src/ranged.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,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 @@ -660,9 +665,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 19f0f67

Please sign in to comment.