Skip to content

Commit

Permalink
clang-tidy modernize-use-equals-default and -delete (CleverRaven#33360)
Browse files Browse the repository at this point in the history
* Enable modernize-use-equals-default and -delete

Enable these clang-tidy checks and fix the related issues.

Mostly this means adding '= default' on a bunch of member functions.

Also:
- Made the Character deleted members public.
- Moved the oter_type_id, npc_template, overmap_special_terrain,
  SkillLevel, and selection_column_preset default constructors
  out-of-line (for the sake of avoiding the clang warning about const
  objects without user-provided default constructors).

* Try alternate solution to clang warning

* Fix unused variable warning
  • Loading branch information
jbytheway authored and ZhilkinSerg committed Aug 20, 2019
1 parent 63c7d00 commit dffa505
Show file tree
Hide file tree
Showing 23 changed files with 40 additions and 77 deletions.
2 changes: 0 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ readability-*,\
-modernize-use-auto,\
-modernize-use-default-member-init,\
-modernize-use-emplace,\
-modernize-use-equals-default,\
-modernize-use-equals-delete,\
-modernize-use-transparent-functors,\
-performance-for-range-copy,\
-performance-inefficient-vector-operation,\
Expand Down
4 changes: 1 addition & 3 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ int base_camps::max_upgrade_by_type( const std::string &type )
return max_upgrade_cache[type];
}

basecamp::basecamp()
{
}
basecamp::basecamp() = default;

