Skip to content

Commit

Permalink
Enable modernize-make-unique
Browse files Browse the repository at this point in the history
Apply changes suggested by the clang-tidy modernize-use-make-unique
check and enable it.
  • Loading branch information
jbytheway authored and kevingranade committed Aug 2, 2019
1 parent 219b12f commit 0b8fac6
Show file tree
Hide file tree
Showing 16 changed files with 52 additions and 38 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ readability-*,\
-misc-redundant-expression,\
-modernize-avoid-c-arrays,\
-modernize-deprecated-headers,\
-modernize-make-unique,\
-modernize-pass-by-value,\
-modernize-raw-string-literal,\
-modernize-return-braced-init-list,\
Expand Down
11 changes: 6 additions & 5 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <iterator>
#include <locale>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
Expand Down Expand Up @@ -275,7 +276,7 @@ game::game() :
{
player_was_sleeping = false;
reset_light_level();
world_generator.reset( new worldfactory() );
world_generator = std::make_unique<worldfactory>();
// do nothing, everything that was in here is moved to init_data() which is called immediately after g = new game; in main.cpp
// The reason for this move is so that g is not uninitialized when it gets to installing the parts into vehicles.
}
Expand Down Expand Up @@ -663,7 +664,7 @@ void game::load_map( const tripoint &pos_sm )
bool game::start_game()
{
if( !gamemode ) {
gamemode.reset( new special_game() );
gamemode = std::make_unique<special_game>();
}

seed = rng_bits();
Expand Down Expand Up @@ -1206,7 +1207,7 @@ bool game::cleanup_at_end()
popup( message.str(), PF_NONE );
}
if( gamemode ) {
gamemode.reset( new special_game() ); // null gamemode or something..
gamemode = std::make_unique<special_game>(); // null gamemode or something..
}
}

Expand Down Expand Up @@ -2646,7 +2647,7 @@ void game::load( const save_t &name )
u.recalc_sight_limits();

if( !gamemode ) {
gamemode.reset( new special_game() );
gamemode = std::make_unique<special_game>();
}

safe_mode = get_option<bool>( "SAFEMODE" ) ? SAFE_MODE_ON : SAFE_MODE_OFF;
Expand Down Expand Up @@ -10160,7 +10161,7 @@ void game::vertical_move( int movez, bool force )

std::unique_ptr<map> tmp_map_ptr;
if( !m.has_zlevels() ) {
tmp_map_ptr.reset( new map() );
tmp_map_ptr = std::make_unique<map>();
}

map &maybetmp = m.has_zlevels() ? m : *( tmp_map_ptr.get() );
Expand Down
10 changes: 6 additions & 4 deletions src/gamemode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "gamemode.h"

#include <memory>

#include "debug.h"
#include "translations.h"

Expand All @@ -23,17 +25,17 @@ std::unique_ptr<special_game> get_special_game( special_game_id id )
std::unique_ptr<special_game> ret;
switch( id ) {
case SGAME_NULL:
ret.reset( new special_game );
ret = std::make_unique<special_game>();
break;
case SGAME_TUTORIAL:
ret.reset( new tutorial_game );
ret = std::make_unique<tutorial_game>();
break;
case SGAME_DEFENSE:
ret.reset( new defense_game );
ret = std::make_unique<defense_game>();
break;
default:
debugmsg( "Missing something in gamemode.cpp:get_special_game()?" );
ret.reset( new special_game );
ret = std::make_unique<special_game>();
break;
}

Expand Down
22 changes: 12 additions & 10 deletions src/item_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <algorithm>
#include <cassert>
#include <cmath>
#include <memory>
#include <sstream>
#include <array>
#include <iterator>
Expand Down Expand Up @@ -574,7 +575,7 @@ void Item_factory::add_item_type( const itype &def )
}

auto &new_item_ptr = m_runtimes[ def.id ];
new_item_ptr.reset( new itype( def ) );
new_item_ptr = std::make_unique<itype>( def );
if( frozen ) {
finalize_pre( *new_item_ptr );
finalize_post( *new_item_ptr );
Expand Down Expand Up @@ -812,7 +813,8 @@ void Item_factory::init()
add_actor( new sew_advanced_actor() );
// An empty dummy group, it will not spawn anything. However, it makes that item group
// id valid, so it can be used all over the place without need to explicitly check for it.
m_template_groups["EMPTY_GROUP"].reset( new Item_group( Item_group::G_COLLECTION, 100, 0, 0 ) );
m_template_groups["EMPTY_GROUP"] = std::make_unique<Item_group>( Item_group::G_COLLECTION, 100, 0,
0 );
}

