diff options
Diffstat (limited to 'src')
77 files changed, 133 insertions, 135 deletions
diff --git a/src/blitter/32bpp_sse2.hpp b/src/blitter/32bpp_sse2.hpp index 4103eed48..12105516f 100644 --- a/src/blitter/32bpp_sse2.hpp +++ b/src/blitter/32bpp_sse2.hpp @@ -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 { diff --git a/src/cargomonitor.h b/src/cargomonitor.h index 9a6a0c44d..31053c46c 100644 --- a/src/cargomonitor.h +++ b/src/cargomonitor.h @@ -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)); /** diff --git a/src/cargopacket.cpp b/src/cargopacket.cpp index 08b72ec46..eafab6880 100644 --- a/src/cargopacket.cpp +++ b/src/cargopacket.cpp @@ -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; diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index 7290414c0..344e15e63 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -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[] = { diff --git a/src/cmd_helper.h b/src/cmd_helper.h index a505c1fd8..ceb4d4bd9 100644 --- a/src/cmd_helper.h +++ b/src/cmd_helper.h @@ -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; } diff --git a/src/command.cpp b/src/command.cpp index 9fbc6cae6..de5f8397d 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -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; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 14567b1de..e0bafda87 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -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) { diff --git a/src/company_manager_face.h b/src/company_manager_face.h index 2f16656d5..fe6365a12 100644 --- a/src/company_manager_face.h +++ b/src/company_manager_face.h @@ -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 diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index e87232b36..d2066df2b 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -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 }; diff --git a/src/core/math_func.hpp b/src/core/math_func.hpp index d36dc55f9..55061066a 100644 --- a/src/core/math_func.hpp +++ b/src/core/math_func.hpp @@ -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)); } diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp index 9e6fc8fec..e847dfbb7 100644 --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -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 diff --git a/src/economy.cpp b/src/economy.cpp index 3af220d96..c73012096 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -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); diff --git a/src/effectvehicle.cpp b/src/effectvehicle.cpp index f11a92e5d..82054acc6 100644 --- a/src/effectvehicle.cpp +++ b/src/effectvehicle.cpp @@ -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); /** diff --git a/src/engine.cpp b/src/engine.cpp index 311a936ed..68e44c8ae 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -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]; diff --git a/src/fileio.cpp b/src/fileio.cpp index e294a8292..e409d9d2a 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -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]; diff --git a/src/gamelog.cpp b/src/gamelog.cpp index 156dfe628..d1a9ab038 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -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 diff --git a/src/genworld_gui.cpp b/src/genworld_gui.cpp index 154097e72..4f1524f8a 100644 --- a/src/genworld_gui.cpp +++ b/src/genworld_gui.cpp @@ -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 */ diff --git a/src/gfx.cpp b/src/gfx.cpp index 8027dad26..c0a2efc31 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -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); diff --git a/src/gfx_type.h b/src/gfx_type.h index ab802c45e..3b9f04d9e 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -199,7 +199,7 @@ union Colour { } }; -assert_compile(sizeof(Colour) == sizeof(uint32)); +static_assert(sizeof(Colour) == sizeof(uint32)); /** Available font sizes */ diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 95c954095..f4d1a7b03 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -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); diff --git a/src/goal.cpp b/src/goal.cpp index 02ec85255..954d2f7bf 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -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); diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index d454d8a9b..3d6d2a3a3 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -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++) { diff --git a/src/ground_vehicle.cpp b/src/ground_vehicle.cpp index 74095fc57..0f1915c96 100644 --- a/src/ground_vehicle.cpp +++ b/src/ground_vehicle.cpp @@ -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. */ diff --git a/src/house.h b/src/house.h index 7d3b8dc5e..f381fc1e0 100644 --- a/src/house.h +++ b/src/house.h @@ -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) diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index caa18c8e3..ed770ed04 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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. diff --git a/src/landscape.cpp b/src/landscape.cpp index 33afd5163..6dddbfd70 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -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 */ diff --git a/src/language.h b/src/language.h index aec5d9c85..269b22c24 100644 --- a/src/language.h +++ b/src/language.h @@ -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 { diff --git a/src/linkgraph/linkgraph_gui.cpp b/src/linkgraph/linkgraph_gui.cpp index b5fbc50ff..fa4002e2b 100644 --- a/src/linkgraph/linkgraph_gui.cpp +++ b/src/linkgraph/linkgraph_gui.cpp @@ -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( diff --git a/src/map_type.h b/src/map_type.h index 453186d88..f34f137c6 100644 --- a/src/map_type.h +++ b/src/map_type.h @@ -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. diff --git a/src/misc/fixedsizearray.hpp b/src/misc/fixedsizearray.hpp index db6c7808b..a36a810f2 100644 --- a/src/misc/fixedsizearray.hpp +++ b/src/misc/fixedsizearray.hpp @@ -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); diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index f7345416c..17a460bf5 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -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; diff --git a/src/music.cpp b/src/music.cpp index 131651e55..66ac2b511 100644 --- a/src/music.cpp +++ b/src/music.cpp @@ -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; diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 8aa072aef..836cfeae8 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -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 */ diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 98227e019..c72583f55 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -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. diff --git a/src/network/network.cpp b/src/network/network.cpp index da341f253..907f15842 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -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 diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index f304740a6..007722ec6 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -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; } diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 07348c048..e0f3bf57c 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -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; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index dc593eacd..eb5c4cbb3 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -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(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c82c51cfd..1454991a8 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -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(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 097e68ae2..2663a3470 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -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; diff --git a/src/newgrf_airporttiles.cpp b/src/newgrf_airporttiles.cpp index 3059174a8..a437fb596 100644 --- a/src/newgrf_airporttiles.cpp +++ b/src/newgrf_airporttiles.cpp @@ -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]; } diff --git a/src/newgrf_engine.cpp b/src/newgrf_engine.cpp index db2f5ac43..efc9873af 100644 --- a/src/newgrf_engine.cpp +++ b/src/newgrf_engine.cpp @@ -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++) { diff --git a/src/newgrf_station.cpp b/src/newgrf_station.cpp index 19f32bd75..d607f8bd0 100644 --- a/src/newgrf_station.cpp +++ b/src/newgrf_station.cpp @@ -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); } } diff --git a/src/newgrf_storage.h b/src/newgrf_storage.h index 61206a587..ff322c944 100644 --- a/src/newgrf_storage.h +++ b/src/newgrf_storage.h @@ -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 */ diff --git a/src/news_gui.cpp b/src/news_gui.cpp index a3f73d729..e98f76da9 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -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. diff --git a/src/openttd.cpp b/src/openttd.cpp index 33f65314d..89cc15c35 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -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() diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index c9fa91989..b8ba7ab90 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -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) diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 162fe9779..a71441532 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -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]; diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index b8aee88d6..bac6f8e1f 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -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]; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 261af7042..0e490fbc2 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -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) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 4eab99c88..329152ab2 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -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); diff --git a/src/saveload/gamelog_sl.cpp b/src/saveload/gamelog_sl.cpp index 576bfa5bc..6bff1b154 100644 --- a/src/saveload/gamelog_sl.cpp +++ b/src/saveload/gamelog_sl.cpp @@ -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) { diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp index 5dac33777..0c2c7f80b 100644 --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -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; diff --git a/src/saveload/oldloader.h b/src/saveload/oldloader.h index fcc7be4be..1600a9ac2 100644 --- a/src/saveload/oldloader.h +++ b/src/saveload/oldloader.h @@ -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); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 3471a8295..bfbf1957b 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -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); diff --git a/src/screenshot.cpp b/src/screenshot.cpp index b7abab8fc..b832e2224 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -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. diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index c7dd0cb14..77be428c9 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -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 { diff --git a/src/signal.cpp b/src/signal.cpp index 9b17e51dc..d6795e3b5 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -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] = { diff --git a/src/sound.cpp b/src/sound.cpp index 0d1547309..73c0b22e3 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -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, diff --git a/src/spritecache.cpp b/src/spritecache.cpp index da0ca8048..3eceb38de 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -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) { diff --git a/src/stdafx.h b/src/stdafx.h index c99d7a277..dca0e6c6f 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -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 diff --git a/src/strings_func.h b/src/strings_func.h index 6ef36dafc..2019b8b36 100644 --- a/src/strings_func.h +++ b/src/strings_func.h @@ -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)); } /** diff --git a/src/table/airport_defaults.h b/src/table/airport_defaults.h index ec30874f7..dce71843a 100644 --- a/src/table/airport_defaults.h +++ b/src/table/airport_defaults.h @@ -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); diff --git a/src/table/airporttiles.h b/src/table/airporttiles.h index d4fb3d968..0393cf7a5 100644 --- a/src/table/airporttiles.h +++ b/src/table/airporttiles.h @@ -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 diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index d14415051..4e5abaff5 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -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); diff --git a/src/table/pricebase.h b/src/table/pricebase.h index 5051254a3..27af6a370 100644 --- a/src/table/pricebase.h +++ b/src/table/pricebase.h @@ -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); diff --git a/src/table/sprites.h b/src/table/sprites.h index 64f628e5d..7d9f980ef 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -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; diff --git a/src/table/station_land.h b/src/table/station_land.h index 6b4b2267a..8429914f3 100644 --- a/src/table/station_land.h +++ b/src/table/station_land.h @@ -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, diff --git a/src/table/town_land.h b/src/table/town_land.h index 80a181baa..92292f620 100644 --- a/src/table/town_land.h +++ b/src/table/town_land.h @@ -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); diff --git a/src/table/train_cmd.h b/src/table/train_cmd.h index cc53582f8..f9419990b 100644 --- a/src/table/train_cmd.h +++ b/src/table/train_cmd.h @@ -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)); diff --git a/src/textfile_gui.cpp b/src/textfile_gui.cpp index 3519c2750..7b728e9b2 100644 --- a/src/textfile_gui.cpp +++ b/src/textfile_gui.cpp @@ -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]; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index ff63b613f..8928ffdbf 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -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]; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 3ed7cb1b0..e014944a9 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -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: diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 2cc9f9d74..50a011c8e 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -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[] = { diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 79df540cf..a574d9b81 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -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; } diff --git a/src/video/dedicated_v.cpp b/src/video/dedicated_v.cpp index 0089d163d..b3acb82a4 100644 --- a/src/video/dedicated_v.cpp +++ b/src/video/dedicated_v.cpp @@ -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 diff --git a/src/viewport_sprite_sorter_sse4.cpp b/src/viewport_sprite_sorter_sse4.cpp index 876821fdd..aac833318 100644 --- a/src/viewport_sprite_sorter_sse4.cpp +++ b/src/viewport_sprite_sorter_sse4.cpp @@ -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 |