basecamp::basecamp( const std::string &name_, const tripoint &omt_pos_ ): name( name_ ),
omt_pos( omt_pos_ )
Expand Down
4 changes: 2 additions & 2 deletions src/character.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ inline social_modifiers operator+( social_modifiers lhs, const social_modifiers
class Character : public Creature, public visitable<Character>
{
public:
Character( const Character & ) = delete;
Character &operator=( const Character & ) = delete;
~Character() override;

field_type_id bloodType() const override;
Expand Down Expand Up @@ -887,9 +889,7 @@ class Character : public Creature, public visitable<Character>
std::array<int, num_hp_parts> healed_total;
protected:
Character();
Character( const Character & ) = delete;
Character( Character && );
Character &operator=( const Character & ) = delete;
Character &operator=( Character && );
struct trait_data {
/** Whether the mutation is activated. */
Expand Down
4 changes: 2 additions & 2 deletions src/colony.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ class colony : private element_allocator_type
return !( rh.it > it );
}

colony_reverse_iterator() noexcept {}
colony_reverse_iterator() noexcept = default;

colony_reverse_iterator( const colony_reverse_iterator &source ) noexcept:
it( source.it ) {}
Expand Down Expand Up @@ -3219,7 +3219,7 @@ class colony : private element_allocator_type
stored_instance( function_instance )
{}

sort_dereferencer() noexcept {}
sort_dereferencer() noexcept = default;

bool operator()( const pointer first, const pointer second ) {
return stored_instance( *first, *second );
Expand Down
4 changes: 1 addition & 3 deletions src/dependency_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,7 @@ std::vector<dependency_node *> dependency_node::get_dependents_as_nodes()
return ret;
}

dependency_tree::dependency_tree()
{
}
dependency_tree::dependency_tree() = default;

void dependency_tree::init( std::map<mod_id, std::vector<mod_id> > key_dependency_map )
{
Expand Down
6 changes: 3 additions & 3 deletions src/inventory_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ bool inventory_entry::operator==( const inventory_entry &other ) const
return get_category_ptr() == other.get_category_ptr() && locations == other.locations;
}

class selection_column_preset: public inventory_selector_preset
class selection_column_preset : public inventory_selector_preset
{
public:
selection_column_preset() {}
selection_column_preset() = default;

std::string get_caption( const inventory_entry &entry ) const override {
std::ostringstream res;
Expand Down Expand Up @@ -125,7 +125,7 @@ class selection_column_preset: public inventory_selector_preset
}
};

static const selection_column_preset selection_preset;
static const selection_column_preset selection_preset{};

int inventory_entry::get_total_charges() const
{
Expand Down
16 changes: 2 additions & 14 deletions src/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6462,21 +6462,9 @@ bool item::units_sufficient( const Character &ch, int qty ) const
return units_remaining( ch, qty ) == qty;
}

item::reload_option::reload_option( const reload_option &rhs ) :
who( rhs.who ), target( rhs.target ), ammo( rhs.ammo ),
qty_( rhs.qty_ ), max_qty( rhs.max_qty ), parent( rhs.parent ) {}
item::reload_option::reload_option( const reload_option & ) = default;

item::reload_option &item::reload_option::operator=( const reload_option &rhs )
{
who = rhs.who;
target = rhs.target;
ammo = rhs.ammo;
qty_ = rhs.qty_;
max_qty = rhs.max_qty;
parent = rhs.parent;

return *this;
}
item::reload_option &item::reload_option::operator=( const reload_option & ) = default;

item::reload_option::reload_option( const player *who, const item *target, const item *parent,
const item_location &ammo ) :
Expand Down
11 changes: 1 addition & 10 deletions src/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,7 @@ JsonObject::JsonObject( const JsonObject &jo )
final_separator = jo.final_separator;
}

JsonObject &JsonObject::operator=( const JsonObject &jo )
{
jsin = jo.jsin;
start = jo.start;
positions = jo.positions;
end = jo.end;
final_separator = jo.final_separator;

return *this;
}
JsonObject &JsonObject::operator=( const JsonObject &jo ) = default;

void JsonObject::finish()
{
Expand Down
4 changes: 2 additions & 2 deletions src/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -1053,9 +1053,9 @@ class JsonSerializer
class JsonDeserializer
{
public:
virtual ~JsonDeserializer() {}
virtual ~JsonDeserializer() = default;
virtual void deserialize( JsonIn &jsin ) = 0;
JsonDeserializer() { }
JsonDeserializer() = default;
JsonDeserializer( JsonDeserializer && ) = default;
JsonDeserializer( const JsonDeserializer & ) = default;
JsonDeserializer &operator=( JsonDeserializer && ) = default;
Expand Down
12 changes: 4 additions & 8 deletions src/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
struct node_base {
node_pointer_type next, previous;

node_base()
{}
node_base() = default;

node_base( const node_pointer_type &n, const node_pointer_type &p ):
next( n ),
Expand Down Expand Up @@ -265,8 +264,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
return *this;
}

~group_vector() noexcept
{}
~group_vector() noexcept = default;

void destroy_all_data( const node_pointer_type last_endpoint_node ) noexcept {
if( block_pointer == nullptr ) {
Expand Down Expand Up @@ -1910,8 +1908,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
stored_instance( function_instance )
{}

sort_dereferencer() noexcept
{}
sort_dereferencer() noexcept = default;

inline bool operator()( const node_pointer_type first, const node_pointer_type second ) {
return stored_instance( first->element, second->element );
Expand Down Expand Up @@ -2283,8 +2280,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
value( store_value )
{}

eq_to() noexcept
{}
eq_to() noexcept = default;

inline bool operator()( const element_type compare_value ) const noexcept {
return value == compare_value;
Expand Down
4 changes: 1 addition & 3 deletions src/mattack_actors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,7 @@ mattack_actor *melee_actor::clone() const
return new melee_actor( *this );
}

bite_actor::bite_actor()
{
}
bite_actor::bite_actor() = default;

void bite_actor::load_internal( JsonObject &obj, const std::string &src )
{
Expand Down
4 changes: 2 additions & 2 deletions src/mattack_actors.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class leap_actor : public mattack_actor
// Don't jump if distance to target is more than this
float max_consider_range;

leap_actor() { }
leap_actor() = default;
~leap_actor() override = default;

void load_internal( JsonObject &jo, const std::string &src ) override;
Expand All @@ -50,7 +50,7 @@ class mon_spellcasting_actor : public mattack_actor
spell spell_data;
int move_cost;

mon_spellcasting_actor() {}
mon_spellcasting_actor() = default;
~mon_spellcasting_actor() override = default;

void load_internal( JsonObject &jo, const std::string &src ) override;
Expand Down
2 changes: 1 addition & 1 deletion src/mattack_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using mon_action_attack = bool ( * )( monster * );
class mattack_actor
{
protected:
mattack_actor() { }
mattack_actor() = default;
public:
mattack_actor( const mattack_id &new_id ) : id( new_id ) { }

Expand Down
2 changes: 1 addition & 1 deletion src/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ const npc_template &string_id<npc_template>::obj() const
const auto found = npc_templates.find( *this );
if( found == npc_templates.end() ) {
debugmsg( "Tried to get invalid npc: %s", c_str() );
static const npc_template dummy;
static const npc_template dummy{};
return dummy;
}
return found->second;
Expand Down
2 changes: 1 addition & 1 deletion src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1295,7 +1295,7 @@ class standard_npc : public npc
class npc_template
{
public:
npc_template() {}
npc_template() = default;

npc guy;

Expand Down
6 changes: 1 addition & 5 deletions src/npc_class.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,8 +462,4 @@ distribution distribution::operator*( const distribution &other ) const
} );
}

distribution &distribution::operator=( const distribution &other )
{
generator_function = other.generator_function;
return *this;
}
distribution &distribution::operator=( const distribution &other ) = default;
4 changes: 2 additions & 2 deletions src/omdata.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ struct oter_type_t {

std::string get_symbol() const;

oter_type_t() {}
oter_type_t() = default;

oter_id get_first() const;
oter_id get_rotated( om_direction::type dir ) const;
Expand Down Expand Up @@ -359,7 +359,7 @@ struct overmap_special_spawns : public overmap_spawns {
};

struct overmap_special_terrain {
overmap_special_terrain() {}
overmap_special_terrain() = default;
tripoint p;
oter_str_id terrain;
std::set<std::string> flags;
Expand Down
4 changes: 2 additions & 2 deletions src/overmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ oter_id ot_null,
ot_forest_water,
ot_river_center;

const oter_type_t oter_type_t::null_type;
const oter_type_t oter_type_t::null_type{};

namespace om_lines
{
Expand Down Expand Up @@ -877,7 +877,7 @@ const overmap_special_terrain &overmap_special::get_terrain_at( const tripoint &
return elem.p == p;
} );
if( iter == terrains.end() ) {
static const overmap_special_terrain null_terrain;
static const overmap_special_terrain null_terrain{};
return null_terrain;
}
return *iter;
Expand Down
6 changes: 3 additions & 3 deletions src/requirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct component {
// If true, it's not actually a component but a requirement (list of components)
bool requirement = false;

component() { }
component() = default;
component( const itype_id &TYPE, int COUNT ) : type( TYPE ), count( COUNT ) { }
component( const itype_id &TYPE, int COUNT, bool RECOVERABLE ) :
type( TYPE ), count( COUNT ), recoverable( RECOVERABLE ) { }
Expand All @@ -71,7 +71,7 @@ struct component {
};

struct tool_comp : public component {
tool_comp() { }
tool_comp() = default;
tool_comp( const itype_id &TYPE, int COUNT ) : component( TYPE, COUNT ) { }

void load( JsonArray &ja );
Expand All @@ -87,7 +87,7 @@ struct tool_comp : public component {
};

struct item_comp : public component {
item_comp() { }
item_comp() = default;
item_comp( const itype_id &TYPE, int COUNT ) : component( TYPE, COUNT ) { }

void load( JsonArray &ja );
Expand Down
2 changes: 1 addition & 1 deletion src/skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ bool SkillLevel::can_train() const

const SkillLevel &SkillLevelMap::get_skill_level_object( const skill_id &ident ) const
{
static const SkillLevel null_skill;
static const SkillLevel null_skill{};

if( ident && ident->is_contextual_skill() ) {
debugmsg( "Skill \"%s\" is context-dependent. It cannot be assigned.", ident.str() );
Expand Down
2 changes: 1 addition & 1 deletion src/skill.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class SkillLevel
int _highestLevel = 0;

public:
SkillLevel() {}
SkillLevel() = default;

bool isTraining() const {
return _isTraining;
Expand Down
6 changes: 3 additions & 3 deletions src/vehicle_group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const VehicleGroup &string_id<VehicleGroup>::obj() const
const auto iter = vgroups.find( *this );
if( iter == vgroups.end() ) {
debugmsg( "invalid vehicle group id %s", c_str() );
static const VehicleGroup dummy;
static const VehicleGroup dummy{};
return dummy;
}
return iter->second;
Expand All @@ -49,7 +49,7 @@ const VehiclePlacement &string_id<VehiclePlacement>::obj() const
const auto iter = vplacements.find( *this );
if( iter == vplacements.end() ) {
debugmsg( "invalid vehicle placement id %s", c_str() );
static const VehiclePlacement dummy;
static const VehiclePlacement dummy{};
return dummy;
}
return iter->second;
Expand Down Expand Up @@ -158,7 +158,7 @@ const VehicleSpawn &string_id<VehicleSpawn>::obj() const
const auto iter = vspawns.find( *this );
if( iter == vspawns.end() ) {
debugmsg( "invalid vehicle spawn id %s", c_str() );
static const VehicleSpawn dummy;
static const VehicleSpawn dummy{};
return dummy;
}
return iter->second;
Expand Down
6 changes: 3 additions & 3 deletions src/vehicle_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern std::unordered_map<vgroup_id, VehicleGroup> vgroups;
class VehicleGroup
{
public:
VehicleGroup() {}
VehicleGroup() = default;

void add_vehicle( const vproto_id &type, const int &probability ) {
vehicles.add( type, probability );
Expand Down Expand Up @@ -80,7 +80,7 @@ struct VehicleLocation {
* A list of vehicle locations which are valid for spawning new vehicles.
*/
struct VehiclePlacement {
VehiclePlacement() {}
VehiclePlacement() = default;

void add( const jmapgen_int &x, const jmapgen_int &y, const VehicleFacings &facings ) {
locations.emplace_back( x, y, facings );
Expand Down Expand Up @@ -158,7 +158,7 @@ class VehicleFunction_json : public VehicleFunction
class VehicleSpawn
{
public:
VehicleSpawn() {}
VehicleSpawn() = default;

void add( const double &weight, const std::shared_ptr<VehicleFunction> &func ) {
types.add( func, weight );
Expand Down

0 comments on commit dffa505

Please sign in to comment.