diff --git a/.clang-tidy b/.clang-tidy index 780be01410..3c0dcb01c1 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -12,12 +12,31 @@ Checks: >- modernize-*, performance-*, readability-*, + -bugprone-assignment-in-if-condition, + -bugprone-casting-through-void, + -bugprone-easily-swappable-parameters, + -bugprone-empty-catch, + -bugprone-implicit-widening-of-multiplication-result, -bugprone-narrowing-conversions, + -bugprone-optional-value-conversion, + -bugprone-reserved-identifier, + -bugprone-switch-missing-default-case, -bugprone-too-small-loop-variable, + -bugprone-unchecked-optional-access, + -bugprone-unhandled-exception-at-new, + -clang-analyzer-core.NonNullParamChecker, + -clang-analyzer-cplusplus.NewDeleteLeaks, + -clang-analyzer-optin.core.EnumCastOutOfRange, -clang-analyzer-osx.*, + -misc-confusable-identifiers, + -misc-const-correctness, + -misc-include-cleaner, -misc-non-private-member-variables-in-classes, + -misc-no-recursion, -misc-unused-parameters, + -misc-use-anonymous-namespace, -modernize-avoid-c-arrays, + -modernize-macro-to-enum, -modernize-raw-string-literal, -modernize-return-braced-init-list, -modernize-use-default-member-init, @@ -25,15 +44,26 @@ Checks: >- -modernize-use-nodiscard, -modernize-use-override, -modernize-use-trailing-return-type, + -performance-avoid-endl, + -performance-enum-size, + -performance-move-const-arg, + -performance-no-int-to-ptr, + -readability-avoid-nested-conditional-operator, + -readability-avoid-return-with-void-value, -readability-braces-around-statements, -readability-convert-member-functions-to-static, -readability-else-after-return, + -readability-function-cognitive-complexity, + -readability-identifier-length, -readability-implicit-bool-conversion, -readability-isolate-declaration, -readability-magic-numbers, -readability-named-parameter, + -readability-redundant-casting, -readability-static-accessed-through-instance, + -readability-suspicious-call-argument, -readability-uppercase-literal-suffix, + -readability-use-anyofallof, -readability-identifier-naming, -clang-diagnostic-inconsistent-missing-override CheckOptions: @@ -43,5 +73,8 @@ CheckOptions: value: 'Point<.*?>;MapPoint;Position;Extent;DrawPoint' - key: performance-unnecessary-value-param.AllowedTypes value: 'Point<.*?>;MapPoint;Position;Extent;DrawPoint' -AnalyzeTemporaryDtors: false + - key: readability-function-cognitive-complexity.IgnoreMacros + value: true + - key: readability-simplify-boolean-expr.IgnoreMacros + value: true ... diff --git a/external/libendian b/external/libendian index db388230f9..f62a650f04 160000 --- a/external/libendian +++ b/external/libendian @@ -1 +1 @@ -Subproject commit db388230f996a75f7bf6f94771f79126028998d2 +Subproject commit f62a650f04d423423f3b86e0a98f1eb0b9c58199 diff --git a/external/libsiedler2 b/external/libsiedler2 index edc5719934..a2b0374f5d 160000 --- a/external/libsiedler2 +++ b/external/libsiedler2 @@ -1 +1 @@ -Subproject commit edc5719934c6e82d150dd46cfeffed280a698c97 +Subproject commit a2b0374f5d956080329acd2bcdd73beaf5f6b687 diff --git a/external/libutil b/external/libutil index 4658933aad..d9db182a0f 160000 --- a/external/libutil +++ b/external/libutil @@ -1 +1 @@ -Subproject commit 4658933aad0de12e9cdb552dde3aa408833df0fa +Subproject commit d9db182a0f1406da1792e05f010d2650a7095b1f diff --git a/external/mygettext b/external/mygettext index efe8aeb1d7..4ccddc8189 160000 --- a/external/mygettext +++ b/external/mygettext @@ -1 +1 @@ -Subproject commit efe8aeb1d7df3ea342136dd8ca88230dc76d637f +Subproject commit 4ccddc8189ec3e72cc79f9dc51a118e59d66ff39 diff --git a/external/s25edit b/external/s25edit index 0ec492ea5d..f2e3fd5d91 160000 --- a/external/s25edit +++ b/external/s25edit @@ -1 +1 @@ -Subproject commit 0ec492ea5d4e4e7f763001deacd75aa629c90a85 +Subproject commit f2e3fd5d91b6fff1f106cd83df99a227c9d40312 diff --git a/extras/audioDrivers/SDL/AudioSDL.cpp b/extras/audioDrivers/SDL/AudioSDL.cpp index f3b1b1f44d..e7e2ee73f3 100644 --- a/extras/audioDrivers/SDL/AudioSDL.cpp +++ b/extras/audioDrivers/SDL/AudioSDL.cpp @@ -142,7 +142,7 @@ driver::RawSoundHandle AudioSDL::LoadEffect(const std::string& filepath) driver::RawSoundHandle AudioSDL::LoadEffect(const std::vector& data, const std::string& /*ext*/) { - SDL_RWops* rwOps = SDL_RWFromConstMem(&data[0], static_cast(data.size())); + SDL_RWops* rwOps = SDL_RWFromConstMem(data.data(), static_cast(data.size())); Mix_Chunk* sound = Mix_LoadWAV_RW(rwOps, true); //-V601 if(sound == nullptr) diff --git a/libs/common/include/Rect.h b/libs/common/include/Rect.h index 6c5bbe6d64..e6b43aecda 100644 --- a/libs/common/include/Rect.h +++ b/libs/common/include/Rect.h @@ -20,8 +20,11 @@ template struct RectBase { using position_type = Point; + // Deactivated to bug in clang-tidy + // NOLINTBEGIN(modernize-type-traits) using extent_elem_type = typename std::conditional_t, std::make_unsigned, std::common_type>::type; + // NOLINTEND(modernize-type-traits) using extent_type = Point; T left, top, right, bottom; constexpr RectBase() : RectBase(position_type::all(0), extent_type::all(0)) {} diff --git a/libs/common/include/helpers/serializeContainers.h b/libs/common/include/helpers/serializeContainers.h index ca0f39349a..0af2e6f75b 100644 --- a/libs/common/include/helpers/serializeContainers.h +++ b/libs/common/include/helpers/serializeContainers.h @@ -35,8 +35,11 @@ namespace detail { void pushContainer(Serializer& ser, const T& container, long) { using Type = typename T::value_type; + // Deactivated to bug in clang-tidy + // NOLINTBEGIN(modernize-type-traits) using Integral = typename std::conditional_t, std::underlying_type, std::common_type>::type; + // NOLINTEND(modernize-type-traits) for(const auto el : container) { // Cast also required for bool vector -.- diff --git a/libs/s25main/Debug.cpp b/libs/s25main/Debug.cpp index 413a9f59c9..9c5ded36d8 100644 --- a/libs/s25main/Debug.cpp +++ b/libs/s25main/Debug.cpp @@ -132,10 +132,10 @@ bool captureBacktrace(DebugInfo::stacktrace_t& stacktrace, LPCONTEXT ctx) noexce return true; } #else -bool captureBacktrace(DebugInfo::stacktrace_t& stacktrace, void*) noexcept +bool captureBacktrace(DebugInfo::stacktrace_t& stacktrace, void*) noexcept(false) { # if RTTR_BACKTRACE_HAS_FUNCTION - const auto num_frames = backtrace(&stacktrace[0], stacktrace.size()); + const auto num_frames = backtrace(stacktrace.data(), stacktrace.size()); stacktrace.resize(num_frames); return true; # else @@ -182,7 +182,7 @@ DebugInfo::~DebugInfo() sock.Close(); } -DebugInfo::stacktrace_t DebugInfo::GetStackTrace(void* ctx) noexcept +DebugInfo::stacktrace_t DebugInfo::GetStackTrace(void* ctx) noexcept(false) { #ifndef RTTR_CONTEXT_PTR_TYPE using RTTR_CONTEXT_PTR_TYPE = void*; @@ -267,7 +267,7 @@ bool DebugInfo::SendStackTrace(const stacktrace_t& stacktrace) endStacktrace.push_back(reinterpret_cast(ptr)); unsigned stacktraceLen = sizeof(littleVoid_t) * endStacktrace.size(); - return SendString(reinterpret_cast(&endStacktrace[0]), stacktraceLen); + return SendString(reinterpret_cast(endStacktrace.data()), stacktraceLen); } bool DebugInfo::SendReplay() diff --git a/libs/s25main/Debug.h b/libs/s25main/Debug.h index 907b0d7808..399c5a08d1 100644 --- a/libs/s25main/Debug.h +++ b/libs/s25main/Debug.h @@ -21,7 +21,7 @@ class DebugInfo DebugInfo(); ~DebugInfo(); - static stacktrace_t GetStackTrace(void* ctx = nullptr) noexcept; + static stacktrace_t GetStackTrace(void* ctx = nullptr) noexcept(false); bool Send(const void* buffer, size_t length); bool SendSigned(int32_t i); diff --git a/libs/s25main/GameCommands.h b/libs/s25main/GameCommands.h index 1825ce15ae..f1c42eb7e8 100644 --- a/libs/s25main/GameCommands.h +++ b/libs/s25main/GameCommands.h @@ -447,7 +447,7 @@ class SetInventorySetting : public Coords protected: SetInventorySetting(const MapPoint pt, boost_variant2 what, const InventorySetting state) - : Coords(GCType::SetInventorySetting, pt), what(std::move(what)), state(state) + : Coords(GCType::SetInventorySetting, pt), what(what), state(state) {} SetInventorySetting(Serializer& ser) : Coords(GCType::SetInventorySetting, ser) @@ -806,7 +806,7 @@ class TradeOverLand : public Coords protected: /// Note: Can only trade wares or figures! TradeOverLand(const MapPoint pt, boost_variant2 what, const uint32_t count) - : Coords(GCType::Trade, pt), what(std::move(what)), count(count) + : Coords(GCType::Trade, pt), what(what), count(count) {} TradeOverLand(Serializer& ser) : Coords(GCType::Trade, ser) { diff --git a/libs/s25main/GamePlayer.cpp b/libs/s25main/GamePlayer.cpp index 18c09f3102..edba56e759 100644 --- a/libs/s25main/GamePlayer.cpp +++ b/libs/s25main/GamePlayer.cpp @@ -160,7 +160,7 @@ void GamePlayer::Serialize(SerializedGameData& sgd) const sgd.PushEnum(ps); // Nur richtige Spieler serialisieren - if(!(ps == PlayerState::Occupied || ps == PlayerState::AI)) + if(ps != PlayerState::Occupied && ps != PlayerState::AI) return; sgd.PushBool(isDefeated); @@ -234,7 +234,7 @@ void GamePlayer::Deserialize(SerializedGameData& sgd) // Ehemaligen PS auslesen auto origin_ps = sgd.Pop(); // Nur richtige Spieler serialisieren - if(!(origin_ps == PlayerState::Occupied || origin_ps == PlayerState::AI)) + if(origin_ps != PlayerState::Occupied && origin_ps != PlayerState::AI) return; isDefeated = sgd.PopBool(); @@ -614,14 +614,14 @@ bool GamePlayer::FindCarrierForRoad(RoadSegment* rs) const { // dann braucht man Träger UND Boot best[0] = FindWarehouse(*rs->GetF1(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false, - &length[0], rs); + length.data(), rs); // 2. Flagge des Weges best[1] = FindWarehouse(*rs->GetF2(), FW::HasWareAndFigure(GoodType::Boat, Job::Helper, false), false, false, &length[1], rs); } else { // 1. Flagge des Weges - best[0] = FindWarehouse(*rs->GetF1(), FW::HasFigure(Job::Helper, false), false, false, &length[0], rs); + best[0] = FindWarehouse(*rs->GetF1(), FW::HasFigure(Job::Helper, false), false, false, length.data(), rs); // 2. Flagge des Weges best[1] = FindWarehouse(*rs->GetF2(), FW::HasFigure(Job::Helper, false), false, false, &length[1], rs); } @@ -878,7 +878,7 @@ nofCarrier* GamePlayer::OrderDonkey(RoadSegment* road) const std::array best; // 1. Flagge des Weges - best[0] = FindWarehouse(*road->GetF1(), FW::HasFigure(Job::PackDonkey, false), false, false, &length[0], road); + best[0] = FindWarehouse(*road->GetF1(), FW::HasFigure(Job::PackDonkey, false), false, false, length.data(), road); // 2. Flagge des Weges best[1] = FindWarehouse(*road->GetF2(), FW::HasFigure(Job::PackDonkey, false), false, false, &length[1], road); diff --git a/libs/s25main/Replay.cpp b/libs/s25main/Replay.cpp index dbf50b28a9..231b853dd0 100644 --- a/libs/s25main/Replay.cpp +++ b/libs/s25main/Replay.cpp @@ -155,11 +155,11 @@ bool Replay::StartRecording(const boost::filesystem::path& filepath, const MapIn RTTR_Assert(!mapInfo.savegame); file_.WriteUnsignedInt(mapInfo.mapData.uncompressedLength); file_.WriteUnsignedInt(mapInfo.mapData.data.size()); - file_.WriteRawData(&mapInfo.mapData.data[0], mapInfo.mapData.data.size()); + file_.WriteRawData(mapInfo.mapData.data.data(), mapInfo.mapData.data.size()); file_.WriteUnsignedInt(mapInfo.luaData.uncompressedLength); file_.WriteUnsignedInt(mapInfo.luaData.data.size()); if(!mapInfo.luaData.data.empty()) - file_.WriteRawData(&mapInfo.luaData.data[0], mapInfo.luaData.data.size()); + file_.WriteRawData(mapInfo.luaData.data.data(), mapInfo.luaData.data.size()); break; case MapType::Savegame: mapInfo.savegame->Save(file_, GetMapName()); break; } @@ -269,11 +269,11 @@ bool Replay::LoadGameData(MapInfo& mapInfo) case MapType::OldMap: mapInfo.mapData.uncompressedLength = file_.ReadUnsignedInt(); mapInfo.mapData.data.resize(file_.ReadUnsignedInt()); - file_.ReadRawData(&mapInfo.mapData.data[0], mapInfo.mapData.data.size()); + file_.ReadRawData(mapInfo.mapData.data.data(), mapInfo.mapData.data.size()); mapInfo.luaData.uncompressedLength = file_.ReadUnsignedInt(); mapInfo.luaData.data.resize(file_.ReadUnsignedInt()); if(!mapInfo.luaData.data.empty()) - file_.ReadRawData(&mapInfo.luaData.data[0], mapInfo.luaData.data.size()); + file_.ReadRawData(mapInfo.luaData.data.data(), mapInfo.luaData.data.size()); break; case MapType::Savegame: mapInfo.savegame = std::make_unique(); diff --git a/libs/s25main/SavedFile.cpp b/libs/s25main/SavedFile.cpp index f713edf308..1a2e28e326 100644 --- a/libs/s25main/SavedFile.cpp +++ b/libs/s25main/SavedFile.cpp @@ -38,7 +38,7 @@ void SavedFile::WriteExtHeader(BinaryFile& file, const std::string& mapName) mapName_ = mapName; // Program version - file.WriteRawData(&revision[0], revision.size()); + file.WriteRawData(revision.data(), revision.size()); s25util::time64_t tmpTime = libendian::ConvertEndianess::fromNative(saveTime_); file.WriteRawData(&tmpTime, sizeof(tmpTime)); file.WriteShortString(mapName); @@ -57,7 +57,7 @@ bool SavedFile::ReadFileHeader(BinaryFile& file) throw std::range_error("Program signature is to long!"); try { - file.ReadRawData(&read_signature[0], signature.size()); + file.ReadRawData(read_signature.data(), signature.size()); // Signatur überprüfen if(!std::equal(signature.begin(), signature.end(), read_signature.begin())) @@ -88,7 +88,7 @@ bool SavedFile::ReadFileHeader(BinaryFile& file) bool SavedFile::ReadExtHeader(BinaryFile& file) { - file.ReadRawData(&revision[0], revision.size()); + file.ReadRawData(revision.data(), revision.size()); file.ReadRawData(&saveTime_, sizeof(saveTime_)); saveTime_ = libendian::ConvertEndianess::toNative(saveTime_); mapName_ = file.ReadShortString(); diff --git a/libs/s25main/Ware.h b/libs/s25main/Ware.h index 1a4c820b40..d70b300f73 100644 --- a/libs/s25main/Ware.h +++ b/libs/s25main/Ware.h @@ -99,7 +99,7 @@ class Ware : public GameObject noRoadNode* GetLocation() { return location; } const noRoadNode* GetLocation() const { return location; } /// Ist die Ware eine LostWare (Ware, die kein Ziel mehr hat und irgendwo sinnlos rumliegt)? - bool IsLostWare() const { return ((goal ? false : true) && state != State::OnShip); } + bool IsLostWare() const { return ((goal == nullptr) && state != State::OnShip); } /// Informiert Ware, dass eine Schiffsreise beginnt void StartShipJourney(); /// Informiert Ware, dass Schiffsreise beendet ist und die Ware nun in einem Hafengebäude liegt diff --git a/libs/s25main/ai/aijh/Jobs.h b/libs/s25main/ai/aijh/Jobs.h index f823164415..ab4d91d8db 100644 --- a/libs/s25main/ai/aijh/Jobs.h +++ b/libs/s25main/ai/aijh/Jobs.h @@ -57,7 +57,7 @@ class JobWithTarget { public: JobWithTarget() : target(MapPoint::Invalid()) {} - inline MapPoint GetTarget() const { return target; } + MapPoint GetTarget() const { return target; } void SetTarget(MapPoint newTarget) { target = newTarget; } protected: @@ -72,8 +72,8 @@ class BuildJob : public AIJob, public JobWithTarget {} void ExecuteJob() override; - inline BuildingType GetType() const { return type; } - inline MapPoint GetAround() const { return around; } + BuildingType GetType() const { return type; } + MapPoint GetAround() const { return around; } private: BuildingType type; diff --git a/libs/s25main/buildings/nobHarborBuilding.cpp b/libs/s25main/buildings/nobHarborBuilding.cpp index f321f16e8f..c7ad44a99f 100644 --- a/libs/s25main/buildings/nobHarborBuilding.cpp +++ b/libs/s25main/buildings/nobHarborBuilding.cpp @@ -1255,7 +1255,7 @@ void nobHarborBuilding::CancelSeaAttacker(nofAttacker* attacker) unsigned nobHarborBuilding::CalcDistributionPoints(const GoodType type) const { // Ist überhaupt eine Expedition im Gang und ein entsprechender Warentyp - if(!expedition.active || !(type == GoodType::Boards || type == GoodType::Stones)) + if(!expedition.active || (type != GoodType::Boards && type != GoodType::Stones)) return 0; unsigned ordered_boards = 0, ordered_stones = 0; diff --git a/libs/s25main/controls/ctrlChat.cpp b/libs/s25main/controls/ctrlChat.cpp index 7078d63ab4..2acf35614e 100644 --- a/libs/s25main/controls/ctrlChat.cpp +++ b/libs/s25main/controls/ctrlChat.cpp @@ -117,7 +117,7 @@ void ctrlChat::Draw_() for(unsigned i = 0; i < show_lines; ++i) { DrawPoint curTextPos = textPos; - if(PrimaryChatLine* line = get_if(&chat_lines[i + pos])) + if(auto* line = get_if(&chat_lines[i + pos])) { // Zeit, Spieler und danach Textnachricht if(!line->time_string.empty()) @@ -154,8 +154,8 @@ void ctrlChat::WrapLine(unsigned short i) // Breite von Zeitstring und Spielername berechnen (falls vorhanden) unsigned short prefix_width = - (line.time_string.length() ? font->getWidth(line.time_string) : 0) - + (line.player.length() ? (bracket1_size + bracket2_size + font->getWidth(line.player)) : 0); + (!line.time_string.empty() ? font->getWidth(line.time_string) : 0) + + (!line.player.empty() ? (bracket1_size + bracket2_size + font->getWidth(line.player)) : 0); // Reicht die Breite des Textfeldes noch nichtmal dafür aus? if(prefix_width > GetSize().x - 2 - SCROLLBAR_WIDTH) diff --git a/libs/s25main/controls/ctrlEdit.cpp b/libs/s25main/controls/ctrlEdit.cpp index 05e85ec1cd..1c2251c7c0 100644 --- a/libs/s25main/controls/ctrlEdit.cpp +++ b/libs/s25main/controls/ctrlEdit.cpp @@ -34,7 +34,7 @@ void ctrlEdit::SetText(const std::string& text) { text_ = s25util::utf8to32(text); if(numberOnly_) - helpers::erase_if(text_, [](char32_t c) { return !(c >= '0' && c <= '9'); }); + helpers::erase_if(text_, [](char32_t c) { return c < '0' || c > '9'; }); if(maxLength_ > 0 && text_.size() > maxLength_) text_.resize(maxLength_); @@ -168,7 +168,7 @@ void ctrlEdit::Draw_() void ctrlEdit::AddChar(char32_t c) { // Number-only text fields accept numbers only ;) - if(numberOnly_ && !(c >= '0' && c <= '9')) + if(numberOnly_ && (c < '0' || c > '9')) return; if(maxLength_ > 0 && text_.size() >= maxLength_) @@ -184,12 +184,12 @@ void ctrlEdit::AddChar(char32_t c) */ void ctrlEdit::RemoveChar() { - if(cursorPos_ > 0 && text_.length() > 0) + if(cursorPos_ > 0 && !text_.empty()) { text_.erase(cursorPos_ - 1, 1); // View verschieben - while(text_.length() > 0 && text_.length() <= viewStart_) + while(!text_.empty() && text_.length() <= viewStart_) --viewStart_; CursorLeft(); diff --git a/libs/s25main/controls/ctrlProgress.cpp b/libs/s25main/controls/ctrlProgress.cpp index de82895927..6d34414d84 100644 --- a/libs/s25main/controls/ctrlProgress.cpp +++ b/libs/s25main/controls/ctrlProgress.cpp @@ -32,9 +32,9 @@ ctrlProgress::ctrlProgress(Window* parent, const unsigned id, const DrawPoint& p Extent btSize = Extent::all(size.y); AddImageButton(0, DrawPoint(0, 0), btSize, tc, LOADER.GetImageN(btMinusRes, button_minus), - (button_minus_tooltip.length() ? button_minus_tooltip : _("Less"))); + (!button_minus_tooltip.empty() ? button_minus_tooltip : _("Less"))); AddImageButton(1, DrawPoint(size.x - btSize.x, 0), btSize, tc, LOADER.GetImageN(btPlusRes, button_plus), - (button_plus_tooltip.length() ? button_plus_tooltip : _("More"))); + (!button_plus_tooltip.empty() ? button_plus_tooltip : _("More"))); // Hide left and right 3D border by making the buttons overlap the bar padding_.x -= 2; diff --git a/libs/s25main/desktops/dskCredits.cpp b/libs/s25main/desktops/dskCredits.cpp index 573b70924b..a4e0aefac1 100644 --- a/libs/s25main/desktops/dskCredits.cpp +++ b/libs/s25main/desktops/dskCredits.cpp @@ -28,7 +28,6 @@ using namespace std::chrono_literals; const auto PAGE_TIME = 12900ms; /// Duration for fading between pages const auto FADING_TIME = 2s; -using std::chrono::duration_cast; namespace { enum diff --git a/libs/s25main/gameData/ShieldConsts.h b/libs/s25main/gameData/ShieldConsts.h index db4cd502cb..99d01e5c94 100644 --- a/libs/s25main/gameData/ShieldConsts.h +++ b/libs/s25main/gameData/ShieldConsts.h @@ -16,14 +16,14 @@ const helpers::EnumArray SUPPRESS_UNUSED SHIELD_TYPES = { /// Macht ggf. aus den verschiedenen Schilden der Nationen jeweils immer das römische normale Schild für /// die Warensysteme usw -inline constexpr GoodType ConvertShields(const GoodType& good) +constexpr GoodType ConvertShields(const GoodType& good) { return (good == GoodType::ShieldVikings || good == GoodType::ShieldAfricans || good == GoodType::ShieldJapanese) ? GoodType::ShieldRomans : good; } -inline constexpr GoodType convertShieldToNation(const GoodType good, const Nation nation) +constexpr GoodType convertShieldToNation(const GoodType good, const Nation nation) { return (good == GoodType::ShieldRomans) ? SHIELD_TYPES[nation] : good; } diff --git a/libs/s25main/gameTypes/BuildingTypes.h b/libs/s25main/gameTypes/BuildingTypes.h index e9678d2885..dd8ea38cec 100644 --- a/libs/s25main/gameTypes/BuildingTypes.h +++ b/libs/s25main/gameTypes/BuildingTypes.h @@ -45,8 +45,11 @@ struct BldWorkDescription helpers::OptionalEnum job = boost::none; /// Ware produced, if any helpers::OptionalEnum producedWare = boost::none; + // Required for use in aggregate initialization + // NOLINTBEGIN(readability-redundant-member-init) /// Wares the building needs, if any WaresNeeded waresNeeded = {}; + // NOLINTEND(readability-redundant-member-init) /// How many wares of each type can be stored uint8_t numSpacesPerWare = 6; /// True if one of each waresNeeded is used per production cycle diff --git a/libs/s25main/mapGenerator/Textures.h b/libs/s25main/mapGenerator/Textures.h index 79e685cbff..1d2ca10509 100644 --- a/libs/s25main/mapGenerator/Textures.h +++ b/libs/s25main/mapGenerator/Textures.h @@ -35,12 +35,12 @@ class TextureOperator terrains_(worldDesc_.terrain.findAll([landscape](const TerrainDesc& t) { return t.landscape == landscape; })) {} - inline uint8_t GetTextureId(DescIdx texture) const { return worldDesc_.get(texture).s2Id; } + uint8_t GetTextureId(DescIdx texture) const { return worldDesc_.get(texture).s2Id; } - inline uint8_t GetLandscapeId() const { return worldDesc_.get(landscape_).s2Id; } + uint8_t GetLandscapeId() const { return worldDesc_.get(landscape_).s2Id; } template - inline DescIdx Find(T_Predicate predicate) const + DescIdx Find(T_Predicate predicate) const { for(auto texture : terrains_) { @@ -54,7 +54,7 @@ class TextureOperator } template - inline std::vector> FindAll(T_Predicate predicate) const + std::vector> FindAll(T_Predicate predicate) const { auto condition = [&predicate, this](const auto& texture) { return predicate(worldDesc_.get(texture)); }; @@ -65,7 +65,7 @@ class TextureOperator } template - inline void Sort(std::vector>& textures, T_SortBy sortBy) const + void Sort(std::vector>& textures, T_SortBy sortBy) const { auto lessThan = [this, &sortBy](const auto& t1, const auto& t2) { return sortBy(worldDesc_.get(t1)) < sortBy(worldDesc_.get(t2)); @@ -75,7 +75,7 @@ class TextureOperator } template - inline bool Check(DescIdx texture, T_Predicate predicate) const + bool Check(DescIdx texture, T_Predicate predicate) const { return predicate(worldDesc_.get(texture)); } diff --git a/libs/s25main/network/GameServer.cpp b/libs/s25main/network/GameServer.cpp index 4605f8a1c9..9629195c8c 100644 --- a/libs/s25main/network/GameServer.cpp +++ b/libs/s25main/network/GameServer.cpp @@ -217,7 +217,7 @@ bool GameServer::Start(const CreateServerInfo& csi, const MapDescription& map, c lanAnnouncer.Start(); else if(config.servertype == ServerType::Lobby) { - LOBBYCLIENT.AddServer(config.gamename, mapinfo.title, (config.password.length() != 0), config.port); + LOBBYCLIENT.AddServer(config.gamename, mapinfo.title, (!config.password.empty()), config.port); LOBBYCLIENT.AddListener(this); } AnnounceStatusChange(); @@ -733,6 +733,7 @@ void GameServer::ExecuteNWF() // Notify players std::vector checksumHashes; + checksumHashes.reserve(networkPlayers.size()); for(const GameServerPlayer& player : networkPlayers) checksumHashes.push_back(nwfInfo.getPlayerCmds(player.playerId).checksum.getHash()); SendToAll(GameMessage_Server_Async(checksumHashes)); diff --git a/libs/s25main/network/GameServerPlayer.cpp b/libs/s25main/network/GameServerPlayer.cpp index 775b4927ab..7ff62c356b 100644 --- a/libs/s25main/network/GameServerPlayer.cpp +++ b/libs/s25main/network/GameServerPlayer.cpp @@ -42,7 +42,7 @@ void GameServerPlayer::setActive() void GameServerPlayer::doPing() { - ActiveState* state = get_if(&state_); + auto* state = get_if(&state_); if(state && !state->isPinging && (!state->pingTimer.isRunning() || state->pingTimer.getElapsed() >= seconds(PING_RATE))) { diff --git a/libs/s25main/network/NetworkPlayer.cpp b/libs/s25main/network/NetworkPlayer.cpp index 3462bfccea..1cac20accb 100644 --- a/libs/s25main/network/NetworkPlayer.cpp +++ b/libs/s25main/network/NetworkPlayer.cpp @@ -43,7 +43,7 @@ void NetworkPlayer::executeMsgs(MessageInterface& msgHandler) recvQueue.pop()->run(&msgHandler, playerId); } -void swap(NetworkPlayer& lhs, NetworkPlayer& rhs) +void swap(NetworkPlayer& lhs, NetworkPlayer& rhs) noexcept { using std::swap; swap(lhs.playerId, rhs.playerId); diff --git a/libs/s25main/network/NetworkPlayer.h b/libs/s25main/network/NetworkPlayer.h index ef525941ce..1bc041b6b7 100644 --- a/libs/s25main/network/NetworkPlayer.h +++ b/libs/s25main/network/NetworkPlayer.h @@ -35,4 +35,4 @@ class NetworkPlayer Socket socket; }; -void swap(NetworkPlayer& lhs, NetworkPlayer& rhs); +void swap(NetworkPlayer& lhs, NetworkPlayer& rhs) noexcept; diff --git a/libs/s25main/nodeObjs/noFlag.h b/libs/s25main/nodeObjs/noFlag.h index bccc6c3a17..79483862e0 100644 --- a/libs/s25main/nodeObjs/noFlag.h +++ b/libs/s25main/nodeObjs/noFlag.h @@ -26,10 +26,10 @@ class noFlag : public noRoadNode void Destroy() override; void Serialize(SerializedGameData& sgd) const override; - inline GO_Type GetGOT() const final { return GO_Type::Flag; } - inline FlagType GetFlagType() const { return flagtype; } + GO_Type GetGOT() const final { return GO_Type::Flag; } + FlagType GetFlagType() const { return flagtype; } /// Gibt Auskunft darüber, ob noch Platz für eine Ware an der Flagge ist. - inline bool HasSpaceForWare() const { return wares.size() < wares.max_size(); } + bool HasSpaceForWare() const { return wares.size() < wares.max_size(); } void Draw(DrawPoint drawPt) override; diff --git a/libs/s25main/ogl/glFont.cpp b/libs/s25main/ogl/glFont.cpp index 78e28e1994..9fcce96f5e 100644 --- a/libs/s25main/ogl/glFont.cpp +++ b/libs/s25main/ogl/glFont.cpp @@ -248,8 +248,8 @@ void glFont::Draw(DrawPoint pos, const std::string& text, FontStyle format, unsi for(GlPoint& pt : texList.texCoords) pt /= texSize; - glVertexPointer(2, GL_FLOAT, 0, &texList.vertices[0]); - glTexCoordPointer(2, GL_FLOAT, 0, &texList.texCoords[0]); + glVertexPointer(2, GL_FLOAT, 0, texList.vertices.data()); + glTexCoordPointer(2, GL_FLOAT, 0, texList.texCoords.data()); VIDEODRIVER.BindTexture(texture); glColor4ub(GetRed(color), GetGreen(color), GetBlue(color), GetAlpha(color)); glDrawArrays(GL_QUADS, 0, texList.vertices.size()); diff --git a/libs/s25main/pathfinding/NewNode.h b/libs/s25main/pathfinding/NewNode.h index 46dc666e77..3bd03855c6 100644 --- a/libs/s25main/pathfinding/NewNode.h +++ b/libs/s25main/pathfinding/NewNode.h @@ -24,11 +24,11 @@ struct NewNode unsigned prev = INVALID_PREV; unsigned prevEven = INVALID_PREV; /// Iterator auf Position in der Prioritätswarteschlange (std::set), freies Pathfinding - std::set::iterator it_p = {}; + std::set::iterator it_p; /// Wurde Knoten schon besucht (für A*-Algorithmus), wenn lastVisited == currentVisit unsigned lastVisited = 0; unsigned lastVisitedEven = 0; // used for road pathfinding (for ai only for now) - MapPoint mapPt = {}; + MapPoint mapPt; }; struct FreePathNode : BinaryHeapPosMarker diff --git a/libs/s25main/pathfinding/OpenListVector.h b/libs/s25main/pathfinding/OpenListVector.h index 6470244cef..fc4b2c5923 100644 --- a/libs/s25main/pathfinding/OpenListVector.h +++ b/libs/s25main/pathfinding/OpenListVector.h @@ -9,7 +9,7 @@ struct GetEstimateFromPtr { template - static inline unsigned GetValue(T* el) + static unsigned GetValue(T* el) { return el->estimate; } diff --git a/libs/s25main/resources/ResourceId.h b/libs/s25main/resources/ResourceId.h index 9355083223..f79a3f7e09 100644 --- a/libs/s25main/resources/ResourceId.h +++ b/libs/s25main/resources/ResourceId.h @@ -93,7 +93,7 @@ constexpr bool ResourceId::isValid(const char* name, unsigned length) for(int i = 0; i < iLen; i++) { const char c = name[i]; - if(!(('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || c == '_')) + if(('0' > c || c > '9') && ('a' > c || c > 'z') && c != '_') return false; } return true; diff --git a/libs/s25main/world/GameWorld.cpp b/libs/s25main/world/GameWorld.cpp index ddee4dc019..58a8252c83 100644 --- a/libs/s25main/world/GameWorld.cpp +++ b/libs/s25main/world/GameWorld.cpp @@ -554,14 +554,14 @@ TerritoryRegion GameWorld::CreateTerritoryRegion(const noBaseBuilding& building, sortedMilitaryBlds buildings = LookForMilitaryBuildings(bldPos, 3); for(const nobBaseMilitary* milBld : buildings) { - if(!(reason == TerritoryChangeReason::Destroyed && milBld == &building)) + if(reason != TerritoryChangeReason::Destroyed || milBld != &building) region.CalcTerritoryOfBuilding(*milBld); } // Baustellen von Häfen mit einschließen for(const noBuildingSite* bldSite : harbor_building_sites_from_sea) { - if(!(reason == TerritoryChangeReason::Destroyed && bldSite == &building)) + if(reason != TerritoryChangeReason::Destroyed || bldSite != &building) region.CalcTerritoryOfBuilding(*bldSite); } CleanTerritoryRegion(region, reason, building); diff --git a/tests/s25Main/UI/testSmartBitmap.cpp b/tests/s25Main/UI/testSmartBitmap.cpp index 0dfc7e58f1..d72dda2f9d 100644 --- a/tests/s25Main/UI/testSmartBitmap.cpp +++ b/tests/s25Main/UI/testSmartBitmap.cpp @@ -21,7 +21,6 @@ #include using namespace libsiedler2; -namespace tt = boost::test_tools; namespace libsiedler2 { static std::ostream& boost_test_print_type(std::ostream& os, const ColorBGRA color) diff --git a/tests/testHelpers/rttr/test/ConfigOverride.hpp b/tests/testHelpers/rttr/test/ConfigOverride.hpp index caff3bee44..1e8d5a77d6 100644 --- a/tests/testHelpers/rttr/test/ConfigOverride.hpp +++ b/tests/testHelpers/rttr/test/ConfigOverride.hpp @@ -19,6 +19,6 @@ class ConfigOverride { RTTRCONFIG.overridePathMapping(entry, newPath); } - ~ConfigOverride() { RTTRCONFIG.overridePathMapping(entry, std::move(oldPath)); } + ~ConfigOverride() { RTTRCONFIG.overridePathMapping(entry, oldPath); } }; } // namespace rttr::test diff --git a/tools/ci/runClangTidy.sh b/tools/ci/runClangTidy.sh index b0012cd07e..ffa7084c55 100755 --- a/tools/ci/runClangTidy.sh +++ b/tools/ci/runClangTidy.sh @@ -15,7 +15,13 @@ cmake .. -DCMAKE_BUILD_TYPE=Debug \ SRC_DIR="$(cd .. && pwd)" FILTER="extras|libs|tests|external/(libendian|liblobby|libsiedler2|libutil|mygettext|s25edit|s25update)" -script -q -c "run-clang-tidy-10 -p . \ +CLANG_TIDY_CMD="run-clang-tidy-18.py" +if ! which "${CLANG_TIDY_CMD}" &> /dev/null; then + echo "clang-tidy not found. Tried: ${CLANG_TIDY_CMD}" >&2 + exit 1 +fi + +script -q -c "${CLANG_TIDY_CMD} -p . \ -quiet \ -header-filter \"${SRC_DIR}/(${FILTER})\" \ \"${SRC_DIR}/(${FILTER})\"" /dev/null \ diff --git a/tools/runClangTidy.sh b/tools/runClangTidy.sh index 82d0472a96..5c910c06af 100755 --- a/tools/runClangTidy.sh +++ b/tools/runClangTidy.sh @@ -15,7 +15,7 @@ Check that it is generated (-DCMAKE_EXPORT_COMPILE_COMMANDS=ON)" >&2 fi -NAMES=(run-clang-tidy-10.py run-clang-tidy-9.py run-clang-tidy-8.py run-clang-tidy.py) +NAMES=(run-clang-tidy-18.py run-clang-tidy-10.py run-clang-tidy-9.py run-clang-tidy-8.py run-clang-tidy.py) for fn in "${NAMES[@]}"; do if which "${fn}" &> /dev/null; then CLANG_TIDY_CMD="${fn}"