diff --git a/.clang-tidy b/.clang-tidy index 538eff031f715..2e1890ba0e8fd 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -50,12 +50,9 @@ readability-*,\ -bugprone-misplaced-widening-cast,\ -bugprone-narrowing-conversions,\ -bugprone-redundant-branch-condition,\ --bugprone-reserved-identifier,\ -bugprone-signed-char-misuse,\ -bugprone-sizeof-expression,\ -bugprone-unhandled-self-assignment,\ --cert-dcl37-c,\ --cert-dcl51-cpp,\ -cert-oop54-cpp,\ -cert-str34-c,\ -clang-analyzer-core.CallAndMessage,\ diff --git a/src/avatar.h b/src/avatar.h index 87f3c86b13376..4ab5f367a6437 100644 --- a/src/avatar.h +++ b/src/avatar.h @@ -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> new_seen_mon; diff --git a/src/debug.h b/src/debug.h index e7c6e7ce88bea..54e570534f688 100644 --- a/src/debug.h +++ b/src/debug.h @@ -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 /** @@ -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, diff --git a/src/debug_menu.h b/src/debug_menu.h index 4331b0ffdf3d2..a77f3b465aaaa 100644 --- a/src/debug_menu.h +++ b/src/debug_menu.h @@ -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 -_Container string_to_iterable( const std::string &str, const std::string &delimiter ) +template +Container string_to_iterable( const std::string &str, const std::string &delimiter ) { - _Container res; + Container res; size_t pos = 0; size_t start = 0; @@ -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 -std::string iterable_to_string( const _Container &values, const std::string &delimiter, +template +std::string iterable_to_string( const Container &values, const std::string &delimiter, const Mapper &f ) { std::string res; @@ -147,8 +147,8 @@ std::string iterable_to_string( const _Container &values, const std::string &del return res; } -template -std::string iterable_to_string( const _Container &values, const std::string &delimiter ) +template +std::string iterable_to_string( const Container &values, const std::string &delimiter ) { return iterable_to_string( values, delimiter, []( const std::string & f ) { return f; diff --git a/src/magic.h b/src/magic.h index d35ba1e4c95d3..af2d239eb9cb7 100644 --- a/src/magic.h +++ b/src/magic.h @@ -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; diff --git a/src/math_defines.h b/src/math_defines.h index f177677cd4eca..40b2c53f46968 100644 --- a/src/math_defines.h +++ b/src/math_defines.h @@ -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 diff --git a/src/monstergenerator.cpp b/src/monstergenerator.cpp index dc85398df546a..3ec95dfe22ed5 100644 --- a/src/monstergenerator.cpp +++ b/src/monstergenerator.cpp @@ -66,7 +66,7 @@ std::string enum_to_string( 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" ); diff --git a/src/mtype.h b/src/mtype.h index 583f2b8e54137..1cae6a2e48bbb 100644 --- a/src/mtype.h +++ b/src/mtype.h @@ -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 { - 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! diff --git a/src/music.cpp b/src/music.cpp index ed8eb9ed458b1..a6355f6d45822 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -16,7 +16,7 @@ std::string enum_to_string( music::music_id data ) return "sound"; case music::music_id::title: return "title"; - case music::music_id::_LAST: + case music::music_id::LAST: break; } diff --git a/src/music.h b/src/music.h index 2987d953f9100..8ba537f54d0e6 100644 --- a/src/music.h +++ b/src/music.h @@ -11,7 +11,7 @@ enum music_id { instrument, sound, title, - _LAST + LAST }; extern std::map> music_id_list; @@ -32,5 +32,5 @@ void update_music_id_is_empty_flag( std::string data, bool update ); // Use io::string_to_enum( music_id ) to convert a string to music_id. template<> struct enum_traits { - static constexpr music::music_id last = music::music_id::_LAST; + static constexpr music::music_id last = music::music_id::LAST; }; diff --git a/src/npc.h b/src/npc.h index a53a4104741e8..84a7252c3a919 100644 --- a/src/npc.h +++ b/src/npc.h @@ -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; }; diff --git a/src/npctalk_funcs.cpp b/src/npctalk_funcs.cpp index e86c3bcede52d..4428fe47b40b7 100644 --- a/src/npctalk_funcs.cpp +++ b/src/npctalk_funcs.cpp @@ -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 ); } diff --git a/src/output.h b/src/output.h index 023d7afdd3dfc..c08891521110e 100644 --- a/src/output.h +++ b/src/output.h @@ -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 -std::string enumerate_as_string( const _Container &values, +template +std::string enumerate_as_string( const Container &values, enumeration_conjunction conj = enumeration_conjunction::and_ ) { const std::string final_separator = [&]() { @@ -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 -std::string enumerate_as_string( _FIter first, _FIter last, F &&string_for, +template +std::string enumerate_as_string( FIter first, FIter last, F &&string_for, enumeration_conjunction conj = enumeration_conjunction::and_ ) { std::vector values; values.reserve( static_cast( 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 ); diff --git a/src/panels.cpp b/src/panels.cpp index b97d56fa8e1c3..27df28de62966 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -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_npc_needs( "npc_needs" ); +static const string_id behavior_node_t_npc_needs( "npc_needs" ); static const trait_id trait_NOPAIN( "NOPAIN" ); @@ -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) diff --git a/src/proficiency_ui.cpp b/src/proficiency_ui.cpp index 5a3afbab8aa1b..6ed504cf41cbf 100644 --- a/src/proficiency_ui.cpp +++ b/src/proficiency_ui.cpp @@ -25,7 +25,7 @@ using display_prof_deps = std::pair>; -struct _prof_window { +struct prof_window { input_context ctxt; weak_ptr_fast ui; catacurses::window w_border; @@ -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 create_or_get_ui_adaptor(); void filter(); std::vector &get_current_set(); @@ -61,12 +61,12 @@ struct _prof_window { void run(); }; -std::vector &_prof_window::get_current_set() +std::vector &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, @@ -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, {} } ); @@ -156,7 +156,7 @@ void _prof_window::populate_categories() } } -void _prof_window::draw_details() +void prof_window::draw_details() { werase( w_details ); std::vector &cur_set = get_current_set(); @@ -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 &cur_set = get_current_set(); @@ -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 ); @@ -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 ); @@ -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 ); @@ -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 _prof_window::create_or_get_ui_adaptor() +shared_ptr_fast prof_window::create_or_get_ui_adaptor() { shared_ptr_fast current_ui = ui.lock(); if( !current_ui ) { @@ -306,7 +306,7 @@ shared_ptr_fast _prof_window::create_or_get_ui_adaptor() return current_ui; } -void _prof_window::run() +void prof_window::run() { if( !u ) { return; @@ -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(); -} \ No newline at end of file +} diff --git a/src/sounds.cpp b/src/sounds.cpp index 351478f8c4dd9..6e68a93acacbb 100644 --- a/src/sounds.cpp +++ b/src/sounds.cpp @@ -224,7 +224,7 @@ std::string enum_to_string( 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" ); } @@ -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" ); @@ -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: @@ -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; } diff --git a/src/sounds.h b/src/sounds.h index 895354756e16d..def45da834f3b 100644 --- a/src/sounds.h +++ b/src/sounds.h @@ -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. @@ -86,7 +86,7 @@ extern bool sound_enabled; template<> struct enum_traits { - static constexpr sounds::sound_t last = sounds::sound_t::_LAST; + static constexpr sounds::sound_t last = sounds::sound_t::LAST; }; namespace sfx diff --git a/src/submap.h b/src/submap.h index 734bdd56ca744..b815a3f1a9dcc 100644 --- a/src/submap.h +++ b/src/submap.h @@ -50,6 +50,8 @@ struct spawn_point { }; template +// 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 diff --git a/src/translations.h b/src/translations.h index 2f2f6dc53cdf0..0eb79674466ac 100644 --- a/src/translations.h +++ b/src/translations.h @@ -48,6 +48,10 @@ inline const T &translation_argument_identity( const T &t ) } // Note: in case of std::string argument, the result is copied, this is intended (for safety) +// Note that _ triggers reserved identifier warnings, but we suppress all +// three because it's a common use of _ and thus not likely to be a problem in +// practice. +// NOLINTNEXTLINE(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp) #define _( msg ) \ ( ( []( const auto & arg ) { \ static auto cache = detail::get_local_translation_cache( arg ); \ diff --git a/tests/behavior_test.cpp b/tests/behavior_test.cpp index 962612cd42ff0..bfbdee9586eb3 100644 --- a/tests/behavior_test.cpp +++ b/tests/behavior_test.cpp @@ -29,7 +29,7 @@ static const itype_id itype_sandwich_cheese_grilled( "sandwich_cheese_grilled" ) static const itype_id itype_sweater( "sweater" ); static const itype_id itype_water( "water" ); -static const string_id behavior__node_t_npc_needs( "npc_needs" ); +static const string_id behavior_node_t_npc_needs( "npc_needs" ); namespace behavior { @@ -156,7 +156,7 @@ TEST_CASE( "check_npc_behavior_tree", "[npc][behavior]" ) { clear_map(); behavior::tree npc_needs; - npc_needs.add( &behavior__node_t_npc_needs.obj() ); + npc_needs.add( &behavior_node_t_npc_needs.obj() ); npc &test_npc = spawn_npc( { 50, 50 }, "test_talker" ); clear_character( test_npc ); behavior::character_oracle_t oracle( &test_npc ); diff --git a/tests/test_statistics.h b/tests/test_statistics.h index d43b0e103906d..1e9116fc84aa0 100644 --- a/tests/test_statistics.h +++ b/tests/test_statistics.h @@ -44,15 +44,15 @@ class statistics int _n; double _sum; mutable double _error; - const double _Z; - const double _Zsq; + const double Z_; + const double Zsq_; T _max; T _min; std::vector< T > samples; public: explicit statistics( const double Z = Z99_9 ) : _types( 0 ), _n( 0 ), _sum( 0 ), _error( invalid_err ), - _Z( Z ), _Zsq( Z * Z ), _max( std::numeric_limits::min() ), + Z_( Z ), Zsq_( Z * Z ), _max( std::numeric_limits::min() ), _min( std::numeric_limits::max() ) {} void new_type() { @@ -86,13 +86,13 @@ class statistics return _error; } // Implementation of outline from https://measuringu.com/ci-five-steps/ - const double adj_numerator = ( _Zsq / 2 ) + _sum; - const double adj_denominator = _Zsq + _n; + const double adj_numerator = ( Zsq_ / 2 ) + _sum; + const double adj_denominator = Zsq_ + _n; const double adj_proportion = adj_numerator / adj_denominator; const double a = adj_proportion * ( 1.0 - adj_proportion ); const double b = a / adj_denominator; const double c = std::sqrt( b ); - _error = c * _Z; + _error = c * Z_; return _error; } // Standard error is intended to be used with continuous data samples. @@ -108,7 +108,7 @@ class statistics return _error; } const double std_err = stddev() / std::sqrt( _n ); - _error = std_err * _Z; + _error = std_err * Z_; return _error; } diff --git a/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.cpp b/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.cpp index 7d0d7844b39ae..5d53262bd0c3d 100644 --- a/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.cpp +++ b/tools/clang-tidy-plugin/StaticStringIdConstantsCheck.cpp @@ -125,6 +125,15 @@ static std::string GetCanonicalName( const CXXRecordDecl *Type, const StringRef Result.erase( Result.begin(), Result.begin() + anon_prefix.size() ); } + // Remove double underscores since they are reserved identifiers + while( true ) { + size_t double_underscores = Result.find( "__" ); + if( double_underscores == std::string::npos ) { + break; + } + Result.erase( Result.begin() + double_underscores ); + } + return Result; }