Codechange: Replace assert_compile macro with static_assert

pull/217/head
Charles Pigott 3 years ago
parent 395a5d9991
commit 860c270c73

@ -31,7 +31,7 @@ public:
uint8 m;
uint8 v;
};
assert_compile(sizeof(MapValue) == 2);
static_assert(sizeof(MapValue) == 2);
/** Helper for creating specialised functions for specific optimisations. */
enum ReadMode {

@ -48,8 +48,8 @@ enum CargoCompanyBits {
CCB_COMPANY_LENGTH = 4, ///< Number of bits of the company field.
};
assert_compile(NUM_CARGO <= (1 << CCB_CARGO_TYPE_LENGTH));
assert_compile(MAX_COMPANIES <= (1 << CCB_COMPANY_LENGTH));
static_assert(NUM_CARGO <= (1 << CCB_CARGO_TYPE_LENGTH));
static_assert(MAX_COMPANIES <= (1 << CCB_COMPANY_LENGTH));
/**

@ -556,8 +556,8 @@ void VehicleCargoList::InvalidateCache()
template<VehicleCargoList::MoveToAction Tfrom, VehicleCargoList::MoveToAction Tto>
uint VehicleCargoList::Reassign(uint max_move, TileOrStationID)
{
assert_compile(Tfrom != MTA_TRANSFER && Tto != MTA_TRANSFER);
assert_compile(Tfrom - Tto == 1 || Tto - Tfrom == 1);
static_assert(Tfrom != MTA_TRANSFER && Tto != MTA_TRANSFER);
static_assert(Tfrom - Tto == 1 || Tto - Tfrom == 1);
max_move = min(this->action_counts[Tfrom], max_move);
this->action_counts[Tfrom] -= max_move;
this->action_counts[Tto] += max_move;

@ -192,7 +192,7 @@ static const CheatEntry _cheats_ui[] = {
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
};
assert_compile(CHT_NUM_CHEATS == lengthof(_cheats_ui));
static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
/** Widget definitions of the cheat GUI. */
static const NWidgetPart _nested_cheat_widgets[] = {

@ -24,9 +24,9 @@
template<typename T, uint S, uint N, typename U> static inline T Extract(U v)
{
/* Check if there are enough bits in v */
assert_compile(N == EnumPropsT<T>::num_bits);
assert_compile(S + N <= sizeof(U) * 8);
assert_compile(EnumPropsT<T>::end <= (1 << N));
static_assert(N == EnumPropsT<T>::num_bits);
static_assert(S + N <= sizeof(U) * 8);
static_assert(EnumPropsT<T>::end <= (1 << N));
U masked = GB(v, S, N);
return IsInsideMM(masked, EnumPropsT<T>::begin, EnumPropsT<T>::end) ? (T)masked : EnumPropsT<T>::invalid;
}

@ -430,7 +430,7 @@ bool IsCommandAllowedWhilePaused(uint32 cmd)
CMDPL_NO_ACTIONS, ///< CMDT_SERVER_SETTING
CMDPL_NO_ACTIONS, ///< CMDT_CHEAT
};
assert_compile(lengthof(command_type_lookup) == CMDT_END);
static_assert(lengthof(command_type_lookup) == CMDT_END);
assert(IsValidCommand(cmd));
return _game_mode == GM_EDITOR || command_type_lookup[_command_proc_table[cmd & CMD_ID_MASK].type] <= _settings_game.construction.command_pause_level;

@ -2438,7 +2438,7 @@ struct CompanyWindow : Window
if (amounts[0] + amounts[1] + amounts[2] + amounts[3] == 0) {
DrawString(r.left, r.right, y, STR_COMPANY_VIEW_VEHICLES_NONE);
} else {
assert_compile(lengthof(amounts) == lengthof(_company_view_vehicle_count_strings));
static_assert(lengthof(amounts) == lengthof(_company_view_vehicle_count_strings));
for (uint i = 0; i < lengthof(amounts); i++) {
if (amounts[i] != 0) {

@ -83,7 +83,7 @@ static const CompanyManagerFaceBitsInfo _cmf_info[] = {
/* CMFV_GLASSES */ { 31, 1, { 2, 2, 2, 2 }, { 0x347, 0x347, 0x3AE, 0x3AE } } ///< Depends on CMFV_HAS_GLASSES
};
/** Make sure the table's size is right. */
assert_compile(lengthof(_cmf_info) == CMFV_END);
static_assert(lengthof(_cmf_info) == CMFV_END);
/**
* Gets the company manager's face bits for the given company manager's face variable

@ -1760,7 +1760,7 @@ struct ConsoleContentCallback : public ContentCallback {
static void OutputContentState(const ContentInfo *const ci)
{
static const char * const types[] = { "Base graphics", "NewGRF", "AI", "AI library", "Scenario", "Heightmap", "Base sound", "Base music", "Game script", "GS library" };
assert_compile(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
static_assert(lengthof(types) == CONTENT_TYPE_END - CONTENT_TYPE_BEGIN);
static const char * const states[] = { "Not selected", "Selected", "Dep Selected", "Installed", "Unknown" };
static const TextColour state_to_colour[] = { CC_COMMAND, CC_INFO, CC_INFO, CC_WHITE, CC_ERROR };

@ -112,7 +112,7 @@ static inline T Align(const T x, uint n)
template <typename T>
static inline T *AlignPtr(T *x, uint n)
{
assert_compile(sizeof(size_t) == sizeof(void *));
static_assert(sizeof(size_t) == sizeof(void *));
return reinterpret_cast<T *>(Align((size_t)x, n));
}

@ -80,7 +80,7 @@ private:
template <class Titem, typename Tindex, size_t Tgrowth_step, size_t Tmax_size, PoolType Tpool_type = PT_NORMAL, bool Tcache = false, bool Tzero = true>
struct Pool : PoolBase {
/* Ensure Tmax_size is within the bounds of Tindex. */
assert_compile((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static_assert((uint64)(Tmax_size - 1) >> 8 * sizeof(Tindex) == 0);
static const size_t MAX_SIZE = Tmax_size; ///< Make template parameter accessible from outside

@ -1258,7 +1258,7 @@ void PrepareUnload(Vehicle *front_v)
assert(front_v->cargo_payment == nullptr);
/* One CargoPayment per vehicle and the vehicle limit equals the
* limit in number of CargoPayments. Can't go wrong. */
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
static_assert(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
assert(CargoPayment::CanAllocateItem());
front_v->cargo_payment = new CargoPayment(front_v);

@ -546,7 +546,7 @@ static EffectInitProc * const _effect_init_procs[] = {
SmokeInit, // EV_BREAKDOWN_SMOKE_AIRCRAFT
SmokeInit, // EV_COPPER_MINE_SMOKE
};
assert_compile(lengthof(_effect_init_procs) == EV_END);
static_assert(lengthof(_effect_init_procs) == EV_END);
/** Functions for controlling effect vehicles at each tick. */
static EffectTickProc * const _effect_tick_procs[] = {
@ -563,7 +563,7 @@ static EffectTickProc * const _effect_tick_procs[] = {
SmokeTick, // EV_BREAKDOWN_SMOKE_AIRCRAFT
SmokeTick, // EV_COPPER_MINE_SMOKE
};
assert_compile(lengthof(_effect_tick_procs) == EV_END);
static_assert(lengthof(_effect_tick_procs) == EV_END);
/** Transparency options affecting the effects. */
static const TransparencyOption _effect_transparency_options[] = {
@ -580,7 +580,7 @@ static const TransparencyOption _effect_transparency_options[] = {
TO_INVALID, // EV_BREAKDOWN_SMOKE_AIRCRAFT
TO_INDUSTRIES, // EV_COPPER_MINE_SMOKE
};
assert_compile(lengthof(_effect_transparency_options) == EV_END);
static_assert(lengthof(_effect_transparency_options) == EV_END);
/**

@ -62,7 +62,7 @@ const uint8 _engine_offsets[4] = {
lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info),
};
assert_compile(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
static_assert(lengthof(_orig_rail_vehicle_info) + lengthof(_orig_road_vehicle_info) + lengthof(_orig_ship_vehicle_info) + lengthof(_orig_aircraft_vehicle_info) == lengthof(_orig_engine_info));
const uint EngineOverrideManager::NUM_DEFAULT_ENGINES = _engine_counts[VEH_TRAIN] + _engine_counts[VEH_ROAD] + _engine_counts[VEH_SHIP] + _engine_counts[VEH_AIRCRAFT];

@ -238,7 +238,7 @@ static const char * const _subdirs[] = {
"game" PATHSEP "library" PATHSEP,
"screenshot" PATHSEP,
};
assert_compile(lengthof(_subdirs) == NUM_SUBDIRS);
static_assert(lengthof(_subdirs) == NUM_SUBDIRS);
const char *_searchpaths[NUM_SEARCHPATHS];
TarList _tar_list[NUM_SUBDIRS];

@ -45,7 +45,7 @@ static const char * GetGamelogRevisionString()
{
/* Allocate a buffer larger than necessary (git revision hash is 40 bytes) to avoid truncation later */
static char gamelog_revision[48] = { 0 };
assert_compile(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
static_assert(lengthof(gamelog_revision) > GAMELOG_REVISION_LENGTH);
if (IsReleasedVersion()) {
return _openttd_revision;
@ -167,7 +167,7 @@ static const char * const la_text[] = {
"emergency savegame",
};
assert_compile(lengthof(la_text) == GLAT_END);
static_assert(lengthof(la_text) == GLAT_END);
/**
* Information about the presence of a Grf at a certain point during gamelog history

@ -304,7 +304,7 @@ static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_N
static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID};
static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID};
assert_compile(lengthof(_num_inds) == ID_END + 1);
static_assert(lengthof(_num_inds) == ID_END + 1);
struct GenerateLandscapeWindow : public Window {
uint widget_id;
@ -1166,7 +1166,7 @@ static const StringID _generation_class_table[] = {
STR_GENERATION_PREPARING_SCRIPT,
STR_GENERATION_PREPARING_GAME
};
assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
static_assert(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
@ -1268,7 +1268,7 @@ void ShowGenerateWorldProgress()
static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
{
static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
static_assert(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
assert(cls < GWP_CLASS_COUNT);
/* Do not run this function if we aren't in a thread */

@ -1681,7 +1681,7 @@ void UpdateCursorSize()
/* Ignore setting any cursor before the sprites are loaded. */
if (GetMaxSpriteID() == 0) return;
assert_compile(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
static_assert(lengthof(_cursor.sprite_seq) == lengthof(_cursor.sprite_pos));
assert(_cursor.sprite_count <= lengthof(_cursor.sprite_seq));
for (uint i = 0; i < _cursor.sprite_count; ++i) {
const Sprite *p = GetSprite(GB(_cursor.sprite_seq[i].sprite, 0, SPRITE_WIDTH), ST_NORMAL);

@ -199,7 +199,7 @@ union Colour {
}
};
assert_compile(sizeof(Colour) == sizeof(uint32));
static_assert(sizeof(Colour) == sizeof(uint32));
/** Available font sizes */

@ -150,7 +150,7 @@ void CheckExternalFiles()
if (sounds_set->GetNumInvalid() != 0) {
add_pos += seprintf(add_pos, last, "Trying to load sound set '%s', but it is incomplete. The game will probably not run correctly until you properly install this set or select another one. See section 4.1 of README.md.\n\nThe following files are corrupted or missing:\n", sounds_set->name.c_str());
assert_compile(SoundsSet::NUM_FILES == 1);
static_assert(SoundsSet::NUM_FILES == 1);
/* No need to loop each file, as long as there is only a single
* sound file. */
add_pos += seprintf(add_pos, last, "\t%s is %s (%s)\n", sounds_set->files->filename, SoundsSet::CheckMD5(sounds_set->files, BASESET_DIR) == MD5File::CR_MISMATCH ? "corrupt" : "missing", sounds_set->files->missing_warning);

@ -248,7 +248,7 @@ CommandCost CmdGoalQuestion(TileIndex tile, DoCommandFlag flags, uint32 p1, uint
CompanyID company = (CompanyID)GB(p1, 16, 8);
ClientID client = (ClientID)GB(p1, 16, 16);
assert_compile(GOAL_QUESTION_BUTTON_COUNT < 29);
static_assert(GOAL_QUESTION_BUTTON_COUNT < 29);
uint32 button_mask = GB(p2, 0, GOAL_QUESTION_BUTTON_COUNT);
byte type = GB(p2, 29, 2);
bool is_client = HasBit(p2, 31);

@ -289,7 +289,7 @@ protected:
/* the colours and cost array of GraphDrawer must accommodate
* both values for cargo and companies. So if any are higher, quit */
assert_compile(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
static_assert(GRAPH_MAX_DATASETS >= (int)NUM_CARGO && GRAPH_MAX_DATASETS >= (int)MAX_COMPANIES);
assert(this->num_vert_lines > 0);
byte grid_colour = _colour_gradient[COLOUR_GREY][4];
@ -1527,7 +1527,7 @@ static NWidgetBase *MakePerformanceDetailPanels(int *biggest_index)
STR_PERFORMANCE_DETAIL_TOTAL_TOOLTIP,
};
assert_compile(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
static_assert(lengthof(performance_tips) == SCORE_END - SCORE_BEGIN);
NWidgetVertical *vert = new NWidgetVertical(NC_EQUALSIZE);
for (int widnum = WID_PRD_SCORE_FIRST; widnum <= WID_PRD_SCORE_LAST; widnum++) {

@ -191,8 +191,8 @@ bool GroundVehicle<T, Type>::IsChainInDepot() const
{
const T *v = this->First();
/* Is the front engine stationary in the depot? */
assert_compile((int)TRANSPORT_RAIL == (int)VEH_TRAIN);
assert_compile((int)TRANSPORT_ROAD == (int)VEH_ROAD);
static_assert((int)TRANSPORT_RAIL == (int)VEH_TRAIN);
static_assert((int)TRANSPORT_ROAD == (int)VEH_ROAD);
if (!IsDepotTypeTile(v->tile, (TransportType)Type) || v->cur_speed != 0) return false;
/* Check whether the rest is also already trying to enter the depot. */

@ -64,7 +64,7 @@ enum HouseZonesBits {
HZB_TOWN_CENTRE,
HZB_END,
};
assert_compile(HZB_END == 5);
static_assert(HZB_END == 5);
DECLARE_POSTFIX_INCREMENT(HouseZonesBits)

@ -145,7 +145,7 @@ enum CargoSuffixInOut {
template <typename TC, typename TS>
static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixType cst, const Industry *ind, IndustryType ind_type, const IndustrySpec *indspec, const TC &cargoes, TS &suffixes)
{
assert_compile(lengthof(cargoes) <= lengthof(suffixes));
static_assert(lengthof(cargoes) <= lengthof(suffixes));
if (indspec->behaviour & INDUSTRYBEH_CARGOTYPES_UNLIMITED) {
/* Reworked behaviour with new many-in-many-out scheme */
@ -2201,8 +2201,8 @@ private:
}
};
assert_compile(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
assert_compile(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, produced_cargo));
static_assert(MAX_CARGOES >= cpp_lengthof(IndustrySpec, accepts_cargo));
int CargoesField::small_height; ///< Height of the header row.
int CargoesField::normal_height; ///< Height of the non-header rows.

@ -811,7 +811,7 @@ void RunTileLoop()
static const uint32 feedbacks[] = {
0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8, 0x4004B2, 0x800B87
};
assert_compile(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
static_assert(lengthof(feedbacks) == 2 * MAX_MAP_SIZE_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
const uint32 feedback = feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];
/* We update every tile every 256 ticks, so divide the map size by 2^8 = 256 */

@ -86,7 +86,7 @@ struct LanguagePackHeader {
}
};
/** Make sure the size is right. */
assert_compile(sizeof(LanguagePackHeader) % 4 == 0);
static_assert(sizeof(LanguagePackHeader) % 4 == 0);
/** Metadata about a single language. */
struct LanguageMetadata : public LanguagePackHeader {

@ -454,7 +454,7 @@ static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
EndContainer()
};
assert_compile(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
static_assert(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
lengthof(LinkGraphOverlay::LINK_COLOURS) - 1);
static WindowDesc _linkgraph_legend_desc(

@ -24,7 +24,7 @@ struct Tile {
byte m5; ///< General purpose
};
assert_compile(sizeof(Tile) == 8);
static_assert(sizeof(Tile) == 8);
/**
* Data that is stored per tile. Also used Tile for this.

@ -67,7 +67,7 @@ public:
FixedSizeArray()
{
/* Ensure the size won't overflow. */
assert_compile(C < (SIZE_MAX - HeaderSize) / Tsize);
static_assert(C < (SIZE_MAX - HeaderSize) / Tsize);
/* allocate block for header + items (don't construct items) */
data = (T*)((MallocT<byte>(HeaderSize + C * Tsize)) + HeaderSize);

@ -681,7 +681,7 @@ struct TooltipsWindow : public Window
{
this->parent = parent;
this->string_id = str;
assert_compile(sizeof(this->params[0]) == sizeof(params[0]));
static_assert(sizeof(this->params[0]) == sizeof(params[0]));
assert(paramcount <= lengthof(this->params));
if (paramcount > 0) memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
this->paramcount = paramcount;

@ -83,7 +83,7 @@ static const char * const _music_file_names[] = {
"ezy_0", "ezy_1", "ezy_2", "ezy_3", "ezy_4", "ezy_5", "ezy_6", "ezy_7", "ezy_8", "ezy_9",
};
/** Make sure we aren't messing things up. */
assert_compile(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
static_assert(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
/* static */ const char * const *BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names = _music_file_names;

@ -210,7 +210,7 @@ static inline bool SetNoDelay(SOCKET d)
}
/* Make sure these structures have the size we expect them to be */
assert_compile(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
assert_compile(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
static_assert(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes.
static_assert(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes.
#endif /* NETWORK_CORE_OS_ABSTRACTION_H */

@ -18,10 +18,10 @@
#include "../../safeguards.h"
/* Make sure that these enums match. */
assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL);
assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN);
assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT);
assert_compile((int)CRR_END == (int)ADMIN_CRR_END);
static_assert((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL);
static_assert((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN);
static_assert((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT);
static_assert((int)CRR_END == (int)ADMIN_CRR_END);
/**
* Create the admin handler for the given socket.

@ -43,7 +43,7 @@ bool _ddc_fastforward = true;
#endif /* DEBUG_DUMP_COMMANDS */
/** Make sure both pools have the same size. */
assert_compile(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE);
static_assert(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE);
/** The pool with client information. */
NetworkClientInfoPool _networkclientinfo_pool("NetworkClientInfo");
@ -80,8 +80,8 @@ uint8 _network_advertise_retries; ///< The number of advertisement retries w
CompanyMask _network_company_passworded; ///< Bitmask of the password status of all companies.
/* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */
assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
static_assert((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE);
static_assert((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH);
extern NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket
extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket
@ -322,7 +322,7 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err)
STR_NETWORK_ERROR_CLIENT_TIMEOUT_MAP,
STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN,
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL;
@ -920,7 +920,7 @@ void NetworkGameLoop()
if (*p == ' ') p++;
cp = CallocT<CommandPacket>(1);
int company;
assert_compile(sizeof(cp->text) == 128);
static_assert(sizeof(cp->text) == 128);
int ret = sscanf(p, "%x; %x; %x; %x; %x; %x; %x; \"%127[^\"]\"", &next_date, &next_date_fract, &company, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text);
/* There are 8 pieces of data to read, however the last is a
* string that might or might not exist. Ignore it if that

@ -54,7 +54,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = {
ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_GAMESCRIPT
};
/** Sanity check. */
assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
static_assert(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END);
/**
* Create a new socket for the server side of the admin network.
@ -86,7 +86,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler()
bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS;
/* We can't go over the MAX_ADMINS limit here. However, if we accept
* the connection, there has to be space in the pool. */
assert_compile(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS);
assert(!accept || ServerNetworkAdminSocketHandler::CanAllocateItem());
return accept;
}

@ -31,7 +31,7 @@
/** The draw buffer must be able to contain the chat message, client name and the "[All]" message,
* some spaces and possible translations of [All] to other languages. */
assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40);
/** Spacing between chat lines. */
static const uint NETWORK_CHAT_LINE_SPACING = 3;

@ -324,7 +324,7 @@ const char *_network_join_server_password = nullptr;
const char *_network_join_company_password = nullptr;
/** Make sure the server ID length is the same as a md5 hash. */
assert_compile(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1);
/***********
* Sending functions
@ -682,7 +682,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p
STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP
STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN
};
assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END);
static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END);
NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8();

@ -41,9 +41,9 @@ DECLARE_POSTFIX_INCREMENT(ClientID)
static ClientID _network_client_id = CLIENT_ID_FIRST;
/** Make very sure the preconditions given in network_type.h are actually followed */
assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS);
static_assert(MAX_CLIENT_SLOTS > MAX_CLIENTS);
/** Yes... */
assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS);
/** The pool with clients. */
NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket");
@ -223,7 +223,7 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo
/* The Socket and Info pools need to be the same in size. After all,
* each Socket will be associated with at most one Info object. As
* such if the Socket was allocated the Info object can as well. */
assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
static_assert(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE);
}
/**
@ -311,7 +311,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta
/* We can't go over the MAX_CLIENTS limit here. However, the
* pool must have place for all clients and ourself. */
assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1);
assert(!accept || ServerNetworkGameSocketHandler::CanAllocateItem());
return accept;
}
@ -1962,7 +1962,7 @@ void NetworkServerShowStatusToConsole()
"ready",
"active"
};
assert_compile(lengthof(stat_str) == NetworkClientSocket::STATUS_END);
static_assert(lengthof(stat_str) == NetworkClientSocket::STATUS_END);
for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) {
NetworkClientInfo *ci = cs->GetInfo();

@ -503,7 +503,7 @@ static StringID TTDPStringIDToOTTDStringIDMapping(StringID str)
assert(!IsInsideMM(str, 0xD000, 0xD7FF));
#define TEXTID_TO_STRINGID(begin, end, stringid, stringend) \
assert_compile(stringend - stringid == end - begin); \
static_assert(stringend - stringid == end - begin); \
if (str >= begin && str <= end) return str + (stringid - begin)
/* We have some changes in our cargo strings, resulting in some missing. */
@ -8728,7 +8728,7 @@ GRFFile::GRFFile(const GRFConfig *config)
/* Copy the initial parameter list
* 'Uninitialised' parameters are zeroed as that is their default value when dynamically creating them. */
assert_compile(lengthof(this->param) == lengthof(config->param) && lengthof(this->param) == 0x80);
static_assert(lengthof(this->param) == lengthof(config->param) && lengthof(this->param) == 0x80);
assert(config->num_params <= lengthof(config->param));
this->param_end = config->num_params;

@ -37,7 +37,7 @@ AirportTileOverrideManager _airporttile_mngr(NEW_AIRPORTTILE_OFFSET, NUM_AIRPORT
{
/* should be assert(gfx < lengthof(tiles)), but that gives compiler warnings
* since it's always true if the following holds: */
assert_compile(MAX_UVALUE(StationGfx) + 1 == lengthof(tiles));
static_assert(MAX_UVALUE(StationGfx) + 1 == lengthof(tiles));
return &AirportTileSpec::tiles[gfx];
}

@ -1313,7 +1313,7 @@ void FillNewGRFVehicleCache(const Vehicle *v)
{ 0x43, NCVV_COMPANY_INFORMATION },
{ 0x4D, NCVV_POSITION_IN_VEHICLE },
};
assert_compile(NCVV_END == lengthof(cache_entries));
static_assert(NCVV_END == lengthof(cache_entries));
/* Resolve all the variables, so their caches are set. */
for (size_t i = 0; i < lengthof(cache_entries); i++) {

@ -431,9 +431,9 @@ uint32 Station::GetNewGRFVariable(const ResolverObject &object, byte variable, b
case 0x64: return ge->HasVehicleEverTriedLoading() ? ge->last_speed | (ge->last_age << 8) : 0xFF00;
case 0x65: return GB(ge->status, GoodsEntry::GES_ACCEPTANCE, 1) << 3;
case 0x69: {
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH);
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH);
assert_compile((int)GoodsEntry::GES_EVER_ACCEPTED + 3 == (int)GoodsEntry::GES_ACCEPTED_BIGTICK);
static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 1 == (int)GoodsEntry::GES_LAST_MONTH);
static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 2 == (int)GoodsEntry::GES_CURRENT_MONTH);
static_assert((int)GoodsEntry::GES_EVER_ACCEPTED + 3 == (int)GoodsEntry::GES_ACCEPTED_BIGTICK);
return GB(ge->status, GoodsEntry::GES_EVER_ACCEPTED, 4);
}
}

@ -228,6 +228,6 @@ struct PersistentStorage : PersistentStorageArray<int32, 256>, PersistentStorage
}
};
assert_compile(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage));
static_assert(cpp_lengthof(OldPersistentStorage, storage) <= cpp_lengthof(PersistentStorage, storage));
#endif /* NEWGRF_STORAGE_H */

@ -244,7 +244,7 @@ static NewsTypeData _news_type_data[] = {
NewsTypeData("news_display.general", 60, SND_BEGIN ), ///< NT_GENERAL
};
assert_compile(lengthof(_news_type_data) == NT_END);
static_assert(lengthof(_news_type_data) == NT_END);
/**
* Return the news display option.

@ -424,7 +424,7 @@ struct AfterNewGRFScan : NewGRFScanCallback {
{
/* Visual C++ 2015 fails compiling this line (AfterNewGRFScan::generation_seed undefined symbol)
* if it's placed outside a member function, directly in the struct body. */
assert_compile(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
static_assert(sizeof(generation_seed) == sizeof(_settings_game.game_creation.generation_seed));
}
virtual void OnNewGRFsScanned()

@ -34,8 +34,8 @@
/* DestinationID must be at least as large as every these below, because it can
* be any of them
*/
assert_compile(sizeof(DestinationID) >= sizeof(DepotID));
assert_compile(sizeof(DestinationID) >= sizeof(StationID));
static_assert(sizeof(DestinationID) >= sizeof(DepotID));
static_assert(sizeof(DestinationID) >= sizeof(StationID));
OrderPool _order_pool("Order");
INSTANTIATE_POOL_METHODS(Order)

@ -62,7 +62,7 @@ enum SignalOffsets {
*/
void ResetRailTypes()
{
assert_compile(lengthof(_original_railtypes) <= lengthof(_railtypes));
static_assert(lengthof(_original_railtypes) <= lengthof(_railtypes));
uint i = 0;
for (; i < lengthof(_original_railtypes); i++) _railtypes[i] = _original_railtypes[i];

@ -61,7 +61,7 @@ RoadTypes _roadtypes_type;
*/
void ResetRoadTypes()
{
assert_compile(lengthof(_original_roadtypes) <= lengthof(_roadtypes));
static_assert(lengthof(_original_roadtypes) <= lengthof(_roadtypes));
uint i = 0;
for (; i < lengthof(_original_roadtypes); i++) _roadtypes[i] = _original_roadtypes[i];

@ -60,7 +60,7 @@ static const uint16 _roadveh_full_adder[] = {
0, 16, 16, 0, 8, 8, 8, 8,
0, 0, 0, 8, 8, 8, 8
};
assert_compile(lengthof(_roadveh_images) == lengthof(_roadveh_full_adder));
static_assert(lengthof(_roadveh_images) == lengthof(_roadveh_full_adder));
template <>
bool IsValidImageIndex<VEH_ROAD>(uint8 image_index)

@ -2182,7 +2182,7 @@ bool AfterLoadGame()
for (iter = st->loading_vehicles.begin(); iter != st->loading_vehicles.end(); ++iter) {
/* There are always as many CargoPayments as Vehicles. We need to make the
* assert() in Pool::GetNew() happy by calling CanAllocateItem(). */
assert_compile(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
static_assert(CargoPaymentPool::MAX_SIZE == VehiclePool::MAX_SIZE);
assert(CargoPayment::CanAllocateItem());
Vehicle *v = *iter;
if (v->cargo_payment == nullptr) v->cargo_payment = new CargoPayment(v);

@ -100,7 +100,7 @@ static const SaveLoad * const _glog_desc[] = {
_glog_emergency_desc,
};
assert_compile(lengthof(_glog_desc) == GLCT_END);
static_assert(lengthof(_glog_desc) == GLCT_END);
static void Load_GLOG_common(LoggedAction *&gamelog_action, uint &gamelog_actions)
{

@ -243,7 +243,7 @@ static inline bool CheckOldSavegameType(FILE *f, char *temp, const char *last, u
static SavegameType DetermineOldSavegameType(FILE *f, char *title, const char *last)
{
assert_compile(TTD_HEADER_SIZE >= TTO_HEADER_SIZE);
static_assert(TTD_HEADER_SIZE >= TTO_HEADER_SIZE);
char temp[TTD_HEADER_SIZE] = "Unknown";
SavegameType type = SGT_TTO;

@ -93,7 +93,7 @@ struct OldChunks {
};
/* If it fails, check lines above.. */
assert_compile(sizeof(TileIndex) == 4);
static_assert(sizeof(TileIndex) == 4);
extern uint _bump_assert_value;
byte ReadByte(LoadgameState *ls);

@ -1142,7 +1142,7 @@ static size_t ReferenceToInt(const void *obj, SLRefType rt)
*/
static void *IntToReference(size_t index, SLRefType rt)
{
assert_compile(sizeof(size_t) <= sizeof(void *));
static_assert(sizeof(size_t) <= sizeof(void *));
assert(_sl.action == SLA_PTRS);

@ -81,7 +81,7 @@ PACK(struct BitmapFileHeader {
uint32 reserved;
uint32 off_bits;
});
assert_compile(sizeof(BitmapFileHeader) == 14);
static_assert(sizeof(BitmapFileHeader) == 14);
/** BMP Info Header (stored in little endian) */
struct BitmapInfoHeader {
@ -90,13 +90,13 @@ struct BitmapInfoHeader {
uint16 planes, bitcount;
uint32 compression, sizeimage, xpels, ypels, clrused, clrimp;
};
assert_compile(sizeof(BitmapInfoHeader) == 40);
static_assert(sizeof(BitmapInfoHeader) == 40);
/** Format of palette data in BMP header */
struct RgbQuad {
byte blue, green, red, reserved;
};
assert_compile(sizeof(RgbQuad) == 4);
static_assert(sizeof(RgbQuad) == 4);
/**
* Generic .BMP writer
@ -419,7 +419,7 @@ struct PcxHeader {
uint16 height;
byte filler[54];
};
assert_compile(sizeof(PcxHeader) == 128);
static_assert(sizeof(PcxHeader) == 128);
/**
* Generic .PCX file image writer.

@ -1783,7 +1783,7 @@ static const StringID _game_settings_restrict_dropdown[] = {
STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
};
assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
static_assert(lengthof(_game_settings_restrict_dropdown) == RM_END);
/** Warnings about hidden search results. */
enum WarnHiddenResult {

@ -25,7 +25,7 @@ static const uint SIG_TBD_SIZE = 256; ///< number of intersections - open nod
static const uint SIG_GLOB_SIZE = 128; ///< number of open blocks (block can be opened more times until detected)
static const uint SIG_GLOB_UPDATE = 64; ///< how many items need to be in _globset to force update
assert_compile(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
static_assert(SIG_GLOB_UPDATE <= SIG_GLOB_SIZE);
/** incidating trackbits with given enterdir */
static const TrackBits _enterdir_to_trackbits[DIAGDIR_END] = {

@ -188,7 +188,7 @@ static void StartSound(SoundID sound_id, float pan, uint volume)
static const byte _vol_factor_by_zoom[] = {255, 255, 255, 190, 134, 87};
assert_compile(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_COUNT);
static_assert(lengthof(_vol_factor_by_zoom) == ZOOM_LVL_COUNT);
static const byte _sound_base_vol[] = {
128, 90, 128, 128, 128, 128, 128, 128,

@ -618,9 +618,9 @@ void DupSprite(SpriteID old_spr, SpriteID new_spr)
static const size_t S_FREE_MASK = sizeof(size_t) - 1;
/* to make sure nobody adds things to MemBlock without checking S_FREE_MASK first */
assert_compile(sizeof(MemBlock) == sizeof(size_t));
static_assert(sizeof(MemBlock) == sizeof(size_t));
/* make sure it's a power of two */
assert_compile((sizeof(size_t) & (sizeof(size_t) - 1)) == 0);
static_assert((sizeof(size_t) & (sizeof(size_t) - 1)) == 0);
static inline MemBlock *NextBlock(MemBlock *block)
{

@ -348,14 +348,12 @@ typedef unsigned char byte;
# define PERSONAL_DIR ""
#endif
#define assert_compile(expr) static_assert(expr, #expr)
/* Check if the types have the bitsizes like we are using them */
assert_compile(sizeof(uint64) == 8);
assert_compile(sizeof(uint32) == 4);
assert_compile(sizeof(uint16) == 2);
assert_compile(sizeof(uint8) == 1);
assert_compile(SIZE_MAX >= UINT32_MAX);
static_assert(sizeof(uint64) == 8);
static_assert(sizeof(uint32) == 4);
static_assert(sizeof(uint16) == 2);
static_assert(sizeof(uint8) == 1);
static_assert(SIZE_MAX >= UINT32_MAX);
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923

@ -84,7 +84,7 @@ public:
offset(0),
num_param(Tnum_param)
{
assert_compile(sizeof(data[0]) == sizeof(uint64));
static_assert(sizeof(data[0]) == sizeof(uint64));
}
/**

@ -406,7 +406,7 @@ extern const AirportSpec _origin_airport_specs[] = {
AS_GENERIC(&_airportfta_oilrig, nullptr, _default_airports_rotation, 0, nullptr, 0, 1, 1, 0, 4, 0, 0, 0, ATP_TTDP_OILRIG, APC_HELIPORT, STR_NULL, 0, false),
};
assert_compile(NEW_AIRPORT_OFFSET == lengthof(_origin_airport_specs));
static_assert(NEW_AIRPORT_OFFSET == lengthof(_origin_airport_specs));
const AirportSpec AirportSpec::dummy = AS_GENERIC(&_airportfta_dummy, nullptr, _default_airports_rotation, 0, nullptr, 0, 0, 0, 0, 0, MIN_YEAR, MIN_YEAR, 0, ATP_TTDP_LARGE, APC_BEGIN, STR_NULL, 0, false);

@ -104,7 +104,7 @@ static const AirportTileSpec _origin_airporttile_specs[] = {
AT(3, 1), // APT_GRASS_FENCE_NE_FLAG_2
};
assert_compile(NEW_AIRPORTTILE_OFFSET == lengthof(_origin_airporttile_specs));
static_assert(NEW_AIRPORTTILE_OFFSET == lengthof(_origin_airporttile_specs));
#undef AT_NOANIM
#undef AT

@ -620,4 +620,4 @@ static const NIFeature * const _nifeatures[] = {
&_nif_tramtype, // GSF_TRAMTYPES
&_nif_town, // GSF_FAKE_TOWNS
};
assert_compile(lengthof(_nifeatures) == GSF_FAKE_END);
static_assert(lengthof(_nifeatures) == GSF_FAKE_END);

@ -80,4 +80,4 @@ extern const PriceBaseSpec _price_base_specs[] = {
{ 100, PCAT_RUNNING, GSF_END, PR_STATION_VALUE }, ///< PR_INFRASTRUCTURE_STATION
{ 5000, PCAT_RUNNING, GSF_END, PR_BUILD_STATION_AIRPORT}, ///< PR_INFRASTRUCTURE_AIRPORT
};
assert_compile(lengthof(_price_base_specs) == PR_END);
static_assert(lengthof(_price_base_specs) == PR_END);

@ -1545,11 +1545,11 @@ enum SpriteMasks {
PALETTE_MASK = MAX_PALETTES - 1, ///< The mask for the auxiliary sprite (the one that takes care of recolouring)
};
assert_compile( (1 << TRANSPARENT_BIT & SPRITE_MASK) == 0 );
assert_compile( (1 << RECOLOUR_BIT & SPRITE_MASK) == 0 );
assert_compile( TRANSPARENT_BIT != RECOLOUR_BIT );
assert_compile( (1 << TRANSPARENT_BIT & PALETTE_MASK) == 0);
assert_compile( (1 << RECOLOUR_BIT & PALETTE_MASK) == 0 );
static_assert( (1 << TRANSPARENT_BIT & SPRITE_MASK) == 0 );
static_assert( (1 << RECOLOUR_BIT & SPRITE_MASK) == 0 );
static_assert( TRANSPARENT_BIT != RECOLOUR_BIT );
static_assert( (1 << TRANSPARENT_BIT & PALETTE_MASK) == 0);
static_assert( (1 << RECOLOUR_BIT & PALETTE_MASK) == 0 );
static const PaletteID PAL_NONE = 0;

@ -988,7 +988,7 @@ static const DrawTileSprites _station_display_datas_waypoint[] = {
/* Default waypoint is also drawn as fallback for NewGRF waypoints.
* As these are drawn/build like stations, they may use the same number of layouts. */
assert_compile(lengthof(_station_display_datas_rail) == lengthof(_station_display_datas_waypoint));
static_assert(lengthof(_station_display_datas_rail) == lengthof(_station_display_datas_waypoint));
static const DrawTileSprites * const _station_display_datas[] = {
_station_display_datas_rail,

@ -1788,7 +1788,7 @@ static const DrawBuildingsTileStruct _town_draw_tile_data[] = {
};
#undef M
/** Make sure we have the right number of elements: 4 variants * 4 build stages for each house */
assert_compile(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
static_assert(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4);
/**
* Describes the data that defines each house in the game
@ -2276,4 +2276,4 @@ static const HouseSpec _original_house_specs[] = {
#undef MS
/** Make sure we have the right number of elements: one entry for each house */
assert_compile(lengthof(_original_house_specs) == NEW_HOUSE_OFFSET);
static_assert(lengthof(_original_house_specs) == NEW_HOUSE_OFFSET);

@ -63,6 +63,6 @@ static const byte _wagon_full_adder[] = {
32, 32
};
assert_compile(lengthof(_engine_sprite_base) == lengthof(_engine_sprite_and));
assert_compile(lengthof(_engine_sprite_base) == lengthof(_engine_sprite_add));
assert_compile(lengthof(_engine_sprite_base) == lengthof(_wagon_full_adder));
static_assert(lengthof(_engine_sprite_base) == lengthof(_engine_sprite_and));
static_assert(lengthof(_engine_sprite_base) == lengthof(_engine_sprite_add));
static_assert(lengthof(_engine_sprite_base) == lengthof(_wagon_full_adder));

@ -390,7 +390,7 @@ const char *GetTextfile(TextfileType type, Subdirectory dir, const char *filenam
"changelog",
"license",
};
assert_compile(lengthof(prefixes) == TFT_END);
static_assert(lengthof(prefixes) == TFT_END);
const char *prefix = prefixes[type];

@ -1877,7 +1877,7 @@ CommandCost CmdFoundTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
static const byte price_mult[][TSZ_RANDOM + 1] = {{ 15, 25, 40, 25 }, { 20, 35, 55, 35 }};
/* multidimensional arrays have to have defined length of non-first dimension */
assert_compile(lengthof(price_mult[0]) == 4);
static_assert(lengthof(price_mult[0]) == 4);
CommandCost cost(EXPENSES_OTHER, _price[PR_BUILD_TOWN]);
byte mult = price_mult[city][size];

@ -1935,7 +1935,7 @@ static PaletteID GetEngineColourMap(EngineID engine_type, CompanyID company, Eng
uint16 callback = GetVehicleCallback(CBID_VEHICLE_COLOUR_MAPPING, 0, 0, engine_type, v);
/* Failure means "use the default two-colour" */
if (callback != CALLBACK_FAILED) {
assert_compile(PAL_NONE == 0); // Returning 0x4000 (resp. 0xC000) coincidences with default value (PAL_NONE)
static_assert(PAL_NONE == 0); // Returning 0x4000 (resp. 0xC000) coincidences with default value (PAL_NONE)
map = GB(callback, 0, 14);
/* If bit 14 is set, then the company colours are applied to the
* map else it's returned as-is. */
@ -2552,9 +2552,9 @@ void Vehicle::ShowVisualEffect() const
} else {
effect_model = (VisualEffectSpawnModel)GB(v->vcache.cached_vis_effect, VE_TYPE_START, VE_TYPE_COUNT);
assert(effect_model != (VisualEffectSpawnModel)VE_TYPE_DEFAULT); // should have been resolved by UpdateVisualEffect
assert_compile((uint)VESM_STEAM == (uint)VE_TYPE_STEAM);
assert_compile((uint)VESM_DIESEL == (uint)VE_TYPE_DIESEL);
assert_compile((uint)VESM_ELECTRIC == (uint)VE_TYPE_ELECTRIC);
static_assert((uint)VESM_STEAM == (uint)VE_TYPE_STEAM);
static_assert((uint)VESM_DIESEL == (uint)VE_TYPE_DIESEL);
static_assert((uint)VESM_ELECTRIC == (uint)VE_TYPE_ELECTRIC);
}
/* Show no smoke when:

@ -2009,10 +2009,10 @@ void ShowVehicleListWindow(CompanyID company, VehicleType vehicle_type, TileInde
/* Unified vehicle GUI - Vehicle Details Window */
assert_compile(WID_VD_DETAILS_CARGO_CARRIED == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_CARGO );
assert_compile(WID_VD_DETAILS_TRAIN_VEHICLES == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_INFO );
assert_compile(WID_VD_DETAILS_CAPACITY_OF_EACH == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_CAPACITY);
assert_compile(WID_VD_DETAILS_TOTAL_CARGO == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_TOTALS );
static_assert(WID_VD_DETAILS_CARGO_CARRIED == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_CARGO );
static_assert(WID_VD_DETAILS_TRAIN_VEHICLES == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_INFO );
static_assert(WID_VD_DETAILS_CAPACITY_OF_EACH == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_CAPACITY);
static_assert(WID_VD_DETAILS_TOTAL_CARGO == WID_VD_DETAILS_CARGO_CARRIED + TDW_TAB_TOTALS );
/** Vehicle details widgets (other than train). */
static const NWidgetPart _nested_nontrain_vehicle_details_widgets[] = {
@ -2554,10 +2554,10 @@ static WindowDesc _train_view_desc(
/* Just to make sure, nobody has changed the vehicle type constants, as we are
using them for array indexing in a number of places here. */
assert_compile(VEH_TRAIN == 0);
assert_compile(VEH_ROAD == 1);
assert_compile(VEH_SHIP == 2);
assert_compile(VEH_AIRCRAFT == 3);
static_assert(VEH_TRAIN == 0);
static_assert(VEH_ROAD == 1);
static_assert(VEH_SHIP == 2);
static_assert(VEH_AIRCRAFT == 3);
/** Zoom levels for vehicle views indexed by vehicle type. */
static const ZoomLevel _vehicle_view_zoom_levels[] = {

@ -25,7 +25,7 @@ uint32 VehicleListIdentifier::Pack() const
assert(this->vtype < (1 << 2));
assert(this->index < (1 << 20));
assert(this->type < VLT_END);
assert_compile(VLT_END <= (1 << 3));
static_assert(VLT_END <= (1 << 3));
return c << 28 | this->type << 23 | this->vtype << 26 | this->index;
}

@ -227,7 +227,7 @@ static void DedicatedHandleKeyInput()
if (fgets(input_line, lengthof(input_line), stdin) == nullptr) return;
#else
/* Handle console input, and signal console thread, it can accept input again */
assert_compile(lengthof(_win_console_thread_buffer) <= lengthof(input_line));
static_assert(lengthof(_win_console_thread_buffer) <= lengthof(input_line));
strecpy(input_line, _win_console_thread_buffer, lastof(input_line));
SetEvent(_hWaitForInputHandling);
#endif

@ -20,7 +20,7 @@
#include "safeguards.h"
#ifdef _SQ64
assert_compile((sizeof(ParentSpriteToDraw) % 16) == 0);
static_assert((sizeof(ParentSpriteToDraw) % 16) == 0);
# define LOAD_128 _mm_load_si128
#else
# define LOAD_128 _mm_loadu_si128

Loading…
Cancel
Save