Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply Clang-Tidy and VS static analysis suggestions. #78957

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ bool string_id<achievement>::is_valid() const
return achievement_factory.is_valid( *this );
}

enum class requirement_visibility : int {
enum class requirement_visibility : std::uint8_t {
always,
when_requirement_completed,
when_achievement_completed,
Expand Down Expand Up @@ -550,7 +550,7 @@ class requirement_watcher : stat_watcher

void new_value( const cata_variant &new_value, stats_tracker & ) override;

bool is_satisfied( stats_tracker &/*stats*/ ) {
bool is_satisfied( stats_tracker &/*stats*/ ) const {
return requirement_->satisfied_by( current_value_ );
}

Expand Down
6 changes: 3 additions & 3 deletions src/achievement.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class event;
class requirement_watcher;
class stats_tracker;

enum class achievement_comparison : int {
enum class achievement_comparison : std::uint8_t {
equal,
less_equal,
greater_equal,
Expand All @@ -46,7 +46,7 @@ struct enum_traits<achievement_comparison> {
static constexpr achievement_comparison last = achievement_comparison::last;
};

enum class achievement_completion : int {
enum class achievement_completion : std::uint8_t {
pending,
completed,
failed,
Expand Down Expand Up @@ -94,7 +94,7 @@ class achievement
class time_bound
{
public:
enum class epoch : int {
enum class epoch : std::uint8_t {
cataclysm,
game_start,
last
Expand Down
2 changes: 1 addition & 1 deletion src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ std::string press_x( action_id act, const std::string &act_desc );
std::optional<std::string> press_x_if_bound( action_id act );

// only has effect in iso mode
enum class iso_rotate : int {
enum class iso_rotate : std::uint8_t {
no,
yes
};
Expand Down
2 changes: 1 addition & 1 deletion src/active_item_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct item_reference {
bool has_watertight_container() const;
};

enum class special_item_type : int {
enum class special_item_type : std::uint8_t {
none,
corpse,
explosive
Expand Down
10 changes: 5 additions & 5 deletions src/activity_actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,14 +818,14 @@ void hacking_activity_actor::start( player_activity &act, Character & )
act.moves_left = to_moves<int>( 5_minutes );
}

enum class hack_result : int {
enum class hack_result : std::uint8_t {
UNABLE,
FAIL,
NOTHING,
SUCCESS
};

enum class hack_type : int {
enum class hack_type : std::uint8_t {
SAFE,
DOOR,
GAS,
Expand Down Expand Up @@ -4166,7 +4166,7 @@ static void debug_drop_list( const std::vector<drop_or_stash_item_info> &items )

std::string res( "Items ordered to drop:\n" );
for( const drop_or_stash_item_info &it : items ) {
item_location loc = it.loc();
const item_location &loc = it.loc();
if( !loc ) {
// some items could have been destroyed by e.g. monster attack
continue;
Expand Down Expand Up @@ -5730,7 +5730,7 @@ void outfit_swap_actor::finish( player_activity &act, Character &who )
// Taken-off items are put in this temporary list, then naturally deleted from the world when the function returns.
std::list<item> it_list;
for( item_location &worn_item : who.get_visible_worn_items() ) {
item outfit_component( *worn_item );
const item &outfit_component( *worn_item );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this safe? does taking off the worn item not invalidate the item location and then invalidate the outfit component?

if( who.takeoff( worn_item, &it_list ) ) {
ground->force_insert_item( outfit_component, pocket_type::CONTAINER );
}
Expand Down Expand Up @@ -7220,7 +7220,7 @@ static void move_item( Character &you, item &it, const int quantity, const tripo

void unload_loot_activity_actor::do_turn( player_activity &act, Character &you )
{
enum activity_stage : int {
enum activity_stage : std::uint8_t {
//Initial stage
INIT = 0,
//Think about what to do first: choose destination
Expand Down
2 changes: 1 addition & 1 deletion src/activity_actor_definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class bikerack_unracking_activity_actor : public activity_actor
class read_activity_actor : public activity_actor
{
public:
enum class book_type : int { normal, martial_art };
enum class book_type : std::uint8_t { normal, martial_art };

read_activity_actor() = default;

Expand Down
2 changes: 1 addition & 1 deletion src/activity_handlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3105,7 +3105,7 @@ void activity_handlers::operation_do_turn( player_activity *act, Character *you
- str_values[2]: installer_name
- str_values[3]: bool autodoc
*/
enum operation_values_ids {
enum operation_values_ids : std::uint8_t {
operation_type = 0,
cbm_id = 1,
installer_name = 2,
Expand Down
8 changes: 4 additions & 4 deletions src/activity_handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ std::vector<Point> get_sorted_tiles_by_distance( const Point &center, const Cont

std::vector<tripoint_bub_ms> route_adjacent( const Character &you, const tripoint_bub_ms &dest );

enum class requirement_check_result : int {
enum class requirement_check_result : std::uint8_t {
SKIP_LOCATION = 0,
SKIP_LOCATION_NO_ZONE, // Zone activity but no zone found
SKIP_LOCATION_NO_SKILL, // Insufficient npc skill for task.
Expand All @@ -51,7 +51,7 @@ enum class requirement_check_result : int {
RETURN_EARLY //another activity like a fetch activity has been started.
};

enum class butcher_type : int {
enum class butcher_type : std::uint8_t {
BLEED, // bleeding a corpse
QUICK, // quick butchery
FULL, // full workshop butchery
Expand All @@ -63,7 +63,7 @@ enum class butcher_type : int {
NUM_TYPES // always keep at the end, number of butchery types
};

enum class do_activity_reason : int {
enum class do_activity_reason : std::uint8_t {
CAN_DO_CONSTRUCTION, // Can do construction.
CAN_DO_FETCH, // Can do fetch - this is usually the default result for fetch task
NO_COMPONENTS, // can't do the activity there due to lack of components /tools
Expand Down Expand Up @@ -176,7 +176,7 @@ int get_auto_consume_moves( Character &you, bool food );
bool try_fuel_fire( player_activity &act, Character &you, bool starting_fire = false );
double butcher_get_progress( const item &corpse_item, butcher_type action );

enum class item_drop_reason : int {
enum class item_drop_reason : std::uint8_t {
deliberate,
too_large,
too_heavy,
Expand Down
2 changes: 1 addition & 1 deletion src/activity_item_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ static bool chop_plank_activity( Character &you, const tripoint_bub_ms &src_loc

void activity_on_turn_move_loot( player_activity &act, Character &you )
{
enum activity_stage : int {
enum activity_stage : std::uint8_t {
//Initial stage
INIT = 0,
//Think about what to do first: choose destination
Expand Down
2 changes: 1 addition & 1 deletion src/activity_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ using activity_id = string_id<activity_type>;
template<>
const activity_type &string_id<activity_type>::obj() const;

enum class based_on_type : int {
enum class based_on_type : std::uint8_t {
TIME = 0,
SPEED,
NEITHER,
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class advanced_inventory
/**
* Refers to the two panes, used as index into @ref panes.
*/
enum side {
enum side : std::uint8_t {
left = 0,
right = 1,
NUM_PANES = 2
Expand Down
2 changes: 1 addition & 1 deletion src/advanced_inv_pane.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct advanced_inv_pane_save_state;

enum aim_location : char;

enum advanced_inv_sortby {
enum advanced_inv_sortby : std::uint8_t {
SORTBY_NONE,
SORTBY_NAME,
SORTBY_WEIGHT,
Expand Down
2 changes: 1 addition & 1 deletion src/animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "color.h"

enum explosion_neighbors {
enum explosion_neighbors : std::uint8_t {
N_NO_NEIGHBORS = 0,
N_NORTH = 1,

Expand Down
2 changes: 1 addition & 1 deletion src/avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void avatar::on_mission_finished( mission &cur_mission )
}
}

bool avatar::has_mission_id( const mission_type_id &miss_id )
bool avatar::has_mission_id( const mission_type_id &miss_id ) const
{
for( mission *miss : active_missions ) {
if( miss->mission_id() == miss_id ) {
Expand Down
4 changes: 2 additions & 2 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespace debug_menu
{
class mission_debug;
} // namespace debug_menu
enum class pool_type;
enum class pool_type : std::uint8_t;

// Monster visible in different directions (safe mode & compass)
// Suppressions due to a bug in clang-tidy 12
Expand Down Expand Up @@ -190,7 +190,7 @@ class avatar : public Character
/**
* Returns true if character has the mission in their active missions list.
*/
bool has_mission_id( const mission_type_id &miss_id );
bool has_mission_id( const mission_type_id &miss_id ) const;

void remove_active_mission( mission &cur_mission );

Expand Down
6 changes: 3 additions & 3 deletions src/basecamp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ std::vector<npc_ptr> basecamp::get_npcs_assigned()
return assigned_npcs;
}

void basecamp::hide_mission( ui_mission_id id )
void basecamp::hide_mission( const ui_mission_id &id )
{
const base_camps::direction_data &base_data = base_camps::all_directions.at( id.id.dir.value() );
for( ui_mission_id &miss_id : hidden_missions[size_t( base_data.tab_order )] ) {
Expand All @@ -616,7 +616,7 @@ void basecamp::hide_mission( ui_mission_id id )
hidden_missions[size_t( base_data.tab_order )].push_back( id );
}

void basecamp::reveal_mission( ui_mission_id id )
void basecamp::reveal_mission( const ui_mission_id &id )
{
const base_camps::direction_data &base_data = base_camps::all_directions.at( id.id.dir.value() );
for( auto it = hidden_missions[size_t( base_data.tab_order )].begin();
Expand All @@ -629,7 +629,7 @@ void basecamp::reveal_mission( ui_mission_id id )
debugmsg( "Trying to reveal revealed mission. Has no effect." );
}

bool basecamp::is_hidden( ui_mission_id id )
bool basecamp::is_hidden( const ui_mission_id &id )
{
if( hidden_missions.empty() ) {
return false;
Expand Down
10 changes: 5 additions & 5 deletions src/basecamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class recipe;
class time_duration;
class zone_data;
struct MonsterGroupResult;
enum class farm_ops;
enum class farm_ops : std::uint8_t;

using faction_id = string_id<faction>;

Expand Down Expand Up @@ -72,7 +72,7 @@ class window;
namespace base_camps
{

enum tab_mode : int {
enum tab_mode : std::uint8_t {
TAB_MAIN,
TAB_N,
TAB_NE,
Expand Down Expand Up @@ -472,9 +472,9 @@ class basecamp
void add_assignee( character_id id );
void remove_assignee( character_id id );
std::vector<npc_ptr> get_npcs_assigned();
void hide_mission( ui_mission_id id );
void reveal_mission( ui_mission_id id );
bool is_hidden( ui_mission_id id );
void hide_mission( const ui_mission_id &id );
void reveal_mission( const ui_mission_id &id );
bool is_hidden( const ui_mission_id &id );
// Save/load
void serialize( JsonOut &json ) const;
void deserialize( const JsonObject &data );
Expand Down
4 changes: 2 additions & 2 deletions src/bionics_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ bionic_chars( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"#&()*+./:;@

namespace
{
enum bionic_tab_mode {
enum bionic_tab_mode : std::uint8_t {
TAB_ACTIVE,
TAB_PASSIVE
};
enum bionic_menu_mode {
enum bionic_menu_mode : std::uint8_t {
ACTIVATING,
EXAMINING,
REASSIGNING
Expand Down
8 changes: 4 additions & 4 deletions src/bodypart.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extern const bodypart_str_id body_part_foot_r;
extern const sub_bodypart_str_id sub_body_part_sub_limb_debug;

// The order is important ; pldata.h has to be in the same order
enum body_part : int {
enum body_part : std::uint8_t {
bp_torso = 0,
bp_head,
bp_eyes,
Expand All @@ -69,10 +69,10 @@ struct enum_traits<body_part> {
static constexpr body_part last = body_part::num_bp;
};

enum class side : int;
enum class side : std::uint8_t;

// Drench cache
enum water_tolerance {
enum water_tolerance : std::uint8_t {
WT_IGNORED = 0,
WT_NEUTRAL,
WT_GOOD,
Expand Down Expand Up @@ -176,7 +176,7 @@ struct body_part_type {
* the different types of body parts there are.
* this allows for the ability to group limbs or determine a limb of a certain type
*/
enum class type {
enum class type : std::uint8_t {
// this is where helmets go, and is a vital part.
head,
// the torso is generally the center of mass of a creature
Expand Down
4 changes: 2 additions & 2 deletions src/bonuses.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Character;
class JsonArray;
class JsonObject;

enum scaling_stat : int {
enum scaling_stat : std::uint8_t {
STAT_NULL = 0,
STAT_STR,
STAT_DEX,
Expand All @@ -39,7 +39,7 @@ enum scaling_stat : int {
NUM_STATS
};

enum class affected_stat : int {
enum class affected_stat : std::uint8_t {
NONE = 0,
HIT,
CRITICAL_HIT_CHANCE,
Expand Down
2 changes: 1 addition & 1 deletion src/butchery_requirements.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
class JsonObject;
class read_only_visitable;

enum class butcher_type : int;
enum class butcher_type : std::uint8_t;
enum class creature_size : int;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/cached_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ extern std::vector<std::string> damage_indicators;
// test_mode is not a regular game option; it's true when we are running unit
// tests.
extern bool test_mode;
enum class test_mode_spilling_action_t {
enum class test_mode_spilling_action_t : std::uint8_t {
spill_all,
cancel_spill,
};
extern test_mode_spilling_action_t test_mode_spilling_action;

extern bool direct3d_mode;

enum class error_log_format_t {
enum class error_log_format_t : std::uint8_t {
human_readable,
// Output error messages in github action command format (currently json only)
// See https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
Expand All @@ -59,7 +59,7 @@ extern error_log_format_t error_log_format;
constexpr error_log_format_t error_log_format = error_log_format_t::human_readable;
#endif

enum class check_plural_t {
enum class check_plural_t : std::uint8_t {
none,
certain, // report strings that certainly have a non-regular plural form, such as those ending in "s"
possible, // report strings that may or may not have a non-regular plural form, such as those containing the word "of"
Expand Down
Loading
Loading