bool Item_factory::check_ammo_type( std::ostream &msg, const ammotype &ammo ) const
Expand Down Expand Up @@ -2458,12 +2460,12 @@ void Item_factory::add_entry( Item_group &ig, JsonObject &obj )
int probability = obj.get_int( "prob", 100 );
JsonArray jarr;
if( obj.has_member( "collection" ) ) {
gptr.reset( new Item_group( Item_group::G_COLLECTION, probability, ig.with_ammo,
ig.with_magazine ) );
gptr = std::make_unique<Item_group>( Item_group::G_COLLECTION, probability, ig.with_ammo,
ig.with_magazine );
jarr = obj.get_array( "collection" );
} else if( obj.has_member( "distribution" ) ) {
gptr.reset( new Item_group( Item_group::G_DISTRIBUTION, probability, ig.with_ammo,
ig.with_magazine ) );
gptr = std::make_unique<Item_group>( Item_group::G_DISTRIBUTION, probability, ig.with_ammo,
ig.with_magazine );
jarr = obj.get_array( "distribution" );
}
if( gptr ) {
Expand All @@ -2477,11 +2479,11 @@ void Item_factory::add_entry( Item_group &ig, JsonObject &obj )

std::unique_ptr<Single_item_creator> sptr;
if( obj.has_member( "item" ) ) {
sptr.reset( new Single_item_creator( obj.get_string( "item" ), Single_item_creator::S_ITEM,
probability ) );
sptr = std::make_unique<Single_item_creator>(
obj.get_string( "item" ), Single_item_creator::S_ITEM, probability );
} else if( obj.has_member( "group" ) ) {
sptr.reset( new Single_item_creator( obj.get_string( "group" ), Single_item_creator::S_ITEM_GROUP,
probability ) );
sptr = std::make_unique<Single_item_creator>(
obj.get_string( "group" ), Single_item_creator::S_ITEM_GROUP, probability );
}
if( !sptr ) {
return;
Expand Down
4 changes: 3 additions & 1 deletion src/loading_ui.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "loading_ui.h"

#include <memory>

#include "color.h"
#include "output.h"
#include "ui.h"
Expand All @@ -19,7 +21,7 @@ extern bool test_mode;
loading_ui::loading_ui( bool display )
{
if( display && !test_mode ) {
menu.reset( new uilist );
menu = std::make_unique<uilist>();
menu->settext( _( "Loading" ) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ int main( int argc, char *argv[] )

rng_set_engine_seed( seed );

g.reset( new game );
g = std::make_unique<game>();
// First load and initialize everything that does not
// depend on the mods.
try {
Expand Down
3 changes: 2 additions & 1 deletion src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cstdlib>
#include <algorithm>
#include <list>
#include <memory>
#include <sstream>
#include <array>
#include <functional>
Expand Down Expand Up @@ -7175,7 +7176,7 @@ computer *map::add_computer( const tripoint &p, const std::string &name, int sec
{
ter_set( p, t_console ); // TODO: Turn this off?
submap *place_on_submap = get_submap_at( p );
place_on_submap->comp.reset( new computer( name, security ) );
place_on_submap->comp = std::make_unique<computer>( name, security );
return place_on_submap->comp.get();
}

Expand Down
12 changes: 7 additions & 5 deletions src/mutation_data.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mutation.h" // IWYU pragma: associated

#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <vector>
Expand Down Expand Up @@ -715,10 +716,10 @@ void mutation_branch::add_entry( Trait_group &tg, JsonObject &obj )
JsonArray jarr;

if( obj.has_member( "collection" ) ) {
ptr.reset( new Trait_group_collection( probability ) );
ptr = std::make_unique<Trait_group_collection>( probability );
jarr = obj.get_array( "collection" );
} else if( obj.has_member( "distribution" ) ) {
ptr.reset( new Trait_group_distribution( probability ) );
ptr = std::make_unique<Trait_group_distribution>( probability );
jarr = obj.get_array( "distribution" );
}

Expand All @@ -734,10 +735,11 @@ void mutation_branch::add_entry( Trait_group &tg, JsonObject &obj )

if( obj.has_member( "trait" ) ) {
trait_id id( obj.get_string( "trait" ) );
ptr.reset( new Single_trait_creator( id, probability ) );
ptr = std::make_unique<Single_trait_creator>( id, probability );
} else if( obj.has_member( "group" ) ) {
ptr.reset( new Trait_group_creator( trait_group::Trait_group_tag( obj.get_string( "group" ) ),
probability ) );
ptr = std::make_unique<Trait_group_creator>( trait_group::Trait_group_tag(
obj.get_string( "group" ) ),
probability );
}

if( !ptr ) {
Expand Down
2 changes: 1 addition & 1 deletion src/npcmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,7 +2162,7 @@ void npc::move_to( const tripoint &pt, bool no_bashing, std::set<tripoint> *nomo
realnomove = nomove;
} else {
// create the no-move list
newnomove.reset( new std::set<tripoint>() );
newnomove = std::make_unique<std::set<tripoint>>();
realnomove = newnomove.get();
}
// other npcs should not try to move into this npc anymore,
Expand Down
3 changes: 2 additions & 1 deletion src/pixel_minimap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <assert.h>
#include <stdlib.h>
#include <memory>
#include <set>
#include <vector>
#include <algorithm>
Expand Down Expand Up @@ -379,7 +380,7 @@ void pixel_minimap::set_screen_rect( const SDL_Rect &screen_rect )
cache.clear();

main_tex = create_cache_texture( renderer, clip_rect.w, clip_rect.h );
tex_pool.reset( new shared_texture_pool() );
tex_pool = std::make_unique<shared_texture_pool>();

for( auto &elem : tex_pool->texture_pool ) {
elem = create_cache_texture( renderer, tile_size.x * SEEX, tile_size.y * SEEY );
Expand Down
7 changes: 4 additions & 3 deletions src/projectile.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "projectile.h"

#include <memory>
#include <utility>

#include "explosion.h"
Expand Down Expand Up @@ -50,7 +51,7 @@ void projectile::set_drop( const item &it )
if( it.is_null() ) {
unset_drop();
} else {
drop.reset( new item( it ) );
drop = std::make_unique<item>( it );
}
}

Expand All @@ -59,7 +60,7 @@ void projectile::set_drop( item &&it )
if( it.is_null() ) {
unset_drop();
} else {
drop.reset( new item( std::move( it ) ) );
drop = std::make_unique<item>( std::move( it ) );
}
}

Expand All @@ -80,7 +81,7 @@ const explosion_data &projectile::get_custom_explosion() const

void projectile::set_custom_explosion( const explosion_data &ex )
{
custom_explosion.reset( new explosion_data( ex ) );
custom_explosion = std::make_unique<explosion_data>( ex );
}

void projectile::unset_custom_explosion()
Expand Down
2 changes: 1 addition & 1 deletion src/sdltiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3440,7 +3440,7 @@ void catacurses::init_interface()
WinCreate();

dbg( D_INFO ) << "Initializing SDL Tiles context";
tilecontext.reset( new cata_tiles( renderer ) );
tilecontext = std::make_unique<cata_tiles>( renderer );
try {
tilecontext->load_tileset( get_option<std::string>( "TILES" ), true );
} catch( const std::exception &err ) {
Expand Down
3 changes: 2 additions & 1 deletion src/string_input_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include <cstdlib>
#include <algorithm>
#include <memory>
#include <vector>

string_input_popup::string_input_popup() = default;
Expand Down Expand Up @@ -92,7 +93,7 @@ void string_input_popup::create_window()

void string_input_popup::create_context()
{
ctxt_ptr.reset( new input_context( "STRING_INPUT" ) );
ctxt_ptr = std::make_unique<input_context>( "STRING_INPUT" );
ctxt = ctxt_ptr.get();
ctxt->register_action( "ANY_INPUT" );
}
Expand Down
3 changes: 2 additions & 1 deletion src/veh_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <cassert>
#include <cstddef>
#include <memory>
#include <numeric>
#include <sstream>
#include <unordered_map>
Expand Down Expand Up @@ -1060,7 +1061,7 @@ void vehicle_prototype::finalize()
// Calls the default constructor to create an empty vehicle. Calling the constructor with
// the type as parameter would make it look up the type in the map and copy the
// (non-existing) blueprint.
proto.blueprint.reset( new vehicle() );
proto.blueprint = std::make_unique<vehicle>();
vehicle &blueprint = *proto.blueprint;
blueprint.type = id;
blueprint.name = _( proto.name );
Expand Down
3 changes: 2 additions & 1 deletion src/worldfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <cstdlib>
#include <fstream>
#include <iterator>
#include <memory>
#include <set>
#include <sstream>
#include <unordered_map>
Expand Down Expand Up @@ -276,7 +277,7 @@ void worldfactory::init()
worldname = native_to_utf8( world_dir.substr( name_index + 1 ) );

// create and store the world
all_worlds[worldname].reset( new WORLD() );
all_worlds[worldname] = std::make_unique<WORLD>();
// give the world a name
all_worlds[worldname]->world_name = worldname;
// add sav files
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void init_global_game_state( const std::vector<mod_id> &mods,
}
init_colors();

g.reset( new game );
g = std::make_unique<game>( );
g->new_game = true;
g->load_static_data();

Expand Down

0 comments on commit 0b8fac6

Please sign in to comment.