From b1718478c853a22481ea756ab0ea2f8b57da47f9 Mon Sep 17 00:00:00 2001 From: frosch Date: Wed, 31 Jan 2024 21:03:17 +0100 Subject: [PATCH] Codechange: Replace old non-standard attributes with C++17/20 standard attributes. --- src/3rdparty/squirrel/squirrel/sqlexer.cpp | 2 +- src/3rdparty/squirrel/squirrel/sqvm.cpp | 10 ++--- src/aircraft.h | 2 +- src/blitter/32bpp_anim_sse4.hpp | 2 +- src/blitter/8bpp_optimized.hpp | 2 +- src/blitter/8bpp_simple.hpp | 2 +- src/company_gui.cpp | 6 +-- src/console.cpp | 2 +- src/core/alloc_func.cpp | 4 +- src/core/alloc_func.hpp | 4 +- src/core/overflowsafe_type.hpp | 6 +-- src/depot_gui.cpp | 2 +- src/disaster_vehicle.h | 2 +- src/effectvehicle_base.h | 2 +- src/elrail.cpp | 2 +- src/engine_gui.cpp | 2 +- src/error.cpp | 4 +- src/error_func.h | 4 +- src/fileio.cpp | 4 +- src/fios_gui.cpp | 2 +- src/industry_gui.cpp | 4 +- src/misc_gui.cpp | 6 +-- src/music/extmidi.cpp | 2 +- src/network/core/network_game_info.cpp | 12 +++--- src/network/network_chat_gui.cpp | 2 +- src/network/network_content_gui.cpp | 2 +- src/network/network_gui.cpp | 4 +- src/network/network_server.cpp | 2 +- src/newgrf.cpp | 8 ++-- src/newgrf_airport.h | 2 +- src/newgrf_gui.cpp | 8 ++-- src/newgrf_industries.cpp | 2 +- src/newgrf_industries.h | 2 +- src/newgrf_object.cpp | 2 +- src/newgrf_object.h | 2 +- src/newgrf_roadstop.h | 2 +- src/newgrf_station.h | 2 +- src/order_cmd.cpp | 6 +-- src/order_gui.cpp | 2 +- src/os/windows/crashlog_win.cpp | 2 +- src/pathfinder/yapf/yapf_destrail.hpp | 4 +- src/rail_cmd.cpp | 14 +++---- src/rail_gui.cpp | 2 +- src/roadveh.h | 2 +- src/saveload/afterload.cpp | 2 +- src/saveload/company_sl.cpp | 2 +- src/saveload/saveload.cpp | 6 +-- src/saveload/saveload_error.hpp | 6 +-- src/script/api/script_error.cpp | 2 +- src/script/api/script_stationlist.cpp | 4 +- src/settings.cpp | 2 +- src/settingsgen/settingsgen.cpp | 2 +- src/ship.h | 2 +- src/signal.cpp | 4 +- src/signs_gui.cpp | 2 +- src/smallmap_gui.cpp | 8 ++-- src/spritecache.cpp | 2 +- src/station_base.h | 2 +- src/station_cmd.cpp | 2 +- src/stdafx.h | 43 ++-------------------- src/strgen/strgen.cpp | 4 +- src/strgen/strgen.h | 2 +- src/terraform_gui.cpp | 2 +- src/timer/timer.h | 6 +-- src/timetable_gui.cpp | 2 +- src/town_cmd.cpp | 6 +-- src/town_gui.cpp | 2 +- src/train.h | 2 +- src/train_cmd.cpp | 4 +- src/tree_cmd.cpp | 4 +- src/vehicle.cpp | 2 +- src/vehicle_gui.cpp | 10 ++--- src/vehiclelist.cpp | 2 +- src/video/win32_v.cpp | 2 +- src/viewport.cpp | 8 ++-- src/water_cmd.cpp | 8 ++-- src/waypoint_base.h | 2 +- src/widget.cpp | 26 ++++++------- src/window.cpp | 28 +++++++------- 79 files changed, 169 insertions(+), 206 deletions(-) diff --git a/src/3rdparty/squirrel/squirrel/sqlexer.cpp b/src/3rdparty/squirrel/squirrel/sqlexer.cpp index f8e9d1754c..96e43f4af7 100644 --- a/src/3rdparty/squirrel/squirrel/sqlexer.cpp +++ b/src/3rdparty/squirrel/squirrel/sqlexer.cpp @@ -92,7 +92,7 @@ SQLexer::SQLexer(SQSharedState *ss, SQLEXREADFUNC rg, SQUserPointer up) Next(); } -NORETURN void SQLexer::Error(const SQChar *err) +[[noreturn]] void SQLexer::Error(const SQChar *err) { throw CompileException(err); } diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp index 56f8868c76..02dbc1625d 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -217,7 +217,7 @@ bool SQVM::ObjCmp(const SQObjectPtr &o1,const SQObjectPtr &o2,SQInteger &result) _RET_SUCCEED(_integer(res)) } } - FALLTHROUGH; + [[fallthrough]]; default: _RET_SUCCEED( _userpointer(o1) < _userpointer(o2)?-1:1 ); } @@ -289,7 +289,7 @@ void SQVM::ToString(const SQObjectPtr &o,SQObjectPtr &res) //else keeps going to the default } } - FALLTHROUGH; + [[fallthrough]]; default: str = fmt::format("({} : 0x{:08X})",GetTypeName(o),(size_t)(void*)_rawval(o)); } @@ -541,7 +541,7 @@ bool SQVM::FOREACH_OP(SQObjectPtr &o1,SQObjectPtr &o2,SQObjectPtr _generator(o1)->Resume(this, arg_2+1); _FINISH(0); } - FALLTHROUGH; + [[fallthrough]]; default: Raise_Error(fmt::format("cannot iterate {}", GetTypeName(o1))); } @@ -776,7 +776,7 @@ exception_restore: ct_stackbase = _stackbase; goto common_call; } - FALLTHROUGH; + [[fallthrough]]; case _OP_CALL: { ct_tailcall = false; ct_target = arg0; @@ -1338,7 +1338,7 @@ bool SQVM::Set(const SQObjectPtr &self,const SQObjectPtr &key,const SQObjectPtr return true; } } - FALLTHROUGH; + [[fallthrough]]; case OT_USERDATA: if(_delegable(self)->_delegate) { SQObjectPtr t; diff --git a/src/aircraft.h b/src/aircraft.h index 0beab20dfb..3ac5a6102e 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -71,7 +71,7 @@ struct AircraftCache { /** * Aircraft, helicopters, rotors and their shadows belong to this class. */ -struct Aircraft FINAL : public SpecializedVehicle { +struct Aircraft final : public SpecializedVehicle { uint16_t crashed_counter; ///< Timer for handling crash animations. byte pos; ///< Next desired position of the aircraft. byte previous_pos; ///< Previous desired position of the aircraft. diff --git a/src/blitter/32bpp_anim_sse4.hpp b/src/blitter/32bpp_anim_sse4.hpp index 379e7e9647..d11c90d341 100644 --- a/src/blitter/32bpp_anim_sse4.hpp +++ b/src/blitter/32bpp_anim_sse4.hpp @@ -32,7 +32,7 @@ #define MARGIN_NORMAL_THRESHOLD 4 /** The SSE4 32 bpp blitter with palette animation. */ -class Blitter_32bppSSE4_Anim FINAL : public Blitter_32bppSSE2_Anim, public Blitter_32bppSSE4 { +class Blitter_32bppSSE4_Anim final : public Blitter_32bppSSE2_Anim, public Blitter_32bppSSE4 { private: public: diff --git a/src/blitter/8bpp_optimized.hpp b/src/blitter/8bpp_optimized.hpp index 169dee0c26..39a7d91d22 100644 --- a/src/blitter/8bpp_optimized.hpp +++ b/src/blitter/8bpp_optimized.hpp @@ -14,7 +14,7 @@ #include "factory.hpp" /** 8bpp blitter optimised for speed. */ -class Blitter_8bppOptimized FINAL : public Blitter_8bppBase { +class Blitter_8bppOptimized final : public Blitter_8bppBase { public: /** Data stored about a (single) sprite. */ struct SpriteData { diff --git a/src/blitter/8bpp_simple.hpp b/src/blitter/8bpp_simple.hpp index 455d76d937..23d49d7f91 100644 --- a/src/blitter/8bpp_simple.hpp +++ b/src/blitter/8bpp_simple.hpp @@ -14,7 +14,7 @@ #include "factory.hpp" /** Most trivial 8bpp blitter. */ -class Blitter_8bppSimple FINAL : public Blitter_8bppBase { +class Blitter_8bppSimple final : public Blitter_8bppBase { public: void Draw(Blitter::BlitterParams *bp, BlitterMode mode, ZoomLevel zoom) override; Sprite *Encode(const SpriteLoader::SpriteCollection &sprite, AllocatorProc *allocator) override; diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 3785d11693..bf25b9022a 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -399,7 +399,7 @@ struct CompanyFinancesWindow : Window { case WID_CF_EXPS_PRICE2: case WID_CF_EXPS_PRICE3: size->height = GetTotalCategoriesHeight(); - FALLTHROUGH; + [[fallthrough]]; case WID_CF_BALANCE_VALUE: case WID_CF_LOAN_VALUE: @@ -819,7 +819,7 @@ public: size->width = 0; break; } - FALLTHROUGH; + [[fallthrough]]; case WID_SCL_PRI_COL_DROPDOWN: { this->square = GetSpriteSize(SPR_SQUARE); @@ -1649,7 +1649,7 @@ public: /* OK button */ case WID_SCMF_ACCEPT: Command::Post(this->face); - FALLTHROUGH; + [[fallthrough]]; /* Cancel button */ case WID_SCMF_CANCEL: diff --git a/src/console.cpp b/src/console.cpp index baeb893e83..9781283095 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -351,7 +351,7 @@ void IConsoleCmdExec(const std::string &command_string, const uint recurse_count tokenstream[tstream_i++] = *++cmdptr; break; } - FALLTHROUGH; + [[fallthrough]]; default: // Normal character tokenstream[tstream_i++] = *cmdptr; diff --git a/src/core/alloc_func.cpp b/src/core/alloc_func.cpp index b02b1a84a4..00f9ecdb1a 100644 --- a/src/core/alloc_func.cpp +++ b/src/core/alloc_func.cpp @@ -17,7 +17,7 @@ * Function to exit with an error message after malloc() or calloc() have failed * @param size number of bytes we tried to allocate */ -void NORETURN MallocError(size_t size) +[[noreturn]] void MallocError(size_t size) { FatalError("Out of memory. Cannot allocate {} bytes", size); } @@ -26,7 +26,7 @@ void NORETURN MallocError(size_t size) * Function to exit with an error message after realloc() have failed * @param size number of bytes we tried to allocate */ -void NORETURN ReallocError(size_t size) +[[noreturn]] void ReallocError(size_t size) { FatalError("Out of memory. Cannot reallocate {} bytes", size); } diff --git a/src/core/alloc_func.hpp b/src/core/alloc_func.hpp index 0e3920a184..3bc4dde683 100644 --- a/src/core/alloc_func.hpp +++ b/src/core/alloc_func.hpp @@ -17,8 +17,8 @@ * binary needlessly large. */ -void NORETURN MallocError(size_t size); -void NORETURN ReallocError(size_t size); +[[noreturn]] void MallocError(size_t size); +[[noreturn]] void ReallocError(size_t size); /** * Checks whether allocating memory would overflow size_t. diff --git a/src/core/overflowsafe_type.hpp b/src/core/overflowsafe_type.hpp index 8e40973192..455510f831 100644 --- a/src/core/overflowsafe_type.hpp +++ b/src/core/overflowsafe_type.hpp @@ -53,7 +53,7 @@ public: inline constexpr OverflowSafeInt& operator += (const OverflowSafeInt& other) { #ifdef HAS_OVERFLOW_BUILTINS - if (unlikely(__builtin_add_overflow(this->m_value, other.m_value, &this->m_value))) { + if (__builtin_add_overflow(this->m_value, other.m_value, &this->m_value)) [[unlikely]] { this->m_value = (other.m_value < 0) ? T_MIN : T_MAX; } #else @@ -76,7 +76,7 @@ public: inline constexpr OverflowSafeInt& operator -= (const OverflowSafeInt& other) { #ifdef HAS_OVERFLOW_BUILTINS - if (unlikely(__builtin_sub_overflow(this->m_value, other.m_value, &this->m_value))) { + if (__builtin_sub_overflow(this->m_value, other.m_value, &this->m_value)) [[unlikely]] { this->m_value = (other.m_value < 0) ? T_MAX : T_MIN; } #else @@ -114,7 +114,7 @@ public: { #ifdef HAS_OVERFLOW_BUILTINS const bool is_result_positive = (this->m_value < 0) == (factor < 0); // -ve * -ve == +ve - if (unlikely(__builtin_mul_overflow(this->m_value, factor, &this->m_value))) { + if (__builtin_mul_overflow(this->m_value, factor, &this->m_value)) [[unlikely]] { this->m_value = is_result_positive ? T_MAX : T_MIN; } #else diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index f523825b85..9b7831c156 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -497,7 +497,7 @@ struct DepotWindow : Window { switch (this->type) { case VEH_TRAIN: if (wagon) return MODE_ERROR; - FALLTHROUGH; + [[fallthrough]]; case VEH_ROAD: if (xm <= this->flag_size.width) return MODE_START_STOP; diff --git a/src/disaster_vehicle.h b/src/disaster_vehicle.h index 196f4ade95..fc3abecc6e 100644 --- a/src/disaster_vehicle.h +++ b/src/disaster_vehicle.h @@ -34,7 +34,7 @@ enum DisasterSubType { /** * Disasters, like submarines, skyrangers and their shadows, belong to this class. */ -struct DisasterVehicle FINAL : public SpecializedVehicle { +struct DisasterVehicle final : public SpecializedVehicle { SpriteID image_override; ///< Override for the default disaster vehicle sprite. VehicleID big_ufo_destroyer_target; ///< The big UFO that this destroyer is supposed to bomb. byte flags; ///< Flags about the state of the vehicle, @see AirVehicleFlags diff --git a/src/effectvehicle_base.h b/src/effectvehicle_base.h index 7926a0ee7a..2c0d2744c5 100644 --- a/src/effectvehicle_base.h +++ b/src/effectvehicle_base.h @@ -21,7 +21,7 @@ * - bulldozer (road works) * - bubbles (industry) */ -struct EffectVehicle FINAL : public SpecializedVehicle { +struct EffectVehicle final : public SpecializedVehicle { uint16_t animation_state; ///< State primarily used to change the graphics/behaviour. byte animation_substate; ///< Sub state to time the change of the graphics/behaviour. diff --git a/src/elrail.cpp b/src/elrail.cpp index 72021cb9ed..20fb2facce 100644 --- a/src/elrail.cpp +++ b/src/elrail.cpp @@ -125,7 +125,7 @@ static TrackBits GetRailTrackBitsUniversal(TileIndex t, byte *override) static TrackBits MaskWireBits(TileIndex t, TrackBits tracks) { /* Single track bits are never masked out. */ - if (likely(HasAtMostOneBit(tracks))) return tracks; + if (HasAtMostOneBit(tracks)) [[likely]] return tracks; if (!IsPlainRailTile(t)) return tracks; diff --git a/src/engine_gui.cpp b/src/engine_gui.cpp index 908c856199..bbf5ba5626 100644 --- a/src/engine_gui.cpp +++ b/src/engine_gui.cpp @@ -128,7 +128,7 @@ struct EnginePreviewWindow : Window { switch (widget) { case WID_EP_YES: Command::Post(this->window_number); - FALLTHROUGH; + [[fallthrough]]; case WID_EP_NO: if (!_shift_pressed) this->Close(); break; diff --git a/src/error.cpp b/src/error.cpp index 2d90a83e2b..a1cba7d02e 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -10,12 +10,12 @@ #include "stdafx.h" #include "error_func.h" -void NORETURN NotReachedError(int line, const char *file) +[[noreturn]] void NotReachedError(int line, const char *file) { FatalError("NOT_REACHED triggered at line {} of {}", line, file); } -void NORETURN AssertFailedError(int line, const char *file, const char *expression) +[[noreturn]] void AssertFailedError(int line, const char *file, const char *expression) { FatalError("Assertion failed at line {} of {}: {}", line, file, expression); } diff --git a/src/error_func.h b/src/error_func.h index a1fb7a2c33..afbe763abe 100644 --- a/src/error_func.h +++ b/src/error_func.h @@ -12,8 +12,8 @@ #include "3rdparty/fmt/format.h" -void NORETURN UserErrorI(const std::string &str); -void NORETURN FatalErrorI(const std::string &str); +[[noreturn]] void UserErrorI(const std::string &str); +[[noreturn]] void FatalErrorI(const std::string &str); #define UserError(format_string, ...) UserErrorI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) #define FatalError(format_string, ...) FatalErrorI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) diff --git a/src/fileio.cpp b/src/fileio.cpp index 26792fa596..71a65e4add 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -327,7 +327,7 @@ FILE *FioFOpenFile(const std::string &filename, const char *mode, Subdirectory s case BASESET_DIR: f = FioFOpenFile(filename, mode, OLD_GM_DIR, filesize); if (f != nullptr) break; - FALLTHROUGH; + [[fallthrough]]; case NEWGRF_DIR: f = FioFOpenFile(filename, mode, OLD_DATA_DIR, filesize); break; @@ -1230,7 +1230,7 @@ uint FileScanner::Scan(const char *extension, Subdirectory sd, bool tars, bool r switch (sd) { case BASESET_DIR: num += this->Scan(extension, OLD_GM_DIR, tars, recursive); - FALLTHROUGH; + [[fallthrough]]; case NEWGRF_DIR: num += this->Scan(extension, OLD_DATA_DIR, tars, recursive); break; diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 041189711f..ac073062fe 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -836,7 +836,7 @@ public: /* We reset the files filtered */ this->OnInvalidateData(SLIWD_FILTER_CHANGES); - FALLTHROUGH; + [[fallthrough]]; case SLIWD_SELECTION_CHANGES: /* Selection changes */ diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 6810433c17..f2420cb8fd 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -886,14 +886,14 @@ public: switch (suffix.display) { case CSD_CARGO_AMOUNT_TEXT: SetDParamStr(3, suffix.text); - FALLTHROUGH; + [[fallthrough]]; case CSD_CARGO_AMOUNT: str = stockpiling ? STR_INDUSTRY_VIEW_ACCEPT_CARGO_AMOUNT : STR_INDUSTRY_VIEW_ACCEPT_CARGO; break; case CSD_CARGO_TEXT: SetDParamStr(3, suffix.text); - FALLTHROUGH; + [[fallthrough]]; case CSD_CARGO: str = STR_INDUSTRY_VIEW_ACCEPT_CARGO; break; diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 64e1d02840..2e9928e793 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1025,11 +1025,11 @@ struct QueryStringWindow : public Window switch (widget) { case WID_QS_DEFAULT: this->editbox.text.DeleteAll(); - FALLTHROUGH; + [[fallthrough]]; case WID_QS_OK: this->OnOk(); - FALLTHROUGH; + [[fallthrough]]; case WID_QS_CANCEL: this->Close(); @@ -1181,7 +1181,7 @@ struct QueryWindow : public Window { this->proc(this->parent, true); this->proc = nullptr; } - FALLTHROUGH; + [[fallthrough]]; case WKC_ESC: this->Close(); diff --git a/src/music/extmidi.cpp b/src/music/extmidi.cpp index 74539ff569..af62d3488d 100644 --- a/src/music/extmidi.cpp +++ b/src/music/extmidi.cpp @@ -122,7 +122,7 @@ void MusicDriver_ExtMidi::DoPlay() case -1: Debug(driver, 0, "extmidi: couldn't fork: {}", strerror(errno)); - FALLTHROUGH; + [[fallthrough]]; default: this->song.clear(); diff --git a/src/network/core/network_game_info.cpp b/src/network/core/network_game_info.cpp index 5c7404040d..ceffa9e227 100644 --- a/src/network/core/network_game_info.cpp +++ b/src/network/core/network_game_info.cpp @@ -274,17 +274,17 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfo switch (game_info_version) { case 7: info->ticks_playing = p->Recv_uint64(); - FALLTHROUGH; + [[fallthrough]]; case 6: newgrf_serialisation = (NewGRFSerializationType)p->Recv_uint8(); if (newgrf_serialisation >= NST_END) return; - FALLTHROUGH; + [[fallthrough]]; case 5: { info->gamescript_version = (int)p->Recv_uint32(); info->gamescript_name = p->Recv_string(NETWORK_NAME_LENGTH); - FALLTHROUGH; + [[fallthrough]]; } case 4: { @@ -326,19 +326,19 @@ void DeserializeNetworkGameInfo(Packet *p, NetworkGameInfo *info, const GameInfo *dst = c; dst = &c->next; } - FALLTHROUGH; + [[fallthrough]]; } case 3: info->calendar_date = Clamp(p->Recv_uint32(), 0, CalendarTime::MAX_DATE.base()); info->calendar_start = Clamp(p->Recv_uint32(), 0, CalendarTime::MAX_DATE.base()); - FALLTHROUGH; + [[fallthrough]]; case 2: info->companies_max = p->Recv_uint8 (); info->companies_on = p->Recv_uint8 (); p->Recv_uint8(); // Used to contain max-spectators. - FALLTHROUGH; + [[fallthrough]]; case 1: info->server_name = p->Recv_string(NETWORK_NAME_LENGTH); diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index c91a74bde6..ece8f5e88a 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -454,7 +454,7 @@ struct NetworkChatWindow : public Window { switch (widget) { case WID_NC_SENDBUTTON: /* Send */ SendChat(this->message_editbox.text.buf, this->dtype, this->dest); - FALLTHROUGH; + [[fallthrough]]; case WID_NC_CLOSE: /* Cancel */ this->Close(); diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 886992130c..6b16a91647 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -894,7 +894,7 @@ public: return ES_HANDLED; } /* space is pressed and filter is focused. */ - FALLTHROUGH; + [[fallthrough]]; default: return ES_NOT_HANDLED; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index e7a597b9b3..2590475ca7 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2134,7 +2134,7 @@ struct NetworkJoinStatusWindow : Window { progress = 15; // We don't have the final size yet; the server is still compressing! break; } - FALLTHROUGH; + [[fallthrough]]; default: // Waiting is 15%, so the resting receivement of map is maximum 70% progress = 15 + _network_join_bytes * (100 - 15) / _network_join_bytes_total; @@ -2307,7 +2307,7 @@ struct NetworkCompanyPasswordWindow : public Window { switch (widget) { case WID_NCP_OK: this->OnOk(); - FALLTHROUGH; + [[fallthrough]]; case WID_NCP_CANCEL: this->Close(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c6cb213115..96c95434e5 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -1362,7 +1362,7 @@ void NetworkServerSendChat(NetworkAction action, DestType desttype, int dest, co } default: Debug(net, 1, "Received unknown chat destination type {}; doing broadcast instead", desttype); - FALLTHROUGH; + [[fallthrough]]; case DESTTYPE_BROADCAST: for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) { diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 34246726a1..4781e460a6 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -3073,7 +3073,7 @@ static ChangeInfoResult CargoChangeInfo(uint cid, int numinfo, int prop, ByteRea case 0x0B: cs->town_acceptance_effect = TAE_FOOD; break; default: GrfMsg(1, "CargoChangeInfo: Unknown town growth substitute value {}, setting to none.", substitute_type); - FALLTHROUGH; + [[fallthrough]]; case 0xFF: cs->town_acceptance_effect = TAE_NONE; break; } break; @@ -4279,7 +4279,7 @@ static ChangeInfoResult RailTypeChangeInfo(uint id, int numinfo, int prop, ByteR RailType resolved_rt = GetRailTypeByLabel(BSWAP32(label), false); if (resolved_rt != INVALID_RAILTYPE) { switch (prop) { - case 0x0F: SetBit(rti->powered_railtypes, resolved_rt); FALLTHROUGH; // Powered implies compatible. + case 0x0F: SetBit(rti->powered_railtypes, resolved_rt); [[fallthrough]]; // Powered implies compatible. case 0x0E: SetBit(rti->compatible_railtypes, resolved_rt); break; case 0x18: SetBit(rti->introduction_required_railtypes, resolved_rt); break; case 0x19: SetBit(rti->introduces_railtypes, resolved_rt); break; @@ -4396,7 +4396,7 @@ static ChangeInfoResult RailTypeReserveInfo(uint id, int numinfo, int prop, Byte break; } GrfMsg(1, "RailTypeReserveInfo: Ignoring property 1D for rail type {} because no label was set", id + i); - FALLTHROUGH; + [[fallthrough]]; case 0x0E: // Compatible railtype list case 0x0F: // Powered railtype list @@ -4885,7 +4885,7 @@ static bool HandleChangeInfoResult(const char *caller, ChangeInfoResult cir, uin case CIR_UNKNOWN: GrfMsg(0, "{}: Unknown property 0x{:02X} of feature 0x{:02X}, disabling", caller, property, feature); - FALLTHROUGH; + [[fallthrough]]; case CIR_INVALID_ID: { /* No debug message for an invalid ID, as it has already been output */ diff --git a/src/newgrf_airport.h b/src/newgrf_airport.h index a07dd504b5..297d0d1c25 100644 --- a/src/newgrf_airport.h +++ b/src/newgrf_airport.h @@ -189,7 +189,7 @@ struct AirportResolverObject : public ResolverObject { { TownScopeResolver *tsr = this->GetTown(); if (tsr != nullptr) return tsr; - FALLTHROUGH; + [[fallthrough]]; } default: return ResolverObject::GetScope(scope, relative); } diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp index d3d7ad4fe0..c1fdb7aec2 100644 --- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -1048,7 +1048,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { break; } /* With double click, continue */ - FALLTHROUGH; + [[fallthrough]]; } case WID_NS_REMOVE: { // Remove GRF @@ -1106,7 +1106,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { break; } /* With double click, continue */ - FALLTHROUGH; + [[fallthrough]]; } case WID_NS_ADD: @@ -1261,7 +1261,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { } this->avails.ForceRebuild(); - FALLTHROUGH; + [[fallthrough]]; case GOID_NEWGRF_CURRENT_LOADED: this->modified = false; @@ -1270,7 +1270,7 @@ struct NewGRFWindow : public Window, NewGRFScanCallback { case GOID_NEWGRF_LIST_EDITED: this->preset = -1; - FALLTHROUGH; + [[fallthrough]]; case GOID_NEWGRF_CHANGES_MADE: UpdateScrollBars(); diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index b2db76a431..59660d0db9 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -126,7 +126,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte param_setID, byte layo case 0xFFFFFFFF: // current grf GrfID = GetIndustrySpec(current->type)->grf_prop.grffile->grfid; - FALLTHROUGH; + [[fallthrough]]; default: // use the grfid specified in register 100h SetBit(param_setID, 7); // bit 7 means it is not an old type diff --git a/src/newgrf_industries.h b/src/newgrf_industries.h index 4cae362258..1a2132951e 100644 --- a/src/newgrf_industries.h +++ b/src/newgrf_industries.h @@ -57,7 +57,7 @@ struct IndustriesResolverObject : public ResolverObject { TownScopeResolver *tsr = this->GetTown(); if (tsr != nullptr) return tsr; } - FALLTHROUGH; + [[fallthrough]]; default: return ResolverObject::GetScope(scope, relative); diff --git a/src/newgrf_object.cpp b/src/newgrf_object.cpp index 740f82ec97..55c53039b4 100644 --- a/src/newgrf_object.cpp +++ b/src/newgrf_object.cpp @@ -239,7 +239,7 @@ static uint32_t GetCountAndDistanceOfClosestInstance(byte local_id, uint32_t grf case 0xFFFFFFFF: // current grf grf_id = grfid; - FALLTHROUGH; + [[fallthrough]]; default: // use the grfid specified in register 100h idx = _object_mngr.GetID(local_id, grf_id); diff --git a/src/newgrf_object.h b/src/newgrf_object.h index 14200091bf..a763ef5fc5 100644 --- a/src/newgrf_object.h +++ b/src/newgrf_object.h @@ -148,7 +148,7 @@ struct ObjectResolverObject : public ResolverObject { case VSG_SCOPE_PARENT: { TownScopeResolver *tsr = this->GetTown(); if (tsr != nullptr) return tsr; - FALLTHROUGH; + [[fallthrough]]; } default: diff --git a/src/newgrf_roadstop.h b/src/newgrf_roadstop.h index bcea002c87..3c9800c0b1 100644 --- a/src/newgrf_roadstop.h +++ b/src/newgrf_roadstop.h @@ -107,7 +107,7 @@ struct RoadStopResolverObject : public ResolverObject { case VSG_SCOPE_PARENT: { TownScopeResolver *tsr = this->GetTown(); if (tsr != nullptr) return tsr; - FALLTHROUGH; + [[fallthrough]]; } default: return ResolverObject::GetScope(scope, relative); } diff --git a/src/newgrf_station.h b/src/newgrf_station.h index eae3a42522..8c9aa60976 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -66,7 +66,7 @@ struct StationResolverObject : public ResolverObject { case VSG_SCOPE_PARENT: { TownScopeResolver *tsr = this->GetTown(); if (tsr != nullptr) return tsr; - FALLTHROUGH; + [[fallthrough]]; } default: diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 1594065a10..03aed58932 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -756,7 +756,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case OSL_PLATFORM_NEAR_END: case OSL_PLATFORM_MIDDLE: if (v->type != VEH_TRAIN) return CMD_ERROR; - FALLTHROUGH; + [[fallthrough]]; case OSL_PLATFORM_FAR_END: break; @@ -865,7 +865,7 @@ CommandCost CmdInsertOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case OCV_LOAD_PERCENTAGE: case OCV_RELIABILITY: if (new_order.GetConditionValue() > 100) return CMD_ERROR; - FALLTHROUGH; + [[fallthrough]]; default: if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) return CMD_ERROR; @@ -1388,7 +1388,7 @@ CommandCost CmdModifyOrder(DoCommandFlag flags, VehicleID veh, VehicleOrderID se case OCV_LOAD_PERCENTAGE: case OCV_RELIABILITY: if (order->GetConditionValue() > 100) order->SetConditionValue(100); - FALLTHROUGH; + [[fallthrough]]; default: if (occ == OCC_IS_TRUE || occ == OCC_IS_FALSE) order->SetConditionComparator(OCC_EQUALS); diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 62780c4850..f5b6a4b404 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -844,7 +844,7 @@ public: case VIWD_AUTOREPLACE: /* Autoreplace replaced the vehicle */ this->vehicle = Vehicle::Get(this->window_number); - FALLTHROUGH; + [[fallthrough]]; case VIWD_CONSIST_CHANGED: /* Vehicle composition was changed. */ diff --git a/src/os/windows/crashlog_win.cpp b/src/os/windows/crashlog_win.cpp index e74fc5ed0b..b7d830bb8c 100644 --- a/src/os/windows/crashlog_win.cpp +++ b/src/os/windows/crashlog_win.cpp @@ -71,7 +71,7 @@ static const std::map exception_code_to_name{ * * @param exit_code The exit code to return. */ -static void NORETURN ImmediateExitProcess(uint exit_code) +[[noreturn]] static void ImmediateExitProcess(uint exit_code) { /* TerminateProcess may fail in some special edge cases; fall back to ExitProcess in this case. */ TerminateProcess(GetCurrentProcess(), exit_code); diff --git a/src/pathfinder/yapf/yapf_destrail.hpp b/src/pathfinder/yapf/yapf_destrail.hpp index 7abc4294ee..f39a8a2c4b 100644 --- a/src/pathfinder/yapf/yapf_destrail.hpp +++ b/src/pathfinder/yapf/yapf_destrail.hpp @@ -140,7 +140,7 @@ public: * waypoint. */ Yapf().DisableCache(true); } - FALLTHROUGH; + [[fallthrough]]; case OT_GOTO_STATION: m_destTile = CalcClosestStationTile(v->current_order.GetDestination(), v->tile, v->current_order.IsType(OT_GOTO_STATION) ? STATION_RAIL : STATION_WAYPOINT); @@ -152,7 +152,7 @@ public: if (v->current_order.GetDepotActionType() & ODATFB_NEAREST_DEPOT) { m_any_depot = true; } - FALLTHROUGH; + [[fallthrough]]; default: m_destTile = v->dest_tile; diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 6a0377868a..3b93a5d32c 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -562,7 +562,7 @@ CommandCost CmdBuildSingleRail(DoCommandFlag flags, TileIndex tile, RailType rai if (IsLevelCrossing(tile) && GetCrossingRailBits(tile) == trackbit) { return_cmd_error(STR_ERROR_ALREADY_BUILT); } - FALLTHROUGH; + [[fallthrough]]; } default: { @@ -2475,13 +2475,13 @@ static void DrawTile_Track(TileInfo *ti) switch (GetRailDepotDirection(ti->tile)) { case DIAGDIR_NE: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SW: DrawGroundSprite(ground + RTO_X, PAL_NONE); break; case DIAGDIR_NW: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SE: DrawGroundSprite(ground + RTO_Y, PAL_NONE); break; @@ -2495,13 +2495,13 @@ static void DrawTile_Track(TileInfo *ti) switch (GetRailDepotDirection(ti->tile)) { case DIAGDIR_NE: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SW: DrawGroundSprite(overlay + RTO_X, PALETTE_CRASH); break; case DIAGDIR_NW: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SE: DrawGroundSprite(overlay + RTO_Y, PALETTE_CRASH); break; @@ -2515,13 +2515,13 @@ static void DrawTile_Track(TileInfo *ti) switch (GetRailDepotDirection(ti->tile)) { case DIAGDIR_NE: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SW: DrawGroundSprite(rti->base_sprites.single_x, PALETTE_CRASH); break; case DIAGDIR_NW: if (!IsInvisibilitySet(TO_BUILDINGS)) break; - FALLTHROUGH; + [[fallthrough]]; case DIAGDIR_SE: DrawGroundSprite(rti->base_sprites.single_y, PALETTE_CRASH); break; diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index a326c31532..636f5e6c2b 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -2305,7 +2305,7 @@ static void SetDefaultRailGui() if (count[rt] > 0) break; /* No rail, just get the first available one */ - FALLTHROUGH; + [[fallthrough]]; } case 0: { /* Use first available type */ diff --git a/src/roadveh.h b/src/roadveh.h index f05e7ee3a6..3205da5083 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -103,7 +103,7 @@ struct RoadVehPathCache { /** * Buses, trucks and trams belong to this class. */ -struct RoadVehicle FINAL : public GroundVehicle { +struct RoadVehicle final : public GroundVehicle { RoadVehPathCache path; ///< Cached path. byte state; ///< @see RoadVehicleStates byte frame; diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 38b87c0561..6954d0909b 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -160,7 +160,7 @@ static void ConvertTownOwner() if (GB(tile.m5(), 4, 2) == ROAD_TILE_CROSSING && HasBit(tile.m3(), 7)) { tile.m3() = OWNER_TOWN; } - FALLTHROUGH; + [[fallthrough]]; case MP_TUNNELBRIDGE: if (tile.m1() & 0x80) SetTileOwner(tile, OWNER_TOWN); diff --git a/src/saveload/company_sl.cpp b/src/saveload/company_sl.cpp index 99e8b43a51..ef83c6de03 100644 --- a/src/saveload/company_sl.cpp +++ b/src/saveload/company_sl.cpp @@ -186,7 +186,7 @@ void AfterLoadCompanyStats() } } } - FALLTHROUGH; + [[fallthrough]]; case MP_OBJECT: if (GetWaterClass(tile) == WATER_CLASS_CANAL) { diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 78032edc9d..c4e078cf39 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -329,7 +329,7 @@ static void SlNullPointers() * @note This function does never return as it throws an exception to * break out of all the saveload code. */ -void NORETURN SlError(StringID string, const std::string &extra_msg) +[[noreturn]] void SlError(StringID string, const std::string &extra_msg) { /* Distinguish between loading into _load_check_data vs. normal save/load. */ if (_sl.action == SLA_LOAD_CHECK) { @@ -359,7 +359,7 @@ void NORETURN SlError(StringID string, const std::string &extra_msg) * @note This function does never return as it throws an exception to * break out of all the saveload code. */ -void NORETURN SlErrorCorrupt(const std::string &msg) +[[noreturn]] void SlErrorCorrupt(const std::string &msg) { SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_SAVEGAME, msg); } @@ -1934,7 +1934,7 @@ void ChunkHandler::LoadCheck(size_t len) const case CH_TABLE: case CH_SPARSE_TABLE: SlTableHeader({}); - FALLTHROUGH; + [[fallthrough]]; case CH_ARRAY: case CH_SPARSE_ARRAY: SlSkipArray(); diff --git a/src/saveload/saveload_error.hpp b/src/saveload/saveload_error.hpp index 1bf3c1556c..5500d90231 100644 --- a/src/saveload/saveload_error.hpp +++ b/src/saveload/saveload_error.hpp @@ -13,8 +13,8 @@ #include "../3rdparty/fmt/format.h" #include "../strings_type.h" -void NORETURN SlError(StringID string, const std::string &extra_msg = {}); -void NORETURN SlErrorCorrupt(const std::string &msg); +[[noreturn]] void SlError(StringID string, const std::string &extra_msg = {}); +[[noreturn]] void SlErrorCorrupt(const std::string &msg); /** * Issue an SlErrorCorrupt with a format string. @@ -25,7 +25,7 @@ void NORETURN SlErrorCorrupt(const std::string &msg); * break out of all the saveload code. */ template -inline void NORETURN SlErrorCorruptFmt(const fmt::format_string format, Args&&... fmt_args) +[[noreturn]] inline void SlErrorCorruptFmt(const fmt::format_string format, Args&&... fmt_args) { SlErrorCorrupt(fmt::format(format, std::forward(fmt_args)...)); } diff --git a/src/script/api/script_error.cpp b/src/script/api/script_error.cpp index 3d365c23bb..1d18ef112a 100644 --- a/src/script/api/script_error.cpp +++ b/src/script/api/script_error.cpp @@ -38,7 +38,7 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S case TEXT_TAB_SPECIAL: if (index < 0xE4) break; // Player name - FALLTHROUGH; + [[fallthrough]]; case TEXT_TAB_TOWN: if (index < 0xC0) break; // Town name diff --git a/src/script/api/script_stationlist.cpp b/src/script/api/script_stationlist.cpp index d2c1d532b1..c7038c1ca1 100644 --- a/src/script/api/script_stationlist.cpp +++ b/src/script/api/script_stationlist.cpp @@ -153,13 +153,13 @@ void CargoCollector::Update(StationID from, StationID via, uint amount) switch (Tselector) { case ScriptStationList_Cargo::CS_VIA_BY_FROM: if (via != this->other_station) return; - FALLTHROUGH; + [[fallthrough]]; case ScriptStationList_Cargo::CS_BY_FROM: key = from; break; case ScriptStationList_Cargo::CS_FROM_BY_VIA: if (from != this->other_station) return; - FALLTHROUGH; + [[fallthrough]]; case ScriptStationList_Cargo::CS_BY_VIA: key = via; break; diff --git a/src/settings.cpp b/src/settings.cpp index 18c4790818..e2e3116531 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -255,7 +255,7 @@ static int ParseIntList(const char *p, T *items, size_t maxitems) /* Do not accept multiple commas between numbers */ if (!comma) return -1; comma = false; - FALLTHROUGH; + [[fallthrough]]; case ' ': p++; diff --git a/src/settingsgen/settingsgen.cpp b/src/settingsgen/settingsgen.cpp index 869ec5bb30..0ab4d5bd43 100644 --- a/src/settingsgen/settingsgen.cpp +++ b/src/settingsgen/settingsgen.cpp @@ -27,7 +27,7 @@ * @param s Format string. * @note Function does not return. */ -void NORETURN FatalErrorI(const std::string &msg) +[[noreturn]] void FatalErrorI(const std::string &msg) { fmt::print(stderr, "settingsgen: FATAL: {}\n", msg); exit(1); diff --git a/src/ship.h b/src/ship.h index 955bbf6bfe..5335deefeb 100644 --- a/src/ship.h +++ b/src/ship.h @@ -21,7 +21,7 @@ typedef std::deque ShipPathCache; /** * All ships have this type. */ -struct Ship FINAL : public SpecializedVehicle { +struct Ship final : public SpecializedVehicle { TrackBits state; ///< The "track" the ship is following. ShipPathCache path; ///< Cached path. Direction rotation; ///< Visible direction. diff --git a/src/signal.cpp b/src/signal.cpp index 2326ad78fb..d060c58d22 100644 --- a/src/signal.cpp +++ b/src/signal.cpp @@ -500,7 +500,7 @@ static SigSegState UpdateSignalsInBuffer(Owner owner) _tbdset.Add(tile, INVALID_DIAGDIR); // start from depot inside break; } - FALLTHROUGH; + [[fallthrough]]; case MP_STATION: case MP_ROAD: @@ -510,7 +510,7 @@ static SigSegState UpdateSignalsInBuffer(Owner owner) _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir)); break; } - FALLTHROUGH; + [[fallthrough]]; default: /* jump to next tile */ diff --git a/src/signs_gui.cpp b/src/signs_gui.cpp index 848cb8e529..9826c87087 100644 --- a/src/signs_gui.cpp +++ b/src/signs_gui.cpp @@ -521,7 +521,7 @@ struct SignWindow : Window, SignList { case WID_QES_OK: if (RenameSign(this->cur_sign, this->name_editbox.text.buf)) break; - FALLTHROUGH; + [[fallthrough]]; case WID_QES_CANCEL: this->Close(); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 3df7ab6e14..b058290aaf 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -506,7 +506,7 @@ static inline uint32_t GetSmallMapRoutesPixels(TileIndex tile, TileType t) const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour]; return ApplyMask(cs->default_colour, &andor); } - FALLTHROUGH; + [[fallthrough]]; } default: @@ -1598,11 +1598,11 @@ public: if (tbl->show_on_map && tbl->type == _smallmap_industry_highlight) { legend_colour = _smallmap_industry_highlight_state ? PC_WHITE : PC_BLACK; } - FALLTHROUGH; + [[fallthrough]]; case SMT_LINKSTATS: SetDParam(0, tbl->legend); - FALLTHROUGH; + [[fallthrough]]; case SMT_OWNER: if (this->map_type != SMT_OWNER || tbl->company != INVALID_COMPANY) { @@ -1617,7 +1617,7 @@ public: } break; } - FALLTHROUGH; + [[fallthrough]]; default: if (this->map_type == SMT_CONTOUR) SetDParam(0, tbl->height * TILE_HEIGHT_STEP); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index ae97b53fcc..0762e905bf 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -913,7 +913,7 @@ static void *HandleInvalidSpriteRequest(SpriteID sprite, SpriteType requested, S switch (requested) { case SpriteType::Normal: if (sprite == SPR_IMG_QUERY) UserError("Uhm, would you be so kind not to load a NewGRF that makes the 'query' sprite a non-normal sprite?"); - FALLTHROUGH; + [[fallthrough]]; case SpriteType::Font: return GetRawSprite(SPR_IMG_QUERY, SpriteType::Normal, allocator); case SpriteType::Recolour: diff --git a/src/station_base.h b/src/station_base.h index 86b43fbf14..f3f19fc382 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -439,7 +439,7 @@ struct IndustryCompare { typedef std::set IndustryList; /** Station data structure */ -struct Station FINAL : SpecializedStation { +struct Station final : SpecializedStation { public: RoadStop *GetPrimaryRoadStop(RoadStopType type) const { diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index f1bcd69fd0..9e10faa9d0 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3450,7 +3450,7 @@ static void TileLoop_Station(TileIndex tile) case STATION_DOCK: if (!IsTileFlat(tile)) break; // only handle water part - FALLTHROUGH; + [[fallthrough]]; case STATION_OILRIG: //(station part) case STATION_BUOY: diff --git a/src/stdafx.h b/src/stdafx.h index 8b474920e7..5fc27f4dcc 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -84,24 +84,7 @@ /* Stuff for GCC */ #if defined(__GNUC__) || (defined(__clang__) && !defined(_MSC_VER)) -# define NORETURN __attribute__ ((noreturn)) # define CDECL -# if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) -# define FINAL final -# else -# define FINAL -# endif - - /* Use fallthrough attribute where supported */ -# if __GNUC__ >= 7 -# if __cplusplus > 201402L // C++17 -# define FALLTHROUGH [[fallthrough]] -# else -# define FALLTHROUGH __attribute__((fallthrough)) -# endif -# else -# define FALLTHROUGH -# endif #endif /* __GNUC__ || __clang__ */ #if __GNUC__ > 11 || (__GNUC__ == 11 && __GNUC_MINOR__ >= 1) @@ -110,13 +93,6 @@ # define NOACCESS(args) #endif -/* [[nodiscard]] on constructors doesn't work in GCC older than 10.1. */ -#if __GNUC__ < 10 || (__GNUC__ == 10 && __GNUC_MINOR__ < 1) -# define NODISCARD -#else -# define NODISCARD [[nodiscard]] -#endif - #if defined(_WIN32) # define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers #endif @@ -154,20 +130,11 @@ # include # endif -# define NORETURN __declspec(noreturn) # if (_MSC_VER < 1900) # define inline __forceinline # endif # define CDECL _cdecl -# define FINAL final - - /* fallthrough attribute, VS 2017 */ -# if (_MSC_VER >= 1910) || defined(__clang__) -# define FALLTHROUGH [[fallthrough]] -# else -# define FALLTHROUGH -# endif # if defined(_WIN32) && !defined(_WIN64) # if !defined(_W64) @@ -373,26 +340,22 @@ static_assert(SIZE_MAX >= UINT32_MAX); #endif /* __APPLE__ */ #if defined(__GNUC__) || defined(__clang__) -# define likely(x) __builtin_expect(!!(x), 1) -# define unlikely(x) __builtin_expect(!!(x), 0) # define GNU_TARGET(x) [[gnu::target(x)]] #else -# define likely(x) (x) -# define unlikely(x) (x) # define GNU_TARGET(x) #endif /* __GNUC__ || __clang__ */ /* For the FMT library we only want to use the headers, not link to some library. */ #define FMT_HEADER_ONLY -void NORETURN NotReachedError(int line, const char *file); -void NORETURN AssertFailedError(int line, const char *file, const char *expression); +[[noreturn]] void NotReachedError(int line, const char *file); +[[noreturn]] void AssertFailedError(int line, const char *file, const char *expression); #define NOT_REACHED() NotReachedError(__LINE__, __FILE__) /* For non-debug builds with assertions enabled use the special assertion handler. */ #if defined(NDEBUG) && defined(WITH_ASSERT) # undef assert -# define assert(expression) do { if (unlikely(!(expression))) AssertFailedError(__LINE__, __FILE__, #expression); } while (false) +# define assert(expression) do { if (!(expression)) [[unlikely]] AssertFailedError(__LINE__, __FILE__, #expression); } while (false) #endif /* Define JSON_ASSERT, which is used by nlohmann-json. Otherwise the header-file diff --git a/src/strgen/strgen.cpp b/src/strgen/strgen.cpp index 49ca24087e..6b65b60cfb 100644 --- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -49,7 +49,7 @@ void StrgenErrorI(const std::string &msg) _errors++; } -void NORETURN StrgenFatalI(const std::string &msg) +[[noreturn]] void StrgenFatalI(const std::string &msg) { fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg); #ifdef _MSC_VER @@ -58,7 +58,7 @@ void NORETURN StrgenFatalI(const std::string &msg) throw std::exception(); } -void NORETURN FatalErrorI(const std::string &msg) +[[noreturn]] void FatalErrorI(const std::string &msg) { fmt::print(stderr, LINE_NUM_FMT("FATAL"), _file, _cur_line, msg); #ifdef _MSC_VER diff --git a/src/strgen/strgen.h b/src/strgen/strgen.h index e07c19b098..b7ff9ef4cb 100644 --- a/src/strgen/strgen.h +++ b/src/strgen/strgen.h @@ -149,7 +149,7 @@ ParsedCommandStruct ExtractCommandString(const char *s, bool warnings); void StrgenWarningI(const std::string &msg); void StrgenErrorI(const std::string &msg); -void NORETURN StrgenFatalI(const std::string &msg); +[[noreturn]] void StrgenFatalI(const std::string &msg); #define StrgenWarning(format_string, ...) StrgenWarningI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) #define StrgenError(format_string, ...) StrgenErrorI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) #define StrgenFatal(format_string, ...) StrgenFatalI(fmt::format(FMT_STRING(format_string), ## __VA_ARGS__)) diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp index e589c4f20e..0fe5e2b053 100644 --- a/src/terraform_gui.cpp +++ b/src/terraform_gui.cpp @@ -83,7 +83,7 @@ static void GenerateRockyArea(TileIndex end, TileIndex start) switch (GetTileType(tile)) { case MP_TREES: if (GetTreeGround(tile) == TREE_GROUND_SHORE) continue; - FALLTHROUGH; + [[fallthrough]]; case MP_CLEAR: MakeClear(tile, CLEAR_ROCKS, 3); diff --git a/src/timer/timer.h b/src/timer/timer.h index d49d60aaff..3b76be0bac 100644 --- a/src/timer/timer.h +++ b/src/timer/timer.h @@ -30,7 +30,7 @@ public: * * @param period The period of the timer. */ - NODISCARD BaseTimer(const TPeriod period) : + [[nodiscard]] BaseTimer(const TPeriod period) : period(period) { TimerManager::RegisterTimer(*this); @@ -84,7 +84,7 @@ public: * @param interval The interval between each callback. * @param callback The callback to call when the interval has passed. */ - NODISCARD IntervalTimer(const TPeriod interval, std::function callback) : + [[nodiscard]] IntervalTimer(const TPeriod interval, std::function callback) : BaseTimer(interval), callback(callback) { @@ -127,7 +127,7 @@ public: * @param callback The callback to call when the timeout has passed. * @param start Whether to start the timer immediately. If false, you can call Reset() to start it. */ - NODISCARD TimeoutTimer(const TPeriod timeout, std::function callback, bool start = false) : + [[nodiscard]] TimeoutTimer(const TPeriod timeout, std::function callback, bool start = false) : BaseTimer(timeout), fired(!start), callback(callback) diff --git a/src/timetable_gui.cpp b/src/timetable_gui.cpp index 961e25eda2..a7e700f536 100644 --- a/src/timetable_gui.cpp +++ b/src/timetable_gui.cpp @@ -261,7 +261,7 @@ struct TimetableWindow : Window { SetDParamMaxValue(1, TimerGameEconomy::DateAtStartOfYear(EconomyTime::MAX_YEAR), 0, FS_SMALL); size->width = std::max(GetStringBoundingBox(STR_TIMETABLE_ARRIVAL_DATE).width, GetStringBoundingBox(STR_TIMETABLE_DEPARTURE_DATE).width) + WidgetDimensions::scaled.hsep_wide + padding.width; } - FALLTHROUGH; + [[fallthrough]]; case WID_VT_ARRIVAL_DEPARTURE_SELECTION: case WID_VT_TIMETABLE_PANEL: diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 5663c11815..212c979eba 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1599,7 +1599,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t case TL_3X3_GRID: // Use 2x2 grid afterwards! GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); - FALLTHROUGH; + [[fallthrough]]; case TL_2X2_GRID: rcmd = GetTownRoadGridElement(t1, tile, target_dir); @@ -1608,7 +1608,7 @@ static void GrowTownInTile(TileIndex *tile_ptr, RoadBits cur_rb, DiagDirection t case TL_BETTER_ROADS: // Use original afterwards! GrowTownWithExtraHouse(t1, TileAddByDiagDir(house_tile, target_dir)); - FALLTHROUGH; + [[fallthrough]]; case TL_ORIGINAL: /* Allow a house at the edge. 60% chance or @@ -3764,7 +3764,7 @@ Town *ClosestTownFromTile(TileIndex tile, uint threshold) return town; } - FALLTHROUGH; + [[fallthrough]]; case MP_HOUSE: return Town::GetByTile(tile); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index c3e1bf1a2a..39b8dfa89b 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -314,7 +314,7 @@ public: /* When double-clicking, continue */ if (click_count == 1 || y < 0 || !HasBit(this->available_actions, y)) break; - FALLTHROUGH; + [[fallthrough]]; } case WID_TA_EXECUTE: diff --git a/src/train.h b/src/train.h index f863250e5c..ae584e78d1 100644 --- a/src/train.h +++ b/src/train.h @@ -86,7 +86,7 @@ struct TrainCache { /** * 'Train' is either a loco or a wagon. */ -struct Train FINAL : public GroundVehicle { +struct Train final : public GroundVehicle { TrainCache tcache; /* Link between the two ends of a multiheaded engine */ diff --git a/src/train_cmd.cpp b/src/train_cmd.cpp index 5d019380d2..12f4f9da15 100644 --- a/src/train_cmd.cpp +++ b/src/train_cmd.cpp @@ -2644,7 +2644,7 @@ public: case OT_GOTO_DEPOT: /* Skip service in depot orders when the train doesn't need service. */ if ((order->GetDepotOrderType() & ODTFB_SERVICE) && !this->v->NeedsServicing()) break; - FALLTHROUGH; + [[fallthrough]]; case OT_GOTO_STATION: case OT_GOTO_WAYPOINT: this->v->current_order = *order; @@ -3781,7 +3781,7 @@ static bool TrainApproachingLineEnd(Train *v, bool signal, bool reverse) * for other directions, it will be 1, 3, 5, ..., 15 */ switch (v->direction) { case DIR_N : x = ~x + ~y + 25; break; - case DIR_NW: x = y; FALLTHROUGH; + case DIR_NW: x = y; [[fallthrough]]; case DIR_NE: x = ~x + 16; break; case DIR_E : x = ~x + y + 9; break; case DIR_SE: x = y; break; diff --git a/src/tree_cmd.cpp b/src/tree_cmd.cpp index 99406f81fb..0263f819fb 100644 --- a/src/tree_cmd.cpp +++ b/src/tree_cmd.cpp @@ -428,7 +428,7 @@ CommandCost CmdPlantTree(DoCommandFlag flags, TileIndex tile, TileIndex start_ti msg = STR_ERROR_CAN_T_BUILD_ON_WATER; continue; } - FALLTHROUGH; + [[fallthrough]]; case MP_CLEAR: { if (IsBridgeAbove(current_tile)) { @@ -744,7 +744,7 @@ static void TileLoop_Trees(TileIndex tile) SetTreeGrowth(tile, 0); break; } - FALLTHROUGH; + [[fallthrough]]; case 2: { // add a neighbouring tree if (!CanPlantExtraTrees(tile)) break; diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 5acb56f853..78395a64d7 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1391,7 +1391,7 @@ bool Vehicle::HandleBreakdown() SetWindowDirty(WC_VEHICLE_VIEW, this->index); SetWindowDirty(WC_VEHICLE_DETAILS, this->index); - FALLTHROUGH; + [[fallthrough]]; case 1: /* Aircraft breakdowns end only when arriving at the airport */ if (this->type == VEH_AIRCRAFT) return false; diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index de0a11f11d..f034689720 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1071,7 +1071,7 @@ struct RefitWindow : public Window { Vehicle *v = Vehicle::Get(this->window_number); this->selected_vehicle = v->index; this->num_vehicles = UINT8_MAX; - FALLTHROUGH; + [[fallthrough]]; } case 2: { // The vehicle selection has changed; rebuild the entire list. @@ -1097,7 +1097,7 @@ struct RefitWindow : public Window { this->information_width = max_width; this->ReInit(); } - FALLTHROUGH; + [[fallthrough]]; } case 1: // A new cargo has been selected. @@ -1158,7 +1158,7 @@ struct RefitWindow : public Window { if (_ctrl_pressed) this->num_vehicles = UINT8_MAX; break; } - FALLTHROUGH; + [[fallthrough]]; } default: @@ -1193,7 +1193,7 @@ struct RefitWindow : public Window { this->InvalidateData(1); if (click_count == 1) break; - FALLTHROUGH; + [[fallthrough]]; } case WID_VR_REFIT: // refit button @@ -3166,7 +3166,7 @@ public: str = STR_VEHICLE_STATUS_LEAVING; break; } - FALLTHROUGH; + [[fallthrough]]; default: if (v->GetNumManualOrders() == 0) { str = STR_VEHICLE_STATUS_NO_ORDERS_VEL; diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp index 1f53986599..5095b71ee0 100644 --- a/src/vehiclelist.cpp +++ b/src/vehiclelist.cpp @@ -145,7 +145,7 @@ bool GenerateVehicleSortList(VehicleList *list, const VehicleListIdentifier &vli } break; } - FALLTHROUGH; + [[fallthrough]]; case VL_STANDARD: for (const Vehicle *v : Vehicle::Iterate()) { diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index a2710186a2..23287b04a8 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -424,7 +424,7 @@ LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_PALETTECHANGED: if ((HWND)wParam == hwnd) return 0; - FALLTHROUGH; + [[fallthrough]]; case WM_QUERYNEWPALETTE: video_driver->PaletteChanged(hwnd); diff --git a/src/viewport.cpp b/src/viewport.cpp index 77e93cb2ff..0c40926e81 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2895,7 +2895,7 @@ static int CalcHeightdiff(HighLightStyle style, uint distance, TileIndex start_t byte style_t = (byte)(TileX(end_tile) > TileX(start_tile)); start_tile = TILE_ADD(start_tile, ToTileIndexDiff(heightdiff_area_by_dir[style_t])); end_tile = TILE_ADD(end_tile, ToTileIndexDiff(heightdiff_area_by_dir[2 + style_t])); - FALLTHROUGH; + [[fallthrough]]; } case HT_POINT: @@ -3240,7 +3240,7 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method) case VPM_X_LIMITED: // Drag in X direction (limited size). limit = (_thd.sizelimit - 1) * TILE_SIZE; - FALLTHROUGH; + [[fallthrough]]; case VPM_FIX_X: // drag in Y direction x = sx; @@ -3249,7 +3249,7 @@ void VpSelectTilesWithMethod(int x, int y, ViewportPlaceMethod method) case VPM_Y_LIMITED: // Drag in Y direction (limited size). limit = (_thd.sizelimit - 1) * TILE_SIZE; - FALLTHROUGH; + [[fallthrough]]; case VPM_FIX_Y: // drag in X direction y = sy; @@ -3286,7 +3286,7 @@ calc_heightdiff_single_direction:; limit = (_thd.sizelimit - 1) * TILE_SIZE; x = sx + Clamp(x - sx, -limit, limit); y = sy + Clamp(y - sy, -limit, limit); - FALLTHROUGH; + [[fallthrough]]; case VPM_X_AND_Y: // drag an X by Y area if (_settings_client.gui.measure_tooltip) { diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index 50d105dbc9..21bf4dbd21 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -165,7 +165,7 @@ bool IsPossibleDockingTile(Tile t) switch (GetTileType(t)) { case MP_WATER: if (IsLock(t) && GetLockPart(t) == LOCK_PART_MIDDLE) return false; - FALLTHROUGH; + [[fallthrough]]; case MP_RAILWAY: case MP_STATION: case MP_TUNNELBRIDGE: @@ -507,7 +507,7 @@ CommandCost CmdBuildCanal(DoCommandFlag flags, TileIndex tile, TileIndex start_t MakeSea(current_tile); break; } - FALLTHROUGH; + [[fallthrough]]; default: MakeCanal(current_tile, _current_company, Random()); @@ -1087,7 +1087,7 @@ FloodingBehaviour GetFloodingBehaviour(TileIndex tile) Slope tileh = GetTileSlope(tile); return (IsSlopeWithOneCornerRaised(tileh) ? FLOOD_ACTIVE : FLOOD_DRYUP); } - FALLTHROUGH; + [[fallthrough]]; case MP_STATION: case MP_INDUSTRY: case MP_OBJECT: @@ -1139,7 +1139,7 @@ void DoFloodTile(TileIndex target) flooded = true; break; } - FALLTHROUGH; + [[fallthrough]]; case MP_CLEAR: if (Command::Do(DC_EXEC, target).Succeeded()) { diff --git a/src/waypoint_base.h b/src/waypoint_base.h index 3ddbfc2d99..87f5d55c93 100644 --- a/src/waypoint_base.h +++ b/src/waypoint_base.h @@ -13,7 +13,7 @@ #include "base_station_base.h" /** Representation of a waypoint. */ -struct Waypoint FINAL : SpecializedStation { +struct Waypoint final : SpecializedStation { uint16_t town_cn; ///< The N-1th waypoint for this town (consecutive number) /** diff --git a/src/widget.cpp b/src/widget.cpp index 65d105292b..65278c0003 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2641,7 +2641,7 @@ void NWidgetLeaf::SetupSmallestSize(Window *w) size.width = std::max(size.width, ScaleGUITrad(30) + sprite_size.width); size.height = std::max(sprite_size.height, GetStringBoundingBox("_").height + WidgetDimensions::scaled.framerect.Vertical()); } - FALLTHROUGH; + [[fallthrough]]; case WWT_PUSHBTN: { padding = {WidgetDimensions::scaled.frametext.Horizontal(), WidgetDimensions::scaled.framerect.Vertical()}; break; @@ -2953,7 +2953,7 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg case WPT_RESIZE: { NWidgetResizeBase *nwrb = dynamic_cast(dest.get()); - if (unlikely(nwrb == nullptr)) throw std::runtime_error("WPT_RESIZE requires NWidgetResizeBase"); + if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_RESIZE requires NWidgetResizeBase"); assert(nwid_begin->u.xy.x >= 0 && nwid_begin->u.xy.y >= 0); nwrb->SetResize(nwid_begin->u.xy.x, nwid_begin->u.xy.y); break; @@ -2961,7 +2961,7 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg case WPT_MINSIZE: { NWidgetResizeBase *nwrb = dynamic_cast(dest.get()); - if (unlikely(nwrb == nullptr)) throw std::runtime_error("WPT_MINSIZE requires NWidgetResizeBase"); + if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINSIZE requires NWidgetResizeBase"); assert(nwid_begin->u.xy.x >= 0 && nwid_begin->u.xy.y >= 0); nwrb->SetMinimalSize(nwid_begin->u.xy.x, nwid_begin->u.xy.y); break; @@ -2969,7 +2969,7 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg case WPT_MINTEXTLINES: { NWidgetResizeBase *nwrb = dynamic_cast(dest.get()); - if (unlikely(nwrb == nullptr)) throw std::runtime_error("WPT_MINTEXTLINES requires NWidgetResizeBase"); + if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_MINTEXTLINES requires NWidgetResizeBase"); assert(nwid_begin->u.text_lines.size >= FS_BEGIN && nwid_begin->u.text_lines.size < FS_END); nwrb->SetMinimalTextLines(nwid_begin->u.text_lines.lines, nwid_begin->u.text_lines.spacing, nwid_begin->u.text_lines.size); break; @@ -2977,35 +2977,35 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg case WPT_TEXTSTYLE: { NWidgetCore *nwc = dynamic_cast(dest.get()); - if (unlikely(nwc == nullptr)) throw std::runtime_error("WPT_TEXTSTYLE requires NWidgetCore"); + if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_TEXTSTYLE requires NWidgetCore"); nwc->SetTextStyle(nwid_begin->u.text_style.colour, nwid_begin->u.text_style.size); break; } case WPT_ALIGNMENT: { NWidgetCore *nwc = dynamic_cast(dest.get()); - if (unlikely(nwc == nullptr)) throw std::runtime_error("WPT_ALIGNMENT requires NWidgetCore"); + if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_ALIGNMENT requires NWidgetCore"); nwc->SetAlignment(nwid_begin->u.align.align); break; } case WPT_FILL: { NWidgetResizeBase *nwrb = dynamic_cast(dest.get()); - if (unlikely(nwrb == nullptr)) throw std::runtime_error("WPT_FILL requires NWidgetResizeBase"); + if (nwrb == nullptr) [[unlikely]] throw std::runtime_error("WPT_FILL requires NWidgetResizeBase"); nwrb->SetFill(nwid_begin->u.xy.x, nwid_begin->u.xy.y); break; } case WPT_DATATIP: { NWidgetCore *nwc = dynamic_cast(dest.get()); - if (unlikely(nwc == nullptr)) throw std::runtime_error("WPT_DATATIP requires NWidgetCore"); + if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_DATATIP requires NWidgetCore"); nwc->widget_data = nwid_begin->u.data_tip.data; nwc->tool_tip = nwid_begin->u.data_tip.tooltip; break; } case WPT_PADDING: - if (unlikely(dest == nullptr)) throw std::runtime_error("WPT_PADDING requires NWidgetBase"); + if (dest == nullptr) [[unlikely]] throw std::runtime_error("WPT_PADDING requires NWidgetBase"); dest->SetPadding(nwid_begin->u.padding); break; @@ -3016,7 +3016,7 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg NWidgetBackground *nwb = dynamic_cast(dest.get()); if (nwb != nullptr) nwb->SetPIP(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post); - if (unlikely(nwc == nullptr && nwb == nullptr)) throw std::runtime_error("WPT_PIPSPACE requires NWidgetPIPContainer or NWidgetBackground"); + if (nwc == nullptr && nwb == nullptr) [[unlikely]] throw std::runtime_error("WPT_PIPSPACE requires NWidgetPIPContainer or NWidgetBackground"); break; } @@ -3027,13 +3027,13 @@ static const NWidgetPart *MakeNWidget(const NWidgetPart *nwid_begin, const NWidg NWidgetBackground *nwb = dynamic_cast(dest.get()); if (nwb != nullptr) nwb->SetPIPRatio(nwid_begin->u.pip.pre, nwid_begin->u.pip.inter, nwid_begin->u.pip.post); - if (unlikely(nwc == nullptr && nwb == nullptr)) throw std::runtime_error("WPT_PIPRATIO requires NWidgetPIPContainer or NWidgetBackground"); + if (nwc == nullptr && nwb == nullptr) [[unlikely]] throw std::runtime_error("WPT_PIPRATIO requires NWidgetPIPContainer or NWidgetBackground"); break; } case WPT_SCROLLBAR: { NWidgetCore *nwc = dynamic_cast(dest.get()); - if (unlikely(nwc == nullptr)) throw std::runtime_error("WPT_SCROLLBAR requires NWidgetCore"); + if (nwc == nullptr) [[unlikely]] throw std::runtime_error("WPT_SCROLLBAR requires NWidgetCore"); nwc->scrollbar_index = nwid_begin->u.widget.index; break; } @@ -3139,7 +3139,7 @@ std::unique_ptr MakeNWidgets(const NWidgetPart *nwid_begin, const N if (container == nullptr) container = std::make_unique(); [[maybe_unused]] const NWidgetPart *nwid_part = MakeWidgetTree(nwid_begin, nwid_end, container); #ifdef WITH_ASSERT - if (unlikely(nwid_part != nwid_end)) throw std::runtime_error("Did not consume all NWidgetParts"); + if (nwid_part != nwid_end) [[unlikely]] throw std::runtime_error("Did not consume all NWidgetParts"); #endif return std::move(container); } diff --git a/src/window.cpp b/src/window.cpp index a33c3c0177..b0ae97fc5c 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1267,45 +1267,45 @@ static uint GetWindowZPriority(WindowClass wc) switch (wc) { case WC_TOOLTIPS: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_ERRMSG: case WC_CONFIRM_POPUP_QUERY: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_ENDSCREEN: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_HIGHSCORE: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_DROPDOWN_MENU: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_MAIN_TOOLBAR: case WC_STATUS_BAR: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_OSK: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_QUERY_STRING: case WC_SEND_NETWORK_MSG: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_NETWORK_ASK_RELAY: case WC_MODAL_PROGRESS: case WC_NETWORK_STATUS_WINDOW: case WC_SAVE_PRESET: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_GENERATE_LANDSCAPE: case WC_SAVELOAD: @@ -1317,19 +1317,19 @@ static uint GetWindowZPriority(WindowClass wc) case WC_SCRIPT_SETTINGS: case WC_TEXTFILE: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_CONSOLE: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_NEWS_WINDOW: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; default: ++z_priority; - FALLTHROUGH; + [[fallthrough]]; case WC_MAIN_WINDOW: return z_priority; @@ -2844,7 +2844,7 @@ static void MouseLoop(MouseClick click, int mousewheel) if (!scrollwheel_scrolling || w == nullptr || w->window_class != WC_SMALLMAP) break; /* We try to use the scrollwheel to scroll since we didn't touch any of the buttons. * Simulate a right button click so we can get started. */ - FALLTHROUGH; + [[fallthrough]]; case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top);