Enable clang-tidy check modernize-avoid-c-arrays (#60191)

* Enable clang-tidy check modernize-avoid-c-arrays

Convert various arrays to std::array

* Fix more array warnings

These issues were found in CI due to it compiling with different
features than me.

* Don't us sizeof( std::array )

It's clearer to use .size().
This commit is contained in:
John Bytheway 2022-09-02 20:15:39 -04:00 committed by GitHub
parent c968cf18e8
commit 66746d1e9c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 425 additions and 366 deletions

View File

@ -49,7 +49,6 @@ readability-*,\
-bugprone-narrowing-conversions,\
-misc-no-recursion,\
-misc-non-private-member-variables-in-classes,\
-modernize-avoid-c-arrays,\
-modernize-pass-by-value,\
-modernize-return-braced-init-list,\
-modernize-use-default-member-init,\

View File

@ -5523,7 +5523,10 @@ void chop_tree_activity_actor::finish( player_activity &act, Character &who )
creature_tracker &creatures = get_creature_tracker();
const point main_dir = pos.xy() - who.pos().xy();
const int circle_size = 8;
const point circle[circle_size] = { point_east, point_south_east, point_south, point_south_west, point_west, point_north_west, point_north, point_north_east };
static constexpr std::array<point, circle_size> circle = {
point_east, point_south_east, point_south, point_south_west, point_west,
point_north_west, point_north, point_north_east
};
int circle_center = 0; // Initialized as the compiler complained
for( int i = 0; i < circle_size; i++ ) {
if( main_dir == circle[i] ) {

View File

@ -1070,7 +1070,7 @@ void avatar::reset_stats()
}
// Spider hair is basically a full-body set of whiskers, once you get the brain for it
if( has_trait( trait_CHITIN_FUR3 ) ) {
static const bodypart_str_id parts[] {
static const std::array<bodypart_str_id, 5> parts {
body_part_head, body_part_arm_r, body_part_arm_l,
body_part_leg_r, body_part_leg_l
};

View File

@ -62,11 +62,11 @@ struct monster_visible_info {
// 7 0 1 unique_types uses these indices;
// 6 8 2 0-7 are provide by direction_from()
// 5 4 3 8 is used for local monsters (for when we explain them below)
std::vector<npc *> unique_types[9];
std::vector<std::pair<const mtype *, int>> unique_mons[9];
std::array<std::vector<npc *>, 9> unique_types;
std::array<std::vector<std::pair<const mtype *, int>>, 9> unique_mons;
// If the monster visible in this direction is dangerous
bool dangerous[8] = {};
std::array<bool, 8> dangerous = {};
};
class avatar : public Character

View File

@ -292,7 +292,7 @@ tile_type &tileset::create_tile_type( const std::string &id, tile_type &&new_til
// populate cache by season
constexpr size_t suffix_len = 15;
// NOLINTNEXTLINE(cata-use-mdarray)
// NOLINTNEXTLINE(cata-use-mdarray,modernize-avoid-c-arrays)
constexpr char season_suffix[NUM_SEASONS][suffix_len] = {
"_season_spring", "_season_summer", "_season_autumn", "_season_winter"
};
@ -1197,11 +1197,10 @@ struct tile_render_info {
// accumulator for 3d tallness of sprites rendered here so far;
int height_3d = 0;
lit_level ll;
bool invisible[5];
std::array<bool, 5> invisible;
tile_render_info( const tripoint &pos, const int height_3d, const lit_level ll,
const bool( &invisible )[5] )
: pos( pos ), height_3d( height_3d ), ll( ll ) {
std::copy_n( invisible, 5, this->invisible );
const std::array<bool, 5> &inv )
: pos( pos ), height_3d( height_3d ), ll( ll ), invisible( inv ) {
}
};
@ -1375,7 +1374,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
lit_level ll;
// invisible to normal eyes
bool invisible[5];
std::array<bool, 5> invisible;
invisible[0] = false;
if( y < min_visible.y || y > max_visible.y || x < min_visible.x || x > max_visible.x ) {
@ -1659,7 +1658,7 @@ void cata_tiles::draw( const point &dest, const tripoint &center, int width, int
continue;
}
int height_3d = 0;
bool invisible[5];
std::array<bool, 5> invisible;
invisible[0] = false;
for( int i = 0; i < 4; i++ ) {
const tripoint np = p + neighborhood[i];
@ -2623,7 +2622,7 @@ bool cata_tiles::apply_vision_effects( const tripoint &pos,
}
bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
map &here = get_map();
const auto low_override = draw_below_override.find( p );
@ -2689,7 +2688,7 @@ bool cata_tiles::draw_terrain_below( const tripoint &p, const lit_level, int &,
}
bool cata_tiles::draw_terrain( const tripoint &p, const lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
map &here = get_map();
const auto override = terrain_override.find( p );
@ -2866,7 +2865,7 @@ memorized_terrain_tile cata_tiles::get_vpart_memory_at( const tripoint &p ) cons
}
bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
avatar &you = get_avatar();
const auto override = furniture_override.find( p );
@ -2884,7 +2883,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
// first memorize the actual furniture
const furn_id &f = here.furn( p );
if( f && !invisible[0] ) {
const int neighborhood[4] = {
const std::array<int, 4> neighborhood = {
static_cast<int>( here.furn( p + point_south ) ),
static_cast<int>( here.furn( p + point_east ) ),
static_cast<int>( here.furn( p + point_west ) ),
@ -2921,7 +2920,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
return it != furniture_override.end() ? it->second :
( !overridden || !invis ) ? here.furn( q ) : f_null;
};
const int neighborhood[4] = {
const std::array<int, 4> neighborhood = {
static_cast<int>( furn( p + point_south, invisible[1] ) ),
static_cast<int>( furn( p + point_east, invisible[2] ) ),
static_cast<int>( furn( p + point_west, invisible[3] ) ),
@ -2955,7 +2954,7 @@ bool cata_tiles::draw_furniture( const tripoint &p, const lit_level ll, int &hei
}
bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
const auto override = trap_override.find( p );
const bool overridden = override != trap_override.end();
@ -2974,7 +2973,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3
// first memorize the actual trap
const trap &tr = here.tr_at( p );
if( !tr.is_null() && !invisible[0] && tr.can_see( p, you ) ) {
const int neighborhood[4] = {
const std::array<int, 4> neighborhood = {
static_cast<int>( here.tr_at( p + point_south ).loadid ),
static_cast<int>( here.tr_at( p + point_east ).loadid ),
static_cast<int>( here.tr_at( p + point_west ).loadid ),
@ -3005,7 +3004,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3
return it != trap_override.end() ? it->second :
( !overridden || !invis ) ? here.tr_at( q ).loadid : tr_null;
};
const int neighborhood[4] = {
const std::array<int, 4> neighborhood = {
static_cast<int>( tr_at( p + point_south, invisible[1] ) ),
static_cast<int>( tr_at( p + point_east, invisible[2] ) ),
static_cast<int>( tr_at( p + point_west, invisible[3] ) ),
@ -3033,7 +3032,7 @@ bool cata_tiles::draw_trap( const tripoint &p, const lit_level ll, int &height_3
}
bool cata_tiles::draw_graffiti( const tripoint &p, const lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
const auto override = graffiti_override.find( p );
const bool overridden = override != graffiti_override.end();
@ -3046,7 +3045,7 @@ bool cata_tiles::draw_graffiti( const tripoint &p, const lit_level ll, int &heig
}
bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
const auto fld_override = field_override.find( p );
const bool fld_overridden = fld_override != field_override.end();
@ -3079,11 +3078,12 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int
( !fld_overridden || !invis ) ? found : fd_null;
};
// for rotation information
const int neighborhood[4] = {
static_cast<int>( has_field( fld, p + point_south, invisible[1] ) ),
static_cast<int>( has_field( fld, p + point_east, invisible[2] ) ),
static_cast<int>( has_field( fld, p + point_west, invisible[3] ) ),
static_cast<int>( has_field( fld, p + point_north, invisible[4] ) )
const std::array<int, 4> neighborhood = { {
static_cast<int>( has_field( fld, p + point_south, invisible[1] ) ),
static_cast<int>( has_field( fld, p + point_east, invisible[2] ) ),
static_cast<int>( has_field( fld, p + point_west, invisible[3] ) ),
static_cast<int>( has_field( fld, p + point_north, invisible[4] ) )
}
};
@ -3178,7 +3178,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int
( !fld_overridden || !invis ) ? here.field_at( q ).displayed_field_type() : fd_null;
};
// for rotation information
const int neighborhood[4] = {
const std::array<int, 4> neighborhood = {
static_cast<int>( field_at( p + point_south, invisible[1] ) ),
static_cast<int>( field_at( p + point_east, invisible[2] ) ),
static_cast<int>( field_at( p + point_west, invisible[3] ) ),
@ -3347,7 +3347,7 @@ bool cata_tiles::draw_field_or_item( const tripoint &p, const lit_level ll, int
}
bool cata_tiles::draw_vpart_below( const tripoint &p, const lit_level /*ll*/, int &/*height_3d*/,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
const auto low_override = draw_below_override.find( p );
const bool low_overridden = low_override != draw_below_override.end();
@ -3357,13 +3357,13 @@ bool cata_tiles::draw_vpart_below( const tripoint &p, const lit_level /*ll*/, in
}
tripoint pbelow( p.xy(), p.z - 1 );
int height_3d_below = 0;
bool below_invisible[5];
std::fill_n( below_invisible, 5, false );
std::array<bool, 5> below_invisible;
std::fill( below_invisible.begin(), below_invisible.end(), false );
return draw_vpart( pbelow, lit_level::LOW, height_3d_below, below_invisible );
}
bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
const auto override = vpart_override.find( p );
const bool overridden = override != vpart_override.end();
@ -3431,7 +3431,7 @@ bool cata_tiles::draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
}
bool cata_tiles::draw_critter_at_below( const tripoint &p, const lit_level, int &,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
// Check if we even need to draw below. If not, bail.
const auto low_override = draw_below_override.find( p );
@ -3486,7 +3486,7 @@ bool cata_tiles::draw_critter_at_below( const tripoint &p, const lit_level, int
}
bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
bool result;
bool is_player;
@ -3607,7 +3607,7 @@ bool cata_tiles::draw_critter_at( const tripoint &p, lit_level ll, int &height_3
}
bool cata_tiles::draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] )
const std::array<bool, 5> &invisible )
{
if( invisible[0] ) {
return false;
@ -3634,7 +3634,7 @@ bool cata_tiles::draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d
}
bool cata_tiles::draw_zombie_revival_indicators( const tripoint &pos, const lit_level /*ll*/,
int &/*height_3d*/, const bool ( &invisible )[5] )
int &/*height_3d*/, const std::array<bool, 5> &invisible )
{
map &here = get_map();
if( tileset_ptr->find_tile_type( ZOMBIE_REVIVAL_INDICATOR ) && !invisible[0] &&
@ -4229,7 +4229,7 @@ void cata_tiles::init_light()
}
void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &subtile,
const std::map<tripoint, ter_id> &ter_override, const bool ( &invisible )[5] )
const std::map<tripoint, ter_id> &ter_override, const std::array<bool, 5> &invisible )
{
map &here = get_map();
const bool overridden = ter_override.find( p ) != ter_override.end();
@ -4248,7 +4248,7 @@ void cata_tiles::get_terrain_orientation( const tripoint &p, int &rota, int &sub
}
// get terrain neighborhood
const ter_id neighborhood[4] = {
const std::array<ter_id, 4> neighborhood = {
ter( p + point_south, invisible[1] ),
ter( p + point_east, invisible[2] ),
ter( p + point_west, invisible[3] ),
@ -4359,9 +4359,10 @@ void cata_tiles::get_furn_connect_values( const tripoint &p, int &subtile, int &
get_rotation_and_subtile( connections, rotation, subtile );
}
void cata_tiles::get_tile_values( const int t, const int *tn, int &subtile, int &rotation )
void cata_tiles::get_tile_values( const int t, const std::array<int, 4> &tn, int &subtile,
int &rotation )
{
bool connects[4];
std::array<bool, 4> connects;
char val = 0;
for( int i = 0; i < 4; ++i ) {
connects[i] = ( tn[i] == t );
@ -4372,8 +4373,8 @@ void cata_tiles::get_tile_values( const int t, const int *tn, int &subtile, int
get_rotation_and_subtile( val, rotation, subtile );
}
void cata_tiles::get_tile_values_with_ter( const tripoint &p, const int t, const int *tn,
int &subtile, int &rotation )
void cata_tiles::get_tile_values_with_ter(
const tripoint &p, const int t, const std::array<int, 4> &tn, int &subtile, int &rotation )
{
map &here = get_map();
//check if furniture should connect to itself

View File

@ -146,7 +146,8 @@ class tileset
std::unordered_map<std::string, tile_type> tile_ids;
// caches both "default" and "_season_XXX" tile variants (to reduce the number of lookups)
// either variant can be either a `nullptr` or a pointer/reference to the real value (stored inside `tile_ids`)
std::unordered_map<std::string, season_tile_value> tile_ids_by_season[season_type::NUM_SEASONS];
std::array<std::unordered_map<std::string, season_tile_value>, season_type::NUM_SEASONS>
tile_ids_by_season;
static const texture *get_if_available( const size_t index,
@ -432,10 +433,10 @@ class cata_tiles
lit_level ll, bool apply_night_vision_goggles, int &height_3d );
/* Tile Picking */
void get_tile_values( int t, const int *tn, int &subtile, int &rotation );
void get_tile_values( int t, const std::array<int, 4> &tn, int &subtile, int &rotation );
// as get_tile_values, but for unconnected tiles, infer rotation from surrounding walls
void get_tile_values_with_ter( const tripoint &p, int t, const int *tn, int &subtile,
int &rotation );
void get_tile_values_with_ter( const tripoint &p, int t, const std::array<int, 4> &tn,
int &subtile, int &rotation );
void get_connect_values( const tripoint &p, int &subtile, int &rotation, int connect_group,
const std::map<tripoint, ter_id> &ter_override );
void get_furn_connect_values( const tripoint &p, int &subtile, int &rotation,
@ -443,7 +444,7 @@ class cata_tiles
const std::map<tripoint, furn_id> &furn_override );
void get_terrain_orientation( const tripoint &p, int &rota, int &subtile,
const std::map<tripoint, ter_id> &ter_override,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
void get_rotation_and_subtile( char val, int &rota, int &subtile );
/** Map memory */
@ -461,29 +462,29 @@ class cata_tiles
bool would_apply_vision_effects( visibility_type visibility ) const;
bool apply_vision_effects( const tripoint &pos, visibility_type visibility );
bool draw_terrain( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_terrain_below( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_furniture( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_graffiti( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_trap( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_field_or_item( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_vpart( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_vpart_below( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_critter_at( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_critter_at_below( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_zone_mark( const tripoint &p, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
bool draw_zombie_revival_indicators( const tripoint &pos, lit_level ll, int &height_3d,
const bool ( &invisible )[5] );
const std::array<bool, 5> &invisible );
void draw_entity_with_overlays( const Character &ch, const tripoint &p, lit_level ll,
int &height_3d );

View File

@ -336,8 +336,8 @@ bool read_from_file( const std::string &path, const std::function<void( std::ist
// check if file is gzipped
// (byte1 == 0x1f) && (byte2 == 0x8b)
char header[2];
fin.read( header, 2 );
std::array<char, 2> header;
fin.read( header.data(), 2 );
fin.clear();
fin.seekg( 0, std::ios::beg ); // reset read position
@ -359,18 +359,18 @@ bool read_from_file( const std::string &path, const std::function<void( std::ist
zs.avail_in = str.size();
int ret;
char outbuffer[32768];
std::array<char, 32768> outbuffer;
std::string outstring;
// get the decompressed bytes blockwise using repeated calls to inflate
do {
zs.next_out = reinterpret_cast<Bytef *>( outbuffer );
zs.next_out = reinterpret_cast<Bytef *>( outbuffer.data() );
zs.avail_out = sizeof( outbuffer );
ret = inflate( &zs, 0 );
if( outstring.size() < static_cast<size_t>( zs.total_out ) ) {
outstring.append( outbuffer,
outstring.append( outbuffer.data(),
zs.total_out - outstring.size() );
}
@ -458,6 +458,7 @@ std::string obscure_message( const std::string &str, const std::function<char()>
std::wstring w_gibberish_wide = utf8_to_wstr( gibberish_wide );
std::wstring w_str = utf8_to_wstr( str );
// a trailing NULL terminator is necessary for utf8_width function
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char transformation[2] = { 0 };
for( size_t i = 0; i < w_str.size(); ++i ) {
transformation[0] = f();

View File

@ -407,6 +407,7 @@ bool string_starts_with( const std::string &s1, const std::string &s2 );
* Note: N is (size+1) for null-terminated strings.
*/
template <std::size_t N>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
inline bool string_starts_with( const std::string &s1, const char( &s2 )[N] )
{
return s1.compare( 0, N - 1, s2, N - 1 ) == 0;
@ -423,6 +424,7 @@ bool string_ends_with( const std::string &s1, const std::string &s2 );
* Note: N is (size+1) for null-terminated strings.
*/
template <std::size_t N>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
inline bool string_ends_with( const std::string &s1, const char( &s2 )[N] )
{
return s1.size() >= N - 1 && s1.compare( s1.size() - ( N - 1 ), std::string::npos, s2, N - 1 ) == 0;

View File

@ -3451,6 +3451,7 @@ class colony : private element_allocator_type
if COLONY_CONSTEXPR( std::is_trivial<group_pointer_type>::value &&
std::is_trivial<aligned_pointer_type>::value &&
std::is_trivial<skipfield_pointer_type>::value ) {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char temp[sizeof( colony )];
std::memcpy( &temp, static_cast<void *>( this ), sizeof( colony ) );
std::memcpy( static_cast<void *>( this ), static_cast<void *>( &source ), sizeof( colony ) );

View File

@ -559,7 +559,10 @@ nc_color color_from_string( const std::string &color,
new_color = "c_" + new_color;
}
const std::pair<std::string, std::string> pSearch[2] = { { "light_", "lt" }, { "dark_", "dk" } };
const std::array<std::pair<std::string, std::string>, 2> pSearch = { {
{ "light_", "lt" }, { "dark_", "dk" }
}
};
for( const auto &i : pSearch ) {
size_t pos = 0;
while( ( pos = new_color.find( i.second, pos ) ) != std::string::npos ) {
@ -606,7 +609,10 @@ nc_color bgcolor_from_string( const std::string &color )
std::string new_color = "i_" + color;
const std::pair<std::string, std::string> pSearch[2] = { { "light_", "lt" }, { "dark_", "dk" } };
const std::array<std::pair<std::string, std::string>, 2> pSearch = { {
{ "light_", "lt" }, { "dark_", "dk" }
}
};
for( const auto &i : pSearch ) {
size_t pos = 0;
while( ( pos = new_color.find( i.second, pos ) ) != std::string::npos ) {

View File

@ -816,6 +816,7 @@ static std::ostream &operator<<( std::ostream &out, DebugClass cl )
// In particular, we want to avoid any characters of significance to the shell.
static bool debug_is_safe_string( const char *start, const char *finish )
{
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
static constexpr char safe_chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"01234567890_./-+";
@ -883,7 +884,7 @@ static cata::optional<uintptr_t> debug_compute_load_offset(
// We need to try calling nm in two different ways, because one
// works for executables and the other for libraries.
const char *nm_variants[] = { "nm", "nm -D" };
std::array<const char *, 2> nm_variants = { "nm", "nm -D" };
for( const char *nm_variant : nm_variants ) {
std::ostringstream cmd;
cmd << nm_variant << ' ' << binary << " 2>&1";
@ -893,9 +894,9 @@ static cata::optional<uintptr_t> debug_compute_load_offset(
return cata::nullopt;
}
char buf[1024];
while( fgets( buf, sizeof( buf ), nm ) ) {
std::string line( buf );
std::array<char, 1024> buf;
while( fgets( buf.data(), buf.size(), nm ) ) {
std::string line( buf.data() );
while( !line.empty() && isspace( line.end()[-1] ) ) {
line.erase( line.end() - 1 );
}
@ -1033,6 +1034,7 @@ static std::map<DWORD64, backtrace_module_info_t> bt_module_info_map;
#endif
#elif !defined(__ANDROID__) && !defined(LIBBACKTRACE)
static constexpr int bt_cnt = 20;
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
static void *bt[bt_cnt];
#endif
@ -1251,16 +1253,16 @@ void debug_write_backtrace( std::ostream &out )
out << " backtrace: popen(addr2line) failed\n";
return false;
}
char buf[1024];
while( fgets( buf, sizeof( buf ), addr2line ) ) {
std::array<char, 1024> buf;
while( fgets( buf.data(), buf.size(), addr2line ) ) {
out.write( " ", 4 );
// Strip leading directories for source file path
char search_for[] = "/src/";
char *buf_end = buf + strlen( buf );
char *src = std::find_end( buf, buf_end,
const char *search_for = "/src/";
char *buf_end = buf.data() + strlen( buf.data() );
char *src = std::find_end( buf.data(), buf_end,
search_for, search_for + strlen( search_for ) );
if( src == buf_end ) {
src = buf;
src = buf.data();
} else {
out << "";
}

View File

@ -39,11 +39,12 @@ static const itype_id fuel_type_muscle( "muscle" );
// Cache for the overmap widget string
static disp_overmap_cache disp_om_cache;
// Cache for the bodygraph widget string
static disp_bodygraph_cache disp_bg_cache[] = {
disp_bodygraph_cache( bodygraph_var::hp ),
disp_bodygraph_cache( bodygraph_var::temp ),
disp_bodygraph_cache( bodygraph_var::encumb ),
disp_bodygraph_cache( bodygraph_var::status )
static std::array<disp_bodygraph_cache, 4> disp_bg_cache = { {
disp_bodygraph_cache( bodygraph_var::hp ),
disp_bodygraph_cache( bodygraph_var::temp ),
disp_bodygraph_cache( bodygraph_var::encumb ),
disp_bodygraph_cache( bodygraph_var::status )
}
};
disp_overmap_cache::disp_overmap_cache()
@ -1747,7 +1748,7 @@ void display::print_mon_info( const avatar &u, const catacurses::window &w, int
}
}
}
std::vector<std::pair<const mtype *, int>> mons_at[9];
std::array<std::vector<std::pair<const mtype *, int>>, 9> mons_at;
for( const std::pair<const mtype *const, nearest_loc_and_cnt> &mon : all_mons ) {
mons_at[mon.second.nearest_loc].emplace_back( mon.first, mon.second.cnt );
}

View File

@ -531,7 +531,7 @@ void editmap::draw_main_ui_overlay()
#ifdef TILES
// give some visual indication of different cursor moving modes
if( use_tiles && altblink ) {
point p[2] = { origin.xy(), target.xy() };
std::array<point, 2> p = { origin.xy(), target.xy() };
if( editshape == editmap_rect || editshape == editmap_rect_filled || p[0] == p[1] ) {
if( p[0] == p[1] ) {
// ensure more than one cursor is drawn to differ from resizing mode

View File

@ -199,7 +199,7 @@ static event::fields_type
get_fields_helper( event_type type, std::integer_sequence<int, I...> )
{
event::fields_type result;
bool discard[] = {
std::array<bool, sizeof...( I )> discard = {
( get_fields_if_match<static_cast<event_type>( I )>( type, result ), true )...
};
( void ) discard;

View File

@ -166,9 +166,9 @@ static void do_blast( const tripoint &p, const float power,
// 1 . 2
// 6 4 8
// 9 and 10 are up and down
static const int x_offset[10] = { -1, 1, 0, 0, 1, -1, -1, 1, 0, 0 };
static const int y_offset[10] = { 0, 0, -1, 1, -1, 1, -1, 1, 0, 0 };
static const int z_offset[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
static constexpr std::array<int, 10> x_offset = { -1, 1, 0, 0, 1, -1, -1, 1, 0, 0 };
static constexpr std::array<int, 10> y_offset = { 0, 0, -1, 1, -1, 1, -1, 1, 0, 0 };
static constexpr std::array<int, 10> z_offset = { 0, 0, 0, 0, 0, 0, 0, 0, 1, -1 };
map &here = get_map();
const size_t max_index = 10;

View File

@ -59,9 +59,11 @@ bool remove_directory( const std::string &path )
const char *cata_files::eol()
{
#if defined(_WIN32)
// NOLINTNEXTLINE(cata-text-style): carriage return is necessary here
// carriage return is necessary here
// NOLINTNEXTLINE(cata-text-style, modernize-avoid-c-arrays)
static const char local_eol[] = "\r\n";
#else
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
static const char local_eol[] = "\n";
#endif
return local_eol;

View File

@ -3139,6 +3139,7 @@ void game::write_memorial_file( std::string sLastWords )
current_time.wYear, current_time.wMonth, current_time.wDay,
current_time.wHour, current_time.wMinute, current_time.wSecond );
#else
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char buffer[suffix_len] {};
std::time_t t = std::time( nullptr );
tm current_time;
@ -4098,7 +4099,7 @@ void game::mon_info_update( )
for( auto &m : unique_mons ) {
m.clear();
}
std::fill_n( dangerous, 8, false );
std::fill( dangerous.begin(), dangerous.end(), false );
const tripoint view = u.pos() + u.view_offset;
new_seen_mon.clear();
@ -10166,7 +10167,10 @@ point game::place_player( const tripoint &dest_loc )
//Auto pulp or butcher and Auto foraging
if( get_option<bool>( "AUTO_FEATURES" ) && mostseen == 0 && !u.is_mounted() ) {
static const direction adjacentDir[8] = { direction::NORTH, direction::NORTHEAST, direction::EAST, direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST, direction::NORTHWEST };
static constexpr std::array<direction, 8> adjacentDir = {
direction::NORTH, direction::NORTHEAST, direction::EAST, direction::SOUTHEAST,
direction::SOUTH, direction::SOUTHWEST, direction::WEST, direction::NORTHWEST
};
const std::string forage_type = get_option<std::string>( "AUTO_FORAGING" );
if( forage_type != "off" ) {

View File

@ -878,8 +878,8 @@ std::string defense_location_description( defense_location location )
void defense_game::caravan() const
{
std::vector<itype_id> items[NUM_CARAVAN_CATEGORIES];
std::vector<int> item_count[NUM_CARAVAN_CATEGORIES];
std::array<std::vector<itype_id>, NUM_CARAVAN_CATEGORIES> items;
std::array<std::vector<int>, NUM_CARAVAN_CATEGORIES> item_count;
// Init the items for each category
for( int i = 0; i < NUM_CARAVAN_CATEGORIES; i++ ) {

View File

@ -4574,7 +4574,7 @@ static std::string getGasDiscountName( int discount )
static int getGasPricePerLiter( int discount )
{
// Those prices are in cents
static const int prices[4] = { 1400, 1320, 1200, 1000 };
static constexpr std::array<int, 4> prices = { 1400, 1320, 1200, 1000 };
if( discount < 0 || discount > 3 ) {
return prices[0];
} else {

View File

@ -1894,7 +1894,7 @@ static void insert_separation_line( std::vector<iteminfo> &info )
* attacks
* data painstakingly looked up at http://onlinestatbook.com/2/calculators/normal_dist.html
*/
static const double hits_by_accuracy[41] = {
static constexpr std::array<double, 41> hits_by_accuracy = {
0, 1, 2, 3, 7, // -20 to -16
13, 26, 47, 82, 139, // -15 to -11
228, 359, 548, 808, 1151, // -10 to -6

View File

@ -3353,34 +3353,35 @@ void Item_factory::load_generic( const JsonObject &jo, const std::string &src )
// Set for all items (not just food and clothing) to avoid edge cases
void Item_factory::set_allergy_flags( itype &item_template )
{
static const std::pair<material_id, flag_id> all_pairs[] = {
// First allergens:
// An item is an allergen even if it has trace amounts of allergenic material
{ material_hflesh, flag_CANNIBALISM },
static const std::array<std::pair<material_id, flag_id>, 22> all_pairs = { {
// First allergens:
// An item is an allergen even if it has trace amounts of allergenic material
{ material_hflesh, flag_CANNIBALISM },
{ material_hflesh, flag_ALLERGEN_MEAT },
{ material_iflesh, flag_ALLERGEN_MEAT },
{ material_flesh, flag_ALLERGEN_MEAT },
{ material_wheat, flag_ALLERGEN_WHEAT },
{ material_fruit, flag_ALLERGEN_FRUIT },
{ material_veggy, flag_ALLERGEN_VEGGY },
{ material_bean, flag_ALLERGEN_VEGGY },
{ material_tomato, flag_ALLERGEN_VEGGY },
{ material_garlic, flag_ALLERGEN_VEGGY },
{ material_nut, flag_ALLERGEN_NUT },
{ material_mushroom, flag_ALLERGEN_VEGGY },
{ material_milk, flag_ALLERGEN_MILK },
{ material_egg, flag_ALLERGEN_EGG },
{ material_junk, flag_ALLERGEN_JUNK },
// Not food, but we can keep it here
{ material_wool, flag_ALLERGEN_WOOL },
// Now "made of". Those flags should not be passed
{ material_flesh, flag_CARNIVORE_OK },
{ material_hflesh, flag_CARNIVORE_OK },
{ material_iflesh, flag_CARNIVORE_OK },
{ material_milk, flag_CARNIVORE_OK },
{ material_egg, flag_CARNIVORE_OK },
{ material_honey, flag_URSINE_HONEY }
{ material_hflesh, flag_ALLERGEN_MEAT },
{ material_iflesh, flag_ALLERGEN_MEAT },
{ material_flesh, flag_ALLERGEN_MEAT },
{ material_wheat, flag_ALLERGEN_WHEAT },
{ material_fruit, flag_ALLERGEN_FRUIT },
{ material_veggy, flag_ALLERGEN_VEGGY },
{ material_bean, flag_ALLERGEN_VEGGY },
{ material_tomato, flag_ALLERGEN_VEGGY },
{ material_garlic, flag_ALLERGEN_VEGGY },
{ material_nut, flag_ALLERGEN_NUT },
{ material_mushroom, flag_ALLERGEN_VEGGY },
{ material_milk, flag_ALLERGEN_MILK },
{ material_egg, flag_ALLERGEN_EGG },
{ material_junk, flag_ALLERGEN_JUNK },
// Not food, but we can keep it here
{ material_wool, flag_ALLERGEN_WOOL },
// Now "made of". Those flags should not be passed
{ material_flesh, flag_CARNIVORE_OK },
{ material_hflesh, flag_CARNIVORE_OK },
{ material_iflesh, flag_CARNIVORE_OK },
{ material_milk, flag_CARNIVORE_OK },
{ material_egg, flag_CARNIVORE_OK },
{ material_honey, flag_URSINE_HONEY }
}
};
const auto &mats = item_template.materials;

View File

@ -5891,7 +5891,9 @@ static void init_memory_card_with_random_stuff( item &it )
//add random recipes
if( one_in( recipe_chance ) || ( encrypted && one_in( recipe_retry ) ) ) {
const std::string recipe_category[6] = { "CC_AMMO", "CC_ARMOR", "CC_CHEM", "CC_ELECTRONIC", "CC_FOOD", "CC_WEAPON" };
const std::array<std::string, 6> recipe_category = {
"CC_AMMO", "CC_ARMOR", "CC_CHEM", "CC_ELECTRONIC", "CC_FOOD", "CC_WEAPON"
};
int cc_random = rng( 0, 5 );
it.set_var( "MC_RECIPE", recipe_category[cc_random] );
}
@ -6790,7 +6792,7 @@ static object_names_collection enumerate_objects_around_point( const tripoint &p
if( create_figure_desc ) {
std::vector<std::string> objects_combined_desc;
int objects_combined_num = 0;
std::unordered_map<std::string, int> vecs_to_retrieve[4] = {
std::array<std::unordered_map<std::string, int>, 4> vecs_to_retrieve = {
ret_obj.furniture, ret_obj.vehicles, ret_obj.items, ret_obj.terrain
};

View File

@ -24,6 +24,7 @@ static constexpr int KITTEN = 1;
robot_finds_kitten::robot_finds_kitten()
{
ret = false;
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char ktile[83] =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#&()*+./:;=?![]{|}y";

View File

@ -34,7 +34,7 @@ class robot_finds_kitten
kobject kitten;
kobject empty;
static constexpr int numbogus = 20;
kobject bogus[MAXMESSAGES];
std::array<kobject, MAXMESSAGES> bogus;
std::vector<std::string> bogus_messages;
static constexpr int rfkLINES = 20;
static constexpr int rfkCOLS = 60;

View File

@ -38,9 +38,11 @@ static bool is_whitespace( char ch )
// binary.
std::string utf32_to_utf8( uint32_t ch )
{
char out[5];
char *buf = out;
static const unsigned char utf8FirstByte[7] = { 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC };
std::array<char, 5> out;
char *buf = out.data();
static constexpr std::array<unsigned char, 7> utf8FirstByte = {
0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC
};
int utf8Bytes;
if( ch < 0x80 ) {
utf8Bytes = 1;
@ -73,7 +75,7 @@ std::string utf32_to_utf8( uint32_t ch )
*--buf = ch | utf8FirstByte[utf8Bytes];
}
out[utf8Bytes] = '\0';
return out;
return out.data();
}
void JsonValue::string_error( const std::string &err ) const
@ -980,6 +982,7 @@ void JsonIn::skip_array()
void JsonIn::skip_true()
{
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char text[5];
eat_whitespace();
stream->get( text, 5 );
@ -993,6 +996,7 @@ void JsonIn::skip_true()
void JsonIn::skip_false()
{
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char text[6];
eat_whitespace();
stream->get( text, 6 );
@ -1006,6 +1010,7 @@ void JsonIn::skip_false()
void JsonIn::skip_null()
{
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char text[5];
eat_whitespace();
stream->get( text, 5 );
@ -1417,6 +1422,7 @@ number_sci_notation JsonIn::get_any_number()
bool JsonIn::get_bool()
{
char ch;
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char text[5];
std::stringstream err;
eat_whitespace();
@ -1576,6 +1582,7 @@ bool JsonIn::read_null( bool throw_on_error )
if( !test_null() ) {
return error_or_false( throw_on_error, "Expected null" );
}
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char text[5];
if( !stream->get( text, 5 ) ) {
error( "Unexpected end of stream reading null" );

View File

@ -1427,8 +1427,9 @@ void map::apply_light_arc( const tripoint &p, const units::angle &angle, float l
}
}
void map::apply_light_ray( bool lit[LIGHTMAP_CACHE_X][LIGHTMAP_CACHE_Y],
const tripoint &s, const tripoint &e, float luminance )
void map::apply_light_ray(
cata::mdarray<bool, point_bub_ms, LIGHTMAP_CACHE_X, LIGHTMAP_CACHE_Y> &lit,
const tripoint &s, const tripoint &e, float luminance )
{
point a( std::abs( e.x - s.x ) * 2, std::abs( e.y - s.y ) * 2 );
point d( ( s.x < e.x ) ? 1 : -1, ( s.y < e.y ) ? 1 : -1 );

View File

@ -650,6 +650,7 @@ template <class element_type, class element_allocator_type = std::allocator<elem
void swap( group_vector &source ) LIST_NOEXCEPT_SWAP( group_allocator_type ) {
if LIST_CONSTEXPR(
std::is_trivial<group_pointer_type>::value ) { // if all pointer types are trivial we can just copy using memcpy - faster - avoids constructors/destructors etc
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char temp[sizeof( group_vector )];
std::memcpy( static_cast<void *>( &temp ), static_cast<void *>( this ), sizeof( group_vector ) );
std::memcpy( static_cast<void *>( this ), static_cast<void *>( &source ), sizeof( group_vector ) );

View File

@ -2224,7 +2224,7 @@ int map::combined_movecost( const tripoint &from, const tripoint &to,
const vehicle *ignored_vehicle,
const int modifier, const bool flying, const bool via_ramp ) const
{
const int mults[4] = { 0, 50, 71, 100 };
static constexpr std::array<int, 4> mults = { 0, 50, 71, 100 };
const int cost1 = move_cost( from, ignored_vehicle );
const int cost2 = move_cost( to, ignored_vehicle );
// Multiply cost depending on the number of differing axes
@ -3598,8 +3598,8 @@ ter_id map::get_roof( const tripoint &p, const bool allow_air ) const
// For example, a washing machine behind the bashed door
static bool furn_is_supported( const map &m, const tripoint &p )
{
const signed char cx[4] = { 0, -1, 0, 1};
const signed char cy[4] = { -1, 0, 1, 0};
static constexpr std::array<int8_t, 4> cx = { 0, -1, 0, 1};
static constexpr std::array<int8_t, 4> cy = { -1, 0, 1, 0};
for( int i = 0; i < 4; i++ ) {
const point adj( p.xy() + point( cx[i], cy[i] ) );
@ -6977,16 +6977,16 @@ void map::reachable_flood_steps( std::vector<tripoint> &reachable_pts, const tri
t_grid[ ndx ] = initial_visit_distance;
}
auto gen_neighbors = []( const pq_item & elem, int grid_dim, pq_item * neighbors ) {
auto gen_neighbors = []( const pq_item & elem, int grid_dim, std::array<pq_item, 8> &neighbors ) {
// Up to 8 neighbors
int new_cost = elem.dist + 1;
// *INDENT-OFF*
int ox[8] = {
std::array<int, 8> ox = {
-1, 0, 1,
-1, 1,
-1, 0, 1
};
int oy[8] = {
std::array<int, 8> oy = {
-1, -1, -1,
0, 0,
1, 1, 1
@ -7005,7 +7005,7 @@ void map::reachable_flood_steps( std::vector<tripoint> &reachable_pts, const tri
PQ_type pq( pq_item_comp{} );
pq_item first_item{ 0, range + range * grid_dim };
pq.push( first_item );
pq_item neighbor_elems[8];
std::array<pq_item, 8> neighbor_elems;
while( !pq.empty() ) {
const pq_item item = pq.top();

View File

@ -2062,7 +2062,7 @@ class map
void apply_directional_light( const tripoint &p, int direction, float luminance );
void apply_light_arc( const tripoint &p, const units::angle &angle, float luminance,
const units::angle &wideangle = 30_degrees );
void apply_light_ray( bool lit[MAPSIZE_X][MAPSIZE_Y],
void apply_light_ray( cata::mdarray<bool, point_bub_ms, MAPSIZE_X, MAPSIZE_Y> &lit,
const tripoint &s, const tripoint &e, float luminance );
void add_light_from_items( const tripoint &p, const item_stack::iterator &begin,
const item_stack::iterator &end );

View File

@ -6374,7 +6374,7 @@ void map::draw_connections( const mapgendata &dat )
// finally, any terrain with SIDEWALKS should contribute sidewalks to neighboring diagonal roads
if( terrain_type->has_flag( oter_flags::has_sidewalk ) ) {
for( int dir = 4; dir < 8; dir++ ) { // NE SE SW NW
bool n_roads_nesw[4] = {};
std::array<bool, 4> n_roads_nesw = {};
int n_num_dirs = terrain_type_to_nesw_array( oter_id( dat.t_nesw[dir] ), n_roads_nesw );
// only handle diagonal neighbors
if( n_num_dirs == 2 &&

View File

@ -458,7 +458,7 @@ void mapgen_hive( mapgendata &dat )
}
}
int terrain_type_to_nesw_array( oter_id terrain_type, bool array[4] )
int terrain_type_to_nesw_array( oter_id terrain_type, std::array<bool, 4> &array )
{
// count and mark which directions the road goes
const oter_t &oter( *terrain_type );
@ -470,10 +470,11 @@ int terrain_type_to_nesw_array( oter_id terrain_type, bool array[4] )
}
// perform dist counterclockwise rotations on a nesw or neswx array
template<typename T>
void nesw_array_rotate( T *array, size_t len, size_t dist )
template<typename T, size_t N>
void nesw_array_rotate( std::array<T, N> &array, size_t dist )
{
if( len == 4 ) {
static_assert( N == 8 || N == 4, "Only arrays of size 4 and 8 are supported" );
if( N == 4 ) {
while( dist-- ) {
T temp = array[0];
array[0] = array[1];
@ -507,9 +508,10 @@ static void coord_rotate_cw( int &x, int &y, int rot )
}
}
static bool compare_neswx( bool *a1, std::initializer_list<int> a2 )
static bool compare_neswx( const std::array<bool, 8> &a1, std::initializer_list<int> a2 )
{
return std::equal( std::begin( a2 ), std::end( a2 ), a1,
cata_assert( a1.size() == a2.size() );
return std::equal( std::begin( a2 ), std::end( a2 ), std::begin( a1 ),
[]( int a, bool b ) {
return static_cast<bool>( a ) == b;
} );
@ -523,7 +525,7 @@ void mapgen_road( mapgendata &dat )
dat.fill_groundcover();
// which and how many neighbors have sidewalks?
bool sidewalks_neswx[8] = {};
std::array<bool, 8> sidewalks_neswx = {};
int neighbor_sidewalks = 0;
// N E S W NE SE SW NW
for( int dir = 0; dir < 8; dir++ ) {
@ -532,13 +534,13 @@ void mapgen_road( mapgendata &dat )
}
// which of the cardinal directions get roads?
bool roads_nesw[4] = {};
std::array<bool, 4> roads_nesw = {};
int num_dirs = terrain_type_to_nesw_array( dat.terrain_type(), roads_nesw );
// if this is a dead end, extend past the middle of the tile
int dead_end_extension = num_dirs == 1 ? 8 : 0;
// which way should our roads curve, based on neighbor roads?
int curvedir_nesw[4] = {};
std::array<int, 4> curvedir_nesw = {};
// N E S W
for( int dir = 0; dir < 4; dir++ ) {
if( !roads_nesw[dir] || dat.t_nesw[dir]->get_type_id().str() != "road" ) {
@ -546,7 +548,7 @@ void mapgen_road( mapgendata &dat )
}
// n_* contain details about the neighbor being considered
bool n_roads_nesw[4] = {};
std::array<bool, 4> n_roads_nesw = {};
// TODO: figure out how to call this function without creating a new oter_id object
int n_num_dirs = terrain_type_to_nesw_array( dat.t_nesw[dir], n_roads_nesw );
// if 2-way neighbor has a road facing us
@ -568,7 +570,7 @@ void mapgen_road( mapgendata &dat )
int rot = 0;
bool diag = false;
int plaza_dir = -1;
bool fourways_neswx[8] = {};
std::array<bool, 8> fourways_neswx = {};
// TODO: reduce amount of logical/conditional constructs here
// TODO: make plazas include adjacent tees
switch( num_dirs ) {
@ -666,9 +668,9 @@ void mapgen_road( mapgendata &dat )
}
// rotate the arrays left by rot steps
nesw_array_rotate<bool>( sidewalks_neswx, 8, rot * 2 );
nesw_array_rotate<bool>( roads_nesw, 4, rot );
nesw_array_rotate<int> ( curvedir_nesw, 4, rot );
nesw_array_rotate( sidewalks_neswx, rot * 2 );
nesw_array_rotate( roads_nesw, rot );
nesw_array_rotate( curvedir_nesw, rot );
// now we have only these shapes: ' | '- -'- -|-
@ -992,7 +994,7 @@ void mapgen_subway( mapgendata &dat )
dat.fill_groundcover();
// which of the cardinal directions get subway?
bool subway_nesw[4] = {};
std::array<bool, 4> subway_nesw = {};
int num_dirs = terrain_type_to_nesw_array( dat.terrain_type(), subway_nesw );
// N E S W
@ -1004,7 +1006,7 @@ void mapgen_subway( mapgendata &dat )
}
// which way should our subway curve, based on neighbor subway?
int curvedir_nesw[4] = {};
std::array<int, 4> curvedir_nesw = {};
// N E S W
for( int dir = 0; dir < 4; dir++ ) {
if( !subway_nesw[dir] ) {
@ -1016,7 +1018,7 @@ void mapgen_subway( mapgendata &dat )
continue;
}
// n_* contain details about the neighbor being considered
bool n_subway_nesw[4] = {};
std::array<bool, 4> n_subway_nesw = {};
// TODO: figure out how to call this function without creating a new oter_id object
int n_num_dirs = terrain_type_to_nesw_array( dat.t_nesw[dir], n_subway_nesw );
for( int dir = 0; dir < 4; dir++ ) {
@ -1120,8 +1122,8 @@ void mapgen_subway( mapgendata &dat )
}
// rotate the arrays left by rot steps
nesw_array_rotate<bool>( subway_nesw, 4, rot );
nesw_array_rotate<int> ( curvedir_nesw, 4, rot );
nesw_array_rotate( subway_nesw, rot );
nesw_array_rotate( curvedir_nesw, rot );
// now we have only these shapes: ' | '- -'- -|-
@ -1481,16 +1483,16 @@ void mapgen_railroad( mapgendata &dat )
// start by filling the whole map with grass/dirt/etc
dat.fill_groundcover();
// which of the cardinal directions get railroads?
bool railroads_nesw[4] = {};
std::array<bool, 4> railroads_nesw = {};
int num_dirs = terrain_type_to_nesw_array( dat.terrain_type(), railroads_nesw );
// which way should our railroads curve, based on neighbor railroads?
int curvedir_nesw[4] = {};
std::array<int, 4> curvedir_nesw = {};
for( int dir = 0; dir < 4; dir++ ) { // N E S W
if( !railroads_nesw[dir] || dat.t_nesw[dir]->get_type_id() != oter_type_railroad ) {
continue;
}
// n_* contain details about the neighbor being considered
bool n_railroads_nesw[4] = {};
std::array<bool, 4> n_railroads_nesw = {};
// TODO: figure out how to call this function without creating a new oter_id object
int n_num_dirs = terrain_type_to_nesw_array( dat.t_nesw[dir], n_railroads_nesw );
// if 2-way neighbor has a railroad facing us
@ -1578,8 +1580,8 @@ void mapgen_railroad( mapgendata &dat )
break;
}
// rotate the arrays left by rot steps
nesw_array_rotate<bool>( railroads_nesw, 4, rot );
nesw_array_rotate<int> ( curvedir_nesw, 4, rot );
nesw_array_rotate( railroads_nesw, rot );
nesw_array_rotate( curvedir_nesw, rot );
// now we have only these shapes: ' | '- -'- -|-
switch( num_dirs ) {
case 4:
@ -2198,7 +2200,7 @@ void mapgen_forest( mapgendata &dat )
// In order to feather (blend) this overmap tile with adjacent ones, the general composition thereof must be known.
// This can be calculated once from dat.t_nesw, and stored here:
const forest_biome *adjacent_biomes[8];
std::array<const forest_biome *, 8> adjacent_biomes;
for( int d = 0; d < 7; d++ ) {
auto lookup = dat.region.forest_composition.biomes.find( dat.t_nesw[d] );
if( lookup != dat.region.forest_composition.biomes.end() ) {
@ -2210,7 +2212,7 @@ void mapgen_forest( mapgendata &dat )
// Keep track of the "true perimeter" of the biome. It has a curve to make it seem natural.
// The depth of the perimeter at each border of the forest being generated:
int border_depth[8];
std::array<int, 8> border_depth;
for( int bd_x = 0; bd_x < 2; bd_x++ )
for( int bd_y = 0; bd_y < 2; bd_y++ ) {
@ -2237,12 +2239,12 @@ void mapgen_forest( mapgendata &dat )
}
// Indicies of border_depth accessible by dat.dir() nomenclature, [h_idx 0..4 : v_idx 0..4]:
constexpr int edge_corner_mappings[8] = {0, 5, 3, 4, 1, 6, 2, 7};
static constexpr std::array<int, 8> edge_corner_mappings = {0, 5, 3, 4, 1, 6, 2, 7};
// Now, generate a curve along the border of the biome, which will be used to calculate each cardinally
// adjacent biome's relative impact.
// Format: [ SEEX * 2 (North) : SEEY * 2 (East) : SEEX * 2 (South) : SEEX * 2 (West) ] (order from dat.dir())
int perimeter_depth[perimeter_size];
std::array<int, perimeter_size> perimeter_depth;
for( int edge = 0; edge < 4; edge++ ) {
int perimeter_depth_offset = ( SEEX * 2 ) * ( ( edge + 1 ) / 2 ) + ( SEEY * 2 ) * ( edge / 2 );
int edge_length = edge % 2 == 0 ? SEEX * 2 : SEEY * 2;
@ -2348,7 +2350,8 @@ void mapgen_forest( mapgendata &dat )
* @param p the point in the terrain being weighted from the cardinally adjacent biomes.
*/
const auto unify_all_borders = [&unify_continuous_border,
&adjacent_biomes]( float * cardinal_four_weights, float * self_weight, const point & p ) {
&adjacent_biomes]( std::array<float, 4> &cardinal_four_weights, float * self_weight,
const point & p ) {
// Refer to dat.dir() convention.
if( p.x < SEEX ) {
if( p.y < SEEY ) {
@ -2381,10 +2384,10 @@ void mapgen_forest( mapgendata &dat )
* @return The sum of all of the weights written to \p weights.
*/
const auto nesw_weights = [&perimeter_depth, &adjacent_biomes]( const point & p,
float scaling_factor, float * weights, float root_depth_offset = 0. ) {
float scaling_factor, std::array<float, 4> &weights, float root_depth_offset = 0. ) {
float net_weight = 0.;
float perimeter_depths[4];
int point_depths[4];
std::array<float, 4> perimeter_depths;
std::array<int, 4> point_depths;
point_depths[0] = p.y;
point_depths[1] = SEEX * 2 - p.x - 1;
point_depths[2] = SEEY * 2 - p.y - 1;
@ -2424,7 +2427,7 @@ void mapgen_forest( mapgendata &dat )
*/
const auto get_feathered_groundcover = [&max_factor, &factor, &self_biome,
&adjacent_biomes, &nesw_weights, &unify_all_borders, &dat]( const point & p ) {
float adj_weights[4];
std::array<float, 4> adj_weights;
float net_weight = nesw_weights( p, factor, adj_weights, -groundcover_margin );
float self_weight = self_scalar;
unify_all_borders( adj_weights, &self_weight, p );
@ -2468,7 +2471,7 @@ void mapgen_forest( mapgendata &dat )
const auto get_feathered_feature = [&no_ter_furn, &max_factor, &factor, &self_biome,
&adjacent_biomes, &nesw_weights, &get_feathered_groundcover, &unify_all_borders,
&dat]( const point & p ) {
float adj_weights[4];
std::array<float, 4> adj_weights;
float net_weight = nesw_weights( p, factor, adj_weights );
float self_weight = self_scalar;
unify_all_borders( adj_weights, &self_weight, p );

View File

@ -27,7 +27,7 @@ class JsonObject;
*/
tripoint rotate_point( const tripoint &p, int rotations );
int terrain_type_to_nesw_array( oter_id terrain_type, bool array[4] );
int terrain_type_to_nesw_array( oter_id terrain_type, std::array<bool, 4> &array );
using building_gen_pointer = void ( * )( mapgendata & );
building_gen_pointer get_mapgen_cfunction( const std::string &ident );

View File

@ -76,7 +76,7 @@ class mapgendata
std::vector<oter_id> predecessors_;
public:
oter_id t_nesw[8];
std::array<oter_id, 8> t_nesw;
int n_fac = 0; // dir == 0
int e_fac = 0; // dir == 1

View File

@ -63,6 +63,7 @@ class format_effect
*/
/**@{*/
template<size_t N, typename ...Args>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
inline format_effect<ter_id> ter_bind( const char ( &characters )[N], Args... ids )
{
// Note to self: N contains the 0-char at the end of a string literal!
@ -73,6 +74,7 @@ inline format_effect<ter_id> ter_bind( const char ( &characters )[N], Args... id
}
template<size_t N, typename ...Args>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
inline format_effect<furn_id> furn_bind( const char ( &characters )[N], Args... ids )
{
// Note to self: N contains the 0-char at the end of a string literal!

View File

@ -44,6 +44,7 @@ class mdarray_impl_2d
using value_type = T;
// TODO: in C++17 array::operator[] becomes constexpr and we can use
// std::array here
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
using column_type = T[DimY];
static constexpr size_t size_x = DimX;
@ -98,6 +99,7 @@ class mdarray_impl_2d
private:
// TODO: in C++17 array::operator[] becomes constexpr and we can use
// std::array here
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
column_type data_[DimX];
};

View File

@ -743,7 +743,7 @@ void avatar::disp_medical()
int info_lines = 0;
// Cursor
int cursor_bounds[3]; // Number of selectable rows in each column
std::array<int, 3> cursor_bounds; // Number of selectable rows in each column
point cursor;
ui_adaptor ui;

View File

@ -134,153 +134,154 @@ struct miss_data {
translation action; // Optional extended UI description of task for return.
};
static const miss_data miss_info[Camp_Harvest + 1] = {
{
// No_Mission
"",
no_translation( "" )
},
{
"Scavenging_Patrol_Job",
no_translation( "" )
},
{
"Scavenging_Raid_Job",
no_translation( "" )
},
{
"Hospital_Raid_Job",
no_translation( "" )
},
{
"Menial_Job",
no_translation( "" )
},
{
"Carpentry_Job",
no_translation( "" )
},
{
"Forage_Job",
no_translation( "" )
},
{
"Caravan_Commune_Center_Job",
no_translation( "" )
},
// Faction camp missions
{
"Camp_Distribute_Food",
no_translation( "" )
},
{
"Hide_Mission",
no_translation( "" )
},
{
"Reveal_Mission",
no_translation( "" )
},
{
"Camp_Assign_Jobs",
no_translation( "" )
},
{
"Camp_Assign_Workers",
no_translation( "" )
},
{
"Camp_Abandon",
no_translation( "" )
},
{
"Camp_Upgrade ", // Want to add the blueprint after the space
to_translation( "Working to expand your camp!\n" )
},
{
"Camp_Emergency_Recall",
to_translation( "Lost in the ether!\n" )
},
{
"Camp_Crafting ", // Want to add the recipe after the space
to_translation( "Busy crafting!\n" )
},
{
"Camp_Gather_Materials",
to_translation( "Searching for materials to upgrade the camp.\n" )
},
{
"Camp_Collect_Firewood",
to_translation( "Searching for firewood.\n" )
},
{
"Camp_Menial",
to_translation( "Performing menial labor…\n" )
},
{
"Camp_Survey_Expansion",
to_translation( "Surveying for expansion…\n" )
},
{
"Camp_Cut_Logs",
to_translation( "Cutting logs in the woods…\n" )
},
{
"Camp_Clearcut",
to_translation( "Clearing a forest…\n" )
},
{
"Camp_Setup_Hide_Site",
to_translation( "Setting up a hide site…\n" )
},
{
"Camp_Relay_Hide_Site",
to_translation( "Transferring gear to a hide site…\n" )
},
{
"Camp Foraging",
to_translation( "Foraging for edible plants.\n" )
},
{
"Camp_Trapping",
to_translation( "Trapping Small Game.\n" )
},
{
"Camp_Hunting",
to_translation( "Hunting large animals.\n" )
},
{
"Camp_OM_Fortifications",
to_translation( "Constructing fortifications…\n" )
},
{
"Camp_Recruiting",
to_translation( "Searching for recruits.\n" )
},
{
"Camp_Scouting",
to_translation( "Scouting the region.\n" )
},
{
"Camp_Combat Patrol",
to_translation( "Patrolling the region.\n" )
},
{
// Obsolete entry
"Camp_Chop_Shop",
to_translation( "Working at the chop shop…\n" )
},
{
"Camp_Plow",
to_translation( "Working to plow your fields!\n" )
},
{
"Camp_Plant",
to_translation( "Working to plant your fields!\n" )
},
{
"Camp_Harvest",
to_translation( "Working to harvest your fields!\n" )
static const std::array < miss_data, Camp_Harvest + 1 > miss_info = { {
{
// No_Mission
"",
no_translation( "" )
},
{
"Scavenging_Patrol_Job",
no_translation( "" )
},
{
"Scavenging_Raid_Job",
no_translation( "" )
},
{
"Hospital_Raid_Job",
no_translation( "" )
},
{
"Menial_Job",
no_translation( "" )
},
{
"Carpentry_Job",
no_translation( "" )
},
{
"Forage_Job",
no_translation( "" )
},
{
"Caravan_Commune_Center_Job",
no_translation( "" )
},
// Faction camp missions
{
"Camp_Distribute_Food",
no_translation( "" )
},
{
"Hide_Mission",
no_translation( "" )
},
{
"Reveal_Mission",
no_translation( "" )
},
{
"Camp_Assign_Jobs",
no_translation( "" )
},
{
"Camp_Assign_Workers",
no_translation( "" )
},
{
"Camp_Abandon",
no_translation( "" )
},
{
"Camp_Upgrade ", // Want to add the blueprint after the space
to_translation( "Working to expand your camp!\n" )
},
{
"Camp_Emergency_Recall",
to_translation( "Lost in the ether!\n" )
},
{
"Camp_Crafting ", // Want to add the recipe after the space
to_translation( "Busy crafting!\n" )
},
{
"Camp_Gather_Materials",
to_translation( "Searching for materials to upgrade the camp.\n" )
},
{
"Camp_Collect_Firewood",
to_translation( "Searching for firewood.\n" )
},
{
"Camp_Menial",
to_translation( "Performing menial labor…\n" )
},
{
"Camp_Survey_Expansion",
to_translation( "Surveying for expansion…\n" )
},
{
"Camp_Cut_Logs",
to_translation( "Cutting logs in the woods…\n" )
},
{
"Camp_Clearcut",
to_translation( "Clearing a forest…\n" )
},
{
"Camp_Setup_Hide_Site",
to_translation( "Setting up a hide site…\n" )
},
{
"Camp_Relay_Hide_Site",
to_translation( "Transferring gear to a hide site…\n" )
},
{
"Camp Foraging",
to_translation( "Foraging for edible plants.\n" )
},
{
"Camp_Trapping",
to_translation( "Trapping Small Game.\n" )
},
{
"Camp_Hunting",
to_translation( "Hunting large animals.\n" )
},
{
"Camp_OM_Fortifications",
to_translation( "Constructing fortifications…\n" )
},
{
"Camp_Recruiting",
to_translation( "Searching for recruits.\n" )
},
{
"Camp_Scouting",
to_translation( "Scouting the region.\n" )
},
{
"Camp_Combat Patrol",
to_translation( "Patrolling the region.\n" )
},
{
// Obsolete entry
"Camp_Chop_Shop",
to_translation( "Working at the chop shop…\n" )
},
{
"Camp_Plow",
to_translation( "Working to plow your fields!\n" )
},
{
"Camp_Plant",
to_translation( "Working to plant your fields!\n" )
},
{
"Camp_Harvest",
to_translation( "Working to harvest your fields!\n" )
}
}
};

View File

@ -1315,7 +1315,7 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )
// 0 -> traits that take points ( positive traits )
// 1 -> traits that give points ( negative traits )
// 2 -> neutral traits ( facial hair, skin color, etc )
std::vector<trait_and_var> vStartingTraits[3];
std::array<std::vector<trait_and_var>, 3> vStartingTraits;
for( const mutation_branch &traits_iter : mutation_branch::get_all() ) {
// Don't list blacklisted traits
@ -1375,12 +1375,12 @@ void set_traits( tab_manager &tabs, avatar &u, pool_type pool )
}
int iCurWorkingPage = 0;
int iStartPos[3] = { 0, 0, 0 };
int iCurrentLine[3] = { 0, 0, 0 };
size_t traits_size[3];
std::array<int, 3> iStartPos = { 0, 0, 0 };
std::array<int, 3> iCurrentLine = { 0, 0, 0 };
std::array<size_t, 3> traits_size;
bool recalc_traits = false;
// pointer for memory footprint reasons
std::vector<const trait_and_var *> sorted_traits[3];
std::array<std::vector<const trait_and_var *>, 3> sorted_traits;
std::string filterstring;
for( int i = 0; i < 3; i++ ) {

View File

@ -1879,7 +1879,7 @@ std::vector<spell_id> npc::spells_offered_to( Character &you )
void npc::decide_needs()
{
const item_location weapon = get_wielded_item();
double needrank[num_needs];
std::array<double, num_needs> needrank;
for( double &elem : needrank ) {
elem = 20;
}

View File

@ -506,9 +506,10 @@ struct dangerous_sound {
int volume = 0;
};
const direction npc_threat_dir[8] = { direction::NORTHWEST, direction::NORTH, direction::NORTHEAST, direction::EAST,
direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST
};
constexpr std::array<direction, 8> npc_threat_dir = {
direction::NORTHWEST, direction::NORTH, direction::NORTHEAST, direction::EAST,
direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST, direction::WEST
};
struct healing_options {
bool bandage = false;

View File

@ -108,6 +108,7 @@ std::string string_from_int( const catacurses::chtype ch )
default:
break;
}
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
char buffer[2] = { static_cast<char>( charcode ), '\0' };
return buffer;
}

View File

@ -1395,7 +1395,7 @@ static bool search( const ui_adaptor &om_ui, tripoint_abs_omt &curs, const tripo
int c = utf8_width( _( "Results:" ) );
int d = utf8_width( _( "Direction:" ) );
int align_width = 0;
int align_w_value[4] = { a, b, c, d};
std::array<int, 4> align_w_value = { a, b, c, d};
for( int n : align_w_value ) {
if( n > align_width ) {
align_width = n + 2;

View File

@ -2,6 +2,7 @@
#ifndef CATA_SRC_PATHFINDING_H
#define CATA_SRC_PATHFINDING_H
#include "coordinates.h"
#include "game_constants.h"
#include "mdarray.h"

View File

@ -366,7 +366,7 @@ void Pickup::autopickup( const tripoint &p )
// Recursively pick up adjacent items if that option is on.
if( get_option<bool>( "AUTO_PICKUP_ADJACENT" ) && player.pos() == p ) {
//Autopickup adjacent
direction adjacentDir[8] = {
std::array<direction, 8> adjacentDir = {
direction::NORTH, direction::NORTHEAST, direction::EAST,
direction::SOUTHEAST, direction::SOUTH, direction::SOUTHWEST,
direction::WEST, direction::NORTHWEST

View File

@ -5,6 +5,7 @@
#include <cstdint>
#include <limits>
#include "coordinates.h"
#include "enums.h"
#include "game_constants.h"
#include "mdarray.h"
@ -52,7 +53,7 @@ class reachability_cache_layer
public:
using Q = reachability_cache_quadrant;
using ElType = uint8_t;
using QLayers = reachability_cache_layer[enum_traits<Q>::size];
using QLayers = std::array<reachability_cache_layer, enum_traits<Q>::size>;
// max distance the cache supports
// all checks for distance that exceeds MAX_D will return "false"
static constexpr int MAX_D = std::numeric_limits<ElType>::max() - 3;

View File

@ -145,6 +145,7 @@ void rng_set_engine_seed( unsigned int seed )
std::string random_string( size_t length )
{
auto randchar = []() -> char {
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
static constexpr char charset[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";

View File

@ -389,7 +389,7 @@ BitmapFont::BitmapFont(
}
Uint32 key = SDL_MapRGB( asciiload->format, 0xFF, 0, 0xFF );
SDL_SetColorKey( asciiload.get(), SDL_TRUE, key );
SDL_Surface_Ptr ascii_surf[std::tuple_size<decltype( ascii )>::value];
std::array<SDL_Surface_Ptr, std::tuple_size<decltype( ascii )>::value> ascii_surf;
ascii_surf[0].reset( SDL_ConvertSurface( asciiload.get(), format.get(), 0 ) );
SDL_SetSurfaceRLE( ascii_surf[0].get(), 1 );
asciiload.reset();

View File

@ -22,16 +22,16 @@ static std::array<std::array<int, 2>, max_sticks> sticks_axis = { {
}
};
static int triggers_state[max_triggers] = {0, 0};
static int sticks_state[max_sticks] = {0, 0};
static std::array<int, max_triggers> triggers_state = {0, 0};
static std::array<int, max_sticks> sticks_state = {0, 0};
static int triggers_threshold = 16000;
static int sticks_threshold = 16000;
static int error_margin = 2000;
static std::array<std::array<int, 16>, max_sticks> sticks_map = {};
static int triggers_map[max_triggers] = {0};
static int buttons_map[max_buttons] = {0};
static std::array<int, max_triggers> triggers_map = {0};
static std::array<int, max_buttons> buttons_map = {0};
struct task_t {
Uint32 when;
@ -45,7 +45,7 @@ static constexpr int max_tasks = max_buttons + max_sticks + max_trigge
static constexpr int sticks_task_index = max_buttons;
static constexpr int triggers_task_index = max_buttons + max_sticks;
static task_t all_tasks[max_tasks];
static std::array<task_t, max_tasks> all_tasks;
static int repeat_delay = 400;
static int repeat_interval = 200;

View File

@ -764,7 +764,7 @@ std::string cata_tiles::get_omt_id_rotation_and_subtile(
// This would be for connected terrain
// get terrain neighborhood
const oter_type_id neighborhood[4] = {
const std::array<oter_type_id, 4> neighborhood = {
oter_at( omp + point_south )->get_type_id(),
oter_at( omp + point_east )->get_type_id(),
oter_at( omp + point_west )->get_type_id(),

View File

@ -66,7 +66,7 @@ directed_path<point> greedy_path( const point &source, const point &dest, const
std::vector<bool> closed( map_size, false );
std::vector<int> open( map_size, 0 );
std::vector<short> dirs( map_size, 0 );
std::priority_queue<Node, std::vector<Node>> nodes[2];
std::array<std::priority_queue<Node, std::vector<Node>>, 2> nodes;
int i = 0;
nodes[i].push( first_node );

View File

@ -145,7 +145,7 @@ static constexpr std::array<std::array<int, 4>, 32> grad4 = { {
};
// Permutation table. The same list is repeated twice.
static const int perm[512] = {
static const std::array<int, 512> perm = {
151, 160, 137, 91, 90, 15, 131, 13, 201, 95, 96, 53, 194, 233, 7, 225, 140, 36, 103, 30, 69, 142,
8, 99, 37, 240, 21, 10, 23, 190, 6, 148, 247, 120, 234, 75, 0, 26, 197, 62, 94, 252, 219, 203, 117,
35, 11, 32, 57, 177, 33, 88, 237, 149, 56, 87, 174, 20, 125, 136, 171, 168, 68, 175, 74, 165, 71,

View File

@ -8,8 +8,8 @@
#include "units.h"
#include "units_utility.h"
static const int sx[4] = { 1, -1, -1, 1 };
static const int sy[4] = { 1, 1, -1, -1 };
static constexpr std::array<int, 4> sx = { 1, -1, -1, 1 };
static constexpr std::array<int, 4> sy = { 1, 1, -1, -1 };
tileray::tileray() = default;

View File

@ -92,7 +92,7 @@ class TranslationPluralRulesEvaluator
struct ExprNode {
std::size_t n_children;
ExprNode *children[3];
std::array<ExprNode *, 3> children;
ExprToken token;
ExprNode() : n_children( 0 ), children{ nullptr, nullptr, nullptr } {}
void AddChild( ExprNode *child );

View File

@ -2583,9 +2583,9 @@ void veh_interact::display_stats() const
const int extraw = ( ( TERMX - FULL_SCREEN_WIDTH ) / 4 ) * 2;
// 3 * stats_h
const int slots = 24;
int x[slots];
int y[slots];
int w[slots];
std::array<int, slots> x;
std::array<int, slots> y;
std::array<int, slots> w;
units::volume total_cargo = 0_ml;
units::volume free_cargo = 0_ml;

View File

@ -859,7 +859,9 @@ scored_address vehicle::autodrive_controller::compute_node_score( const node_add
if( node.is_goal ) {
return ret;
}
static const point neighbor_deltas[4] = { point_east, point_south, point_west, point_north };
static constexpr std::array<point, 4> neighbor_deltas = {
point_east, point_south, point_west, point_north
};
for( const point &neighbor_delta : neighbor_deltas ) {
const point p = addr.get_point() + neighbor_delta;
if( !data.nav_bounds.contains( p ) || !data.valid_position( addr.facing_dir, p ) ) {

View File

@ -422,7 +422,7 @@ void vehicle::print_fuel_indicator( const catacurses::window &win, const point &
std::map<itype_id, float> fuel_usages,
bool verbose, bool desc )
{
const char fsyms[5] = { 'E', '\\', '|', '/', 'F' };
static constexpr std::array<char, 5> fsyms = { 'E', '\\', '|', '/', 'F' };
nc_color col_indf1 = c_light_gray;
int cap = fuel_capacity( fuel_type );
int f_left = fuel_left( fuel_type );

View File

@ -95,6 +95,7 @@ int mk_wcwidth( uint32_t ucs )
{
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
static const struct interval combining[] = {
{ 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
{ 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },

View File

@ -90,7 +90,10 @@ static units::temperature weather_temperature_from_common_data( const weather_ge
// -1 at coldest_hour, +1 twelve hours later
// manually specified seasonal temp variation from region_settings.json
const int seasonal_temp_mod[4] = { wg.spring_temp_manual_mod, wg.summer_temp_manual_mod, wg.autumn_temp_manual_mod, wg.winter_temp_manual_mod };
const std::array<int, 4> seasonal_temp_mod = {
wg.spring_temp_manual_mod, wg.summer_temp_manual_mod, wg.autumn_temp_manual_mod,
wg.winter_temp_manual_mod
};
const double baseline(
wg.base_temperature +
seasonal_temp_mod[season] +

View File

@ -1121,8 +1121,8 @@ int worldfactory::show_worldgen_tab_modselection( const catacurses::window &win,
headers.emplace_back( _( "Mod Load Order" ) );
size_t active_header = 0;
int startsel[2] = {0, 0};
size_t cursel[2] = {0, 0};
std::array<int, 2> startsel = {0, 0};
std::array<size_t, 2> cursel = {0, 0};
size_t iCurrentTab = 0;
size_t sel_top_tab = 0;
std::vector<mod_id> current_tab_mods;

View File

@ -16,6 +16,7 @@
// tests both variants of string_starts_with
template <std::size_t N>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
bool test_string_starts_with( const std::string &s1, const char( &s2 )[N] )
{
CAPTURE( s1, s2, N );
@ -27,6 +28,7 @@ bool test_string_starts_with( const std::string &s1, const char( &s2 )[N] )
// tests both variants of string_ends_with
template <std::size_t N>
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
bool test_string_ends_with( const std::string &s1, const char( &s2 )[N] )
{
CAPTURE( s1, s2, N );
@ -71,7 +73,7 @@ TEST_CASE( "string_ends_with_benchmark", "[.][utility][benchmark]" )
TEST_CASE( "string_ends_with_season_suffix", "[utility]" )
{
constexpr size_t suffix_len = 15;
// NOLINTNEXTLINE(cata-use-mdarray)
// NOLINTNEXTLINE(cata-use-mdarray,modernize-avoid-c-arrays)
constexpr char season_suffix[4][suffix_len] = {
"_season_spring", "_season_summer", "_season_autumn", "_season_winter"
};

View File

@ -175,7 +175,7 @@ TEST_CASE( "monster_special_attack", "[vision][reachability]" )
TEST_CASE( "monster_throwing_sanity_test", "[throwing],[balance]" )
{
float expected_average_damage_at_range[] = { 0, 0, 8.5, 6.5, 5, 3.25 };
std::array<float, 6> expected_average_damage_at_range = { 0, 0, 8.5, 6.5, 5, 3.25 };
clear_map();
map &here = get_map();
restore_on_out_of_scope<time_point> restore_calendar_turn( calendar::turn );

View File

@ -228,7 +228,7 @@ TEST_CASE( "snippet-tag-test" )
* B/C is acid with (follower/non-follower) NPC on it.
*/
static constexpr int height = 5, width = 17;
// NOLINTNEXTLINE(cata-use-mdarray)
// NOLINTNEXTLINE(cata-use-mdarray,modernize-avoid-c-arrays)
static constexpr char setup[height][width + 1] = {
"U ###############",
"V #R#AAA#W# # #C#",

View File

@ -353,8 +353,8 @@ static void do_3d_benchmark(
const int iterations )
{
struct test_grids {
cata::mdarray<float, point_bub_ms> seen_squares[OVERMAP_LAYERS] = {};
cata::mdarray<bool, point_bub_ms> floor_cache[OVERMAP_LAYERS] = {};
std::array<cata::mdarray<float, point_bub_ms>, OVERMAP_LAYERS> seen_squares = {};
std::array<cata::mdarray<bool, point_bub_ms>, OVERMAP_LAYERS> floor_cache = {};
};
std::unique_ptr<test_grids> grids = std::make_unique<test_grids>();
@ -386,12 +386,12 @@ static void do_3d_benchmark(
static void shadowcasting_3d_benchmark( const int iterations )
{
struct test_grids {
cata::mdarray<float, point_bub_ms>
transparency_cache[OVERMAP_LAYERS] = {};
std::array<cata::mdarray<float, point_bub_ms>, OVERMAP_LAYERS> transparency_cache = {};
};
std::unique_ptr<test_grids> grids = std::make_unique<test_grids>();
cata::mdarray<float, point_bub_ms> *transparency_cache = grids->transparency_cache;
std::array<cata::mdarray<float, point_bub_ms>, OVERMAP_LAYERS> &transparency_cache =
grids->transparency_cache;
array_of_grids_of<const float> transparency_caches;
for( int z = -OVERMAP_DEPTH; z <= OVERMAP_HEIGHT; z++ ) {
randomly_fill_transparency( transparency_cache[z + OVERMAP_DEPTH] );
@ -558,7 +558,7 @@ static void run_spot_check( const grid_overlay &test_case, const grid_overlay &e
if( !fov_3d ) {
REQUIRE( test_case.depth() == 1 );
}
level_cache *caches[OVERMAP_LAYERS];
std::array<level_cache *, OVERMAP_LAYERS> caches;
array_of_grids_of<float> seen_squares;
array_of_grids_of<const float> transparency_cache;
array_of_grids_of<const bool> floor_cache;

View File

@ -1015,7 +1015,7 @@ TEST_CASE( "submap_rad_load", "[submap][load]" )
REQUIRE( rad_se == 3 );
REQUIRE( rad_ra == 5 );
int rads[SEEX];
std::array<int, SEEX> rads;
// Also, check we have no other radiation
INFO( "Below is the radiation on the row above and the current row. Unknown values are -1" );
for( int y = 0; y < SEEY; ++y ) {

View File

@ -1,6 +1,7 @@
#include "cata_catch.h"
#include "try_parse_integer.h"
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
TEMPLATE_TEST_CASE( "try_parse_int_simple_parsing", "[try_parse_integer]", int, long, long long )
{
try {
@ -63,6 +64,7 @@ TEMPLATE_TEST_CASE( "try_parse_int_simple_parsing", "[try_parse_integer]", int,
}
}
// NOLINTNEXTLINE(modernize-avoid-c-arrays)
TEMPLATE_TEST_CASE( "try_parse_int_locale_parsing", "[try_parse_integer]", int, long, long long )
{
SECTION( "de_DE" ) {