Skip to content

Commit

Permalink
Merge pull request #58200 from jbytheway/clang-tidy_reserved-identifier
Browse files Browse the repository at this point in the history
Avoid reserved identifiers
  • Loading branch information
ZhilkinSerg authored Jun 6, 2022
2 parents 754f5bf + 7385a79 commit 14a6293
Show file tree
Hide file tree
Showing 22 changed files with 79 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ readability-*,\
-bugprone-misplaced-widening-cast,\
-bugprone-narrowing-conversions,\
-bugprone-redundant-branch-condition,\
-bugprone-reserved-identifier,\
-bugprone-signed-char-misuse,\
-bugprone-unhandled-self-assignment,\
-cert-dcl37-c,\
-cert-dcl51-cpp,\
-cert-oop54-cpp,\
-cert-str34-c,\
-clang-analyzer-core.CallAndMessage,\
Expand Down
2 changes: 2 additions & 0 deletions src/avatar.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ struct mtype;
enum class pool_type;

// Monster visible in different directions (safe mode & compass)
// Suppressions due to a bug in clang-tidy 12
// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
struct monster_visible_info {
// New monsters visible from last update
std::vector<shared_ptr_fast<monster>> new_seen_mon;
Expand Down
6 changes: 3 additions & 3 deletions src/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
#define STRING(x) STRING2(x)

#if defined(__GNUC__)
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
#define CATA_FUNCTION_NAME __PRETTY_FUNCTION__
#else
#define __FUNCTION_NAME__ __func__
#define CATA_FUNCTION_NAME __func__
#endif

/**
Expand All @@ -66,7 +66,7 @@
* a printf style format string.
*/

#define debugmsg(...) realDebugmsg(__FILE__, STRING(__LINE__), __FUNCTION_NAME__, __VA_ARGS__)
#define debugmsg(...) realDebugmsg(__FILE__, STRING(__LINE__), CATA_FUNCTION_NAME, __VA_ARGS__)

// Don't use this, use debugmsg instead.
void realDebugmsg( const char *filename, const char *line, const char *funcname,
Expand Down
14 changes: 7 additions & 7 deletions src/debug_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,10 @@ void wishproficiency( Character *you );
void debug();

/* Splits a string by @param delimiter and push_back's the elements into _Container */
template<typename _Container>
_Container string_to_iterable( const std::string &str, const std::string &delimiter )
template<typename Container>
Container string_to_iterable( const std::string &str, const std::string &delimiter )
{
_Container res;
Container res;

size_t pos = 0;
size_t start = 0;
Expand All @@ -133,8 +133,8 @@ _Container string_to_iterable( const std::string &str, const std::string &delimi
* @param delimiter between them
* @param f is callable that is called to transform each value
* */
template<typename _Container, typename Mapper>
std::string iterable_to_string( const _Container &values, const std::string &delimiter,
template<typename Container, typename Mapper>
std::string iterable_to_string( const Container &values, const std::string &delimiter,
const Mapper &f )
{
std::string res;
Expand All @@ -147,8 +147,8 @@ std::string iterable_to_string( const _Container &values, const std::string &del
return res;
}

template<typename _Container>
std::string iterable_to_string( const _Container &values, const std::string &delimiter )
template<typename Container>
std::string iterable_to_string( const Container &values, const std::string &delimiter )
{
return iterable_to_string( values, delimiter, []( const std::string & f ) {
return f;
Expand Down
2 changes: 1 addition & 1 deletion src/magic.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class spell_type

requirement_id spell_components;

sounds::sound_t sound_type = sounds::sound_t::_LAST;
sounds::sound_t sound_type = sounds::sound_t::LAST;
bool sound_ambient = false;
std::string sound_id;
std::string sound_variant;
Expand Down
1 change: 1 addition & 0 deletions src/math_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// Note that it's important to use math.h here, not cmath. See
// https://stackoverflow.com/questions/6563810/m-pi-works-with-math-h-but-not-with-cmath-in-visual-studio/6563891

// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
#define _USE_MATH_DEFINES
// NOLINTNEXTLINE(modernize-deprecated-headers)
#include <math.h>
Expand Down
2 changes: 1 addition & 1 deletion src/monstergenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ std::string enum_to_string<mon_trigger>( mon_trigger data )
case mon_trigger::PLAYER_NEAR_BABY: return "PLAYER_NEAR_BABY";
case mon_trigger::MATING_SEASON: return "MATING_SEASON";
// *INDENT-ON*
case mon_trigger::_LAST:
case mon_trigger::LAST:
break;
}
cata_fatal( "Invalid mon_trigger" );
Expand Down
4 changes: 2 additions & 2 deletions src/mtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ enum class mon_trigger : int {
PLAYER_NEAR_BABY, // Player/npc is near a baby monster of this type
MATING_SEASON, // It's the monster's mating season (defined by baby_flags)

_LAST // This item must always remain last.
LAST // This item must always remain last.
};

template<>
struct enum_traits<mon_trigger> {
static constexpr mon_trigger last = mon_trigger::_LAST;
static constexpr mon_trigger last = mon_trigger::LAST;
};

// Feel free to add to m_flags. Order shouldn't matter, just keep it tidy!
Expand Down
2 changes: 1 addition & 1 deletion src/music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::string enum_to_string<music::music_id>( music::music_id data )
return "sound";
case music::music_id::title:
return "title";
case music::music_id::_LAST:
case music::music_id::LAST:
break;
}

Expand Down
4 changes: 2 additions & 2 deletions src/music.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum music_id {
instrument,
sound,
title,
_LAST
LAST
};

extern std::map<music_id, std::pair<bool, bool>> music_id_list;
Expand All @@ -32,5 +32,5 @@ void update_music_id_is_empty_flag( std::string data, bool update );
// Use io::string_to_enum<music_id>( music_id ) to convert a string to music_id.
template<>
struct enum_traits<music::music_id> {
static constexpr music::music_id last = music::music_id::_LAST;
static constexpr music::music_id last = music::music_id::LAST;
};
2 changes: 1 addition & 1 deletion src/npc.h
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ struct npc_follower_rules {

struct dangerous_sound {
tripoint abs_pos;
sounds::sound_t type = sounds::sound_t::_LAST;
sounds::sound_t type = sounds::sound_t::LAST;
int volume = 0;
};

Expand Down
8 changes: 4 additions & 4 deletions src/npctalk_funcs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -979,10 +979,10 @@ void talk_function::player_weapon_drop( npc &/*p*/ )

void talk_function::lead_to_safety( npc &p )
{
mission *reach_safety__mission = mission::reserve_new( mission_MISSION_REACH_SAFETY,
character_id() );
reach_safety__mission->assign( get_avatar() );
p.goal = reach_safety__mission->get_target();
mission *reach_safety_mission = mission::reserve_new( mission_MISSION_REACH_SAFETY,
character_id() );
reach_safety_mission->assign( get_avatar() );
p.goal = reach_safety_mission->get_target();
p.set_attitude( NPCATT_LEAD );
}

Expand Down
10 changes: 5 additions & 5 deletions src/output.h
Original file line number Diff line number Diff line change
Expand Up @@ -705,8 +705,8 @@ enum class enumeration_conjunction : int {
* @param values A vector of strings
* @param conj Choose how to separate the last elements.
*/
template<typename _Container>
std::string enumerate_as_string( const _Container &values,
template<typename Container>
std::string enumerate_as_string( const Container &values,
enumeration_conjunction conj = enumeration_conjunction::and_ )
{
const std::string final_separator = [&]() {
Expand Down Expand Up @@ -755,13 +755,13 @@ std::string enumerate_as_string( const _Container &values,
* May return an empty string to omit the element.
* @param conj Choose how to separate the last elements.
*/
template<typename _FIter, typename F>
std::string enumerate_as_string( _FIter first, _FIter last, F &&string_for,
template<typename FIter, typename F>
std::string enumerate_as_string( FIter first, FIter last, F &&string_for,
enumeration_conjunction conj = enumeration_conjunction::and_ )
{
std::vector<std::string> values;
values.reserve( static_cast<size_t>( std::distance( first, last ) ) );
for( _FIter iter = first; iter != last; ++iter ) {
for( FIter iter = first; iter != last; ++iter ) {
const std::string str( string_for( *iter ) );
if( !str.empty() ) {
values.push_back( str );
Expand Down
4 changes: 2 additions & 2 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static const efftype_id effect_mending( "mending" );
static const flag_id json_flag_SPLINT( "SPLINT" );
static const flag_id json_flag_THERMOMETER( "THERMOMETER" );

static const string_id<behavior::node_t> behavior__node_t_npc_needs( "npc_needs" );
static const string_id<behavior::node_t> behavior_node_t_npc_needs( "npc_needs" );

static const trait_id trait_NOPAIN( "NOPAIN" );

Expand Down Expand Up @@ -1453,7 +1453,7 @@ static void draw_ai_goal( const draw_args &args )

werase( w );
behavior::tree needs;
needs.add( &behavior__node_t_npc_needs.obj() );
needs.add( &behavior_node_t_npc_needs.obj() );
behavior::character_oracle_t player_oracle( &u );
std::string current_need = needs.tick( &player_oracle );
// NOLINTNEXTLINE(cata-use-named-point-constants)
Expand Down
34 changes: 17 additions & 17 deletions src/proficiency_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using display_prof_deps = std::pair<display_proficiency, std::vector<proficiency_id>>;

struct _prof_window {
struct prof_window {
input_context ctxt;
weak_ptr_fast<ui_adaptor> ui;
catacurses::window w_border;
Expand All @@ -45,10 +45,10 @@ struct _prof_window {
int top_prof = 0;
int current_cat = 0;

_prof_window() = delete;
_prof_window( _prof_window & ) = delete;
_prof_window( _prof_window && ) = delete;
explicit _prof_window( const Character *u ) : u( u ) {}
prof_window() = delete;
prof_window( prof_window & ) = delete;
prof_window( prof_window && ) = delete;
explicit prof_window( const Character *u ) : u( u ) {}
shared_ptr_fast<ui_adaptor> create_or_get_ui_adaptor();
void filter();
std::vector<display_prof_deps *> &get_current_set();
Expand All @@ -61,12 +61,12 @@ struct _prof_window {
void run();
};

std::vector<display_prof_deps *> &_prof_window::get_current_set()
std::vector<display_prof_deps *> &prof_window::get_current_set()
{
return filter_str.empty() ? profs_by_cat[current_cat] : filtered_profs;
}

void _prof_window::filter()
void prof_window::filter()
{
enum class _prof_filter_prefix {
LEARNED,
Expand Down Expand Up @@ -126,7 +126,7 @@ void _prof_window::filter()
}
}

void _prof_window::populate_categories()
void prof_window::populate_categories()
{
for( display_proficiency &p : u->display_proficiencies() ) {
all_profs.push_back( { p, {} } );
Expand Down Expand Up @@ -156,7 +156,7 @@ void _prof_window::populate_categories()
}
}

void _prof_window::draw_details()
void prof_window::draw_details()
{
werase( w_details );
std::vector<display_prof_deps *> &cur_set = get_current_set();
Expand Down Expand Up @@ -203,7 +203,7 @@ void _prof_window::draw_details()
wnoutrefresh( w_details );
}

void _prof_window::draw_profs()
void prof_window::draw_profs()
{
werase( w_profs );
std::vector<display_prof_deps *> &cur_set = get_current_set();
Expand All @@ -219,7 +219,7 @@ void _prof_window::draw_profs()
wnoutrefresh( w_profs );
}

void _prof_window::draw_header()
void prof_window::draw_header()
{
const int w = catacurses::getmaxx( w_header );
werase( w_header );
Expand All @@ -240,7 +240,7 @@ void _prof_window::draw_header()
wnoutrefresh( w_header );
}

void _prof_window::draw_borders()
void prof_window::draw_borders()
{
const int w = catacurses::getmaxx( w_border );
const int h = catacurses::getmaxy( w_border );
Expand Down Expand Up @@ -270,7 +270,7 @@ void _prof_window::draw_borders()
wnoutrefresh( w_border );
}

void _prof_window::init_ui_windows()
void prof_window::init_ui_windows()
{
const int h = std::min( 28, TERMY );
const int w = std::min( 120, TERMX );
Expand All @@ -286,7 +286,7 @@ void _prof_window::init_ui_windows()
w_details = catacurses::newwin( max_rows, column_width, origin + point( center + 1, 5 ) );
}

shared_ptr_fast<ui_adaptor> _prof_window::create_or_get_ui_adaptor()
shared_ptr_fast<ui_adaptor> prof_window::create_or_get_ui_adaptor()
{
shared_ptr_fast<ui_adaptor> current_ui = ui.lock();
if( !current_ui ) {
Expand All @@ -306,7 +306,7 @@ shared_ptr_fast<ui_adaptor> _prof_window::create_or_get_ui_adaptor()
return current_ui;
}

void _prof_window::run()
void prof_window::run()
{
if( !u ) {
return;
Expand Down Expand Up @@ -406,6 +406,6 @@ void _prof_window::run()

void show_proficiencies_window( const Character &u )
{
_prof_window w( &u );
prof_window w( &u );
w.run();
}
}
8 changes: 4 additions & 4 deletions src/sounds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ std::string enum_to_string<sounds::sound_t>( sounds::sound_t data )
case sounds::sound_t::combat: return "combat";
case sounds::sound_t::alert: return "alert";
case sounds::sound_t::order: return "order";
case sounds::sound_t::_LAST: break;
case sounds::sound_t::LAST: break;
}
cata_fatal( "Invalid valid_target" );
}
Expand Down Expand Up @@ -296,7 +296,7 @@ static bool is_provocative( sounds::sound_t category )
case sounds::sound_t::alert:
case sounds::sound_t::order:
return true;
case sounds::sound_t::_LAST:
case sounds::sound_t::LAST:
break;
}
cata_fatal( "Invalid sound_t category" );
Expand Down Expand Up @@ -487,7 +487,7 @@ static bool describe_sound( sounds::sound_t category, bool from_player_position
{
if( from_player_position ) {
switch( category ) {
case sounds::sound_t::_LAST:
case sounds::sound_t::LAST:
debugmsg( "ERROR: Incorrect sound category" );
return false;
case sounds::sound_t::background:
Expand Down Expand Up @@ -522,7 +522,7 @@ static bool describe_sound( sounds::sound_t category, bool from_player_position
case sounds::sound_t::alert:
case sounds::sound_t::order:
return true;
case sounds::sound_t::_LAST:
case sounds::sound_t::LAST:
debugmsg( "ERROR: Incorrect sound category" );
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/sounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ enum class sound_t : int {
combat, // any violent sounding activity
alert, // louder than speech to get attention
order, // loudest to get attention
_LAST // must always be last
LAST // must always be last
};

// Methods for recording sound events.
Expand Down Expand Up @@ -86,7 +86,7 @@ extern bool sound_enabled;

template<>
struct enum_traits<sounds::sound_t> {
static constexpr sounds::sound_t last = sounds::sound_t::_LAST;
static constexpr sounds::sound_t last = sounds::sound_t::LAST;
};

namespace sfx
Expand Down
2 changes: 2 additions & 0 deletions src/submap.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct spawn_point {
};

template<int sx, int sy>
// Suppression due to bug in clang-tidy 12
// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
struct maptile_soa {
ter_id ter[sx][sy]; // Terrain on each square
furn_id frn[sx][sy]; // Furniture on each square
Expand Down
Loading

0 comments on commit 14a6293

Please sign in to comment.