From c6b198ce1433d0b94a07c1e2292a71bca2cae219 Mon Sep 17 00:00:00 2001 From: Konstantin Date: Thu, 19 May 2022 15:14:50 +0300 Subject: [PATCH] Warning fix (I moved C++17 and CI to another branch) (#739) * clang warning fixes * use CMake 3.10 due to MXE CI does not have 3.13 yet Co-authored-by: Konstantin --- AI/VCAI/ArmyManager.cpp | 2 +- AI/VCAI/Pathfinding/Actions/ISpecialAction.h | 1 + CMakeLists.txt | 13 +++++++++---- client/gui/Geometries.h | 2 ++ client/windows/GUIClasses.cpp | 1 - lib/CGameState.h | 2 +- lib/CGameStateFwd.h | 8 +++++--- lib/CPathfinder.h | 5 ++++- lib/HeroBonus.h | 2 ++ lib/NetPacksLib.cpp | 1 + lib/battle/CBattleInfoCallback.cpp | 2 +- lib/events/ObjectVisitEnded.h | 1 - lib/mapObjects/CGTownInstance.cpp | 7 +++---- lib/rmg/CRmgTemplateZone.cpp | 2 +- lib/serializer/BinaryDeserializer.h | 2 +- lib/serializer/CTypeList.h | 1 + lib/serializer/JsonDeserializer.cpp | 2 +- lib/spells/CSpellHandler.cpp | 2 +- lib/spells/TargetCondition.h | 1 + server/CGameHandler.h | 2 +- 20 files changed, 37 insertions(+), 22 deletions(-) diff --git a/AI/VCAI/ArmyManager.cpp b/AI/VCAI/ArmyManager.cpp index f206d71d9..6a836e1fb 100644 --- a/AI/VCAI/ArmyManager.cpp +++ b/AI/VCAI/ArmyManager.cpp @@ -113,7 +113,7 @@ ui64 ArmyManager::howManyReinforcementsCanBuy(const CCreatureSet * h, const CGDw TResources availableRes = cb->getResourceAmount(); int freeHeroSlots = GameConstants::ARMY_SIZE - h->stacksCount(); - for(auto const dc : t->creatures) + for(auto const & dc : t->creatures) { creInfo ci = infoFromDC(dc); diff --git a/AI/VCAI/Pathfinding/Actions/ISpecialAction.h b/AI/VCAI/Pathfinding/Actions/ISpecialAction.h index c8943aaa5..6b7e77f8d 100644 --- a/AI/VCAI/Pathfinding/Actions/ISpecialAction.h +++ b/AI/VCAI/Pathfinding/Actions/ISpecialAction.h @@ -18,6 +18,7 @@ struct AIPathNode; class ISpecialAction { public: + virtual ~ISpecialAction() = default; virtual Goals::TSubgoal whatToDo(const HeroPtr & hero) const = 0; virtual void applyOnDestination( diff --git a/CMakeLists.txt b/CMakeLists.txt index f700b2d00..918b8f4d6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ # Minimum required version greatly affect CMake behavior # So cmake_minimum_required must be called before the project() -# 2.8.12 is used since it's present in Ubuntu 14.04 and Cotire require it -cmake_minimum_required(VERSION 2.8.12) +# 3.10.0 is used since it's minimal in MXE dependencies for now +cmake_minimum_required(VERSION 3.10.0) project(VCMI) # TODO @@ -118,6 +118,12 @@ include(UseDoxygen OPTIONAL) # Compile and linking options # ############################################ +#Enable C++14 Globally +set (CMAKE_CXX_STANDARD 14) +#General visibility options +set(CMAKE_CXX_VISIBILITY_PRESET hidden) +set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) + if(APPLE) set(CMAKE_MACOSX_RPATH 0) endif(APPLE) @@ -180,7 +186,7 @@ if(MINGW OR MSVC) endif(MINGW OR MSVC) if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support such parameters - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wpointer-arith -Wuninitialized") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpointer-arith -Wuninitialized") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing -Wno-switch -Wno-sign-compare -Wno-unused-local-typedefs") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-parameter -Wno-overloaded-virtual -Wno-type-limits -Wno-unknown-pragmas") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-reorder") @@ -190,7 +196,6 @@ if(CMAKE_COMPILER_IS_GNUCXX OR NOT WIN32) #so far all *nix compilers support suc endif() if(UNIX) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") set(SYSTEM_LIBS ${SYSTEM_LIBS} ${CMAKE_DL_LIBS}) endif() endif() diff --git a/client/gui/Geometries.h b/client/gui/Geometries.h index 2b7ff848c..e3e53f7be 100644 --- a/client/gui/Geometries.h +++ b/client/gui/Geometries.h @@ -119,6 +119,8 @@ struct Rect : public SDL_Rect w = r.w; h = r.h; } + Rect(const Rect& r) : Rect(static_cast(r)) + {} explicit Rect(const SDL_Surface * const &surf) { x = y = 0; diff --git a/client/windows/GUIClasses.cpp b/client/windows/GUIClasses.cpp index 289260a14..537e454fb 100644 --- a/client/windows/GUIClasses.cpp +++ b/client/windows/GUIClasses.cpp @@ -1167,7 +1167,6 @@ void CExchangeController::moveArtifact( { auto artifact = source->getArt(srcPosition); auto srcLocation = ArtifactLocation(source, srcPosition); - bool changeMade = false; for(auto slot : artifact->artType->possibleSlots.at(target->bearerType())) { diff --git a/lib/CGameState.h b/lib/CGameState.h index baf8998a4..381b29242 100644 --- a/lib/CGameState.h +++ b/lib/CGameState.h @@ -185,7 +185,7 @@ public: bool checkForVisitableDir(const int3 & src, const int3 & dst) const; //check if src tile is visitable from dst tile void calculatePaths(const CGHeroInstance *hero, CPathsInfo &out); //calculates possible paths for hero, by default uses current hero position and movement left; returns pointer to newly allocated CPath or nullptr if path does not exists void calculatePaths(std::shared_ptr config) override; - int3 guardingCreaturePosition (int3 pos) const; + int3 guardingCreaturePosition (int3 pos) const override; std::vector guardingCreatures (int3 pos) const; void updateRumor(); diff --git a/lib/CGameStateFwd.h b/lib/CGameStateFwd.h index 11d2e5461..63904fcb1 100644 --- a/lib/CGameStateFwd.h +++ b/lib/CGameStateFwd.h @@ -181,13 +181,15 @@ struct DLL_LINKAGE QuestInfo //universal interface for human and AI QuestInfo (const CQuest * Quest, const CGObjectInstance * Obj, int3 Tile) : quest (Quest), obj (Obj), tile (Tile){}; - //FIXME: assignment operator should return QuestInfo & - bool operator= (const QuestInfo &qi) + QuestInfo (const QuestInfo &qi) : quest(qi.quest), obj(qi.obj), tile(qi.tile) + {}; + + const QuestInfo& operator= (const QuestInfo &qi) { quest = qi.quest; obj = qi.obj; tile = qi.tile; - return true; + return *this; } bool operator== (const QuestInfo & qi) const diff --git a/lib/CPathfinder.h b/lib/CPathfinder.h index 5876d6a6b..84984842a 100644 --- a/lib/CPathfinder.h +++ b/lib/CPathfinder.h @@ -232,6 +232,7 @@ struct DLL_LINKAGE CDestinationNodeInfo : public PathNodeInfo class IPathfindingRule { public: + virtual ~IPathfindingRule() = default; virtual void process( const PathNodeInfo & source, CDestinationNodeInfo & destination, @@ -419,6 +420,7 @@ public: } void initialize(const PathfinderOptions & options, const CGameState * gs) override; + virtual ~NodeStorage() = default; virtual std::vector getInitialNodes() override; @@ -456,6 +458,7 @@ private: public: SingleHeroPathfinderConfig(CPathsInfo & out, CGameState * gs, const CGHeroInstance * hero); + virtual ~SingleHeroPathfinderConfig() = default; virtual CPathfinderHelper * getOrCreatePathfinderHelper(const PathNodeInfo & source, CGameState * gs) override; @@ -545,7 +548,7 @@ public: const PathfinderOptions & options; CPathfinderHelper(CGameState * gs, const CGHeroInstance * Hero, const PathfinderOptions & Options); - ~CPathfinderHelper(); + virtual ~CPathfinderHelper(); void initializePatrol(); bool isHeroPatrolLocked() const; bool isPatrolMovementAllowed(const int3 & dst) const; diff --git a/lib/HeroBonus.h b/lib/HeroBonus.h index 83b4a7e9a..1bb218e28 100644 --- a/lib/HeroBonus.h +++ b/lib/HeroBonus.h @@ -128,6 +128,7 @@ class DLL_LINKAGE CCheckProxy public: CCheckProxy(const IBonusBearer * Target, CSelector Selector); CCheckProxy(const CCheckProxy & other); + CCheckProxy& operator= (const CCheckProxy & other) = default; bool getHasBonus() const; @@ -702,6 +703,7 @@ public: // * root is node on which call was made (nullptr will be replaced with this) //interface IBonusBearer(); + virtual ~IBonusBearer() = default; virtual TConstBonusListPtr getAllBonuses(const CSelector &selector, const CSelector &limit, const CBonusSystemNode *root = nullptr, const std::string &cachingStr = "") const = 0; int valOfBonuses(const CSelector &selector, const std::string &cachingStr = "") const; bool hasBonus(const CSelector &selector, const std::string &cachingStr = "") const; diff --git a/lib/NetPacksLib.cpp b/lib/NetPacksLib.cpp index 48499b089..249afd680 100644 --- a/lib/NetPacksLib.cpp +++ b/lib/NetPacksLib.cpp @@ -709,6 +709,7 @@ DLL_LINKAGE void NewObject::applyGs(CGameState *gs) const int3 previousXAxisTile = int3(pos.x - 1, pos.y, pos.z); assert(gs->isInTheMap(previousXAxisTile) && (testObject.visitablePos() == previousXAxisTile)); + UNUSED(previousXAxisTile); } else { diff --git a/lib/battle/CBattleInfoCallback.cpp b/lib/battle/CBattleInfoCallback.cpp index 4a283f3a0..18aee3c73 100644 --- a/lib/battle/CBattleInfoCallback.cpp +++ b/lib/battle/CBattleInfoCallback.cpp @@ -1782,7 +1782,7 @@ SpellID CBattleInfoCallback::getRandomBeneficialSpell(CRandomGenerator & rand, c return stacks.front(); }; - for(const SpellID spellID : allPossibleSpells) + for(const SpellID& spellID : allPossibleSpells) { std::stringstream cachingStr; cachingStr << "source_" << Bonus::SPELL_EFFECT << "id_" << spellID.num; diff --git a/lib/events/ObjectVisitEnded.h b/lib/events/ObjectVisitEnded.h index 123c0d03e..a3b8323ab 100644 --- a/lib/events/ObjectVisitEnded.h +++ b/lib/events/ObjectVisitEnded.h @@ -28,7 +28,6 @@ public: private: PlayerColor player; ObjectInstanceID heroId; - bool enabled; }; } diff --git a/lib/mapObjects/CGTownInstance.cpp b/lib/mapObjects/CGTownInstance.cpp index c93e11b42..290be028e 100644 --- a/lib/mapObjects/CGTownInstance.cpp +++ b/lib/mapObjects/CGTownInstance.cpp @@ -1285,8 +1285,7 @@ void CGTownInstance::recreateBuildingsBonuses() for(auto b : bl) removeBonus(b); - auto owner = this->getOwner(); - for(const auto bid : builtBuildings) + for(const auto & bid : builtBuildings) { if(vstd::contains(overriddenBuildings, bid)) //tricky! -> checks tavern only if no bratherhood of sword continue; @@ -1586,13 +1585,13 @@ void CGTownInstance::serializeJsonOptions(JsonSerializeFormat & handler) boost::logic::tribool hasFort(false); - for(const BuildingID id : forbiddenBuildings) + for(const BuildingID & id : forbiddenBuildings) { buildingsLIC.none.insert(id); customBuildings = true; } - for(const BuildingID id : builtBuildings) + for(const BuildingID & id : builtBuildings) { if(id == BuildingID::DEFAULT) continue; diff --git a/lib/rmg/CRmgTemplateZone.cpp b/lib/rmg/CRmgTemplateZone.cpp index ec3f819ad..69d657fe7 100644 --- a/lib/rmg/CRmgTemplateZone.cpp +++ b/lib/rmg/CRmgTemplateZone.cpp @@ -419,7 +419,7 @@ void CRmgTemplateZone::fractalize() void CRmgTemplateZone::connectLater() { - for (const int3 node : tilesToConnectLater) + for (const int3& node : tilesToConnectLater) { if (!connectWithCenter(node, true)) logGlobal->error("Failed to connect node %s with center of the zone", node.toString()); diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index a5f30dd87..b98025d05 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -521,7 +521,7 @@ public: std::unique_ptr sfile; CLoadFile(const boost::filesystem::path & fname, int minimalVersion = SERIALIZATION_VERSION); //throws! - ~CLoadFile(); + virtual ~CLoadFile(); int read(void * data, unsigned size) override; //throws! void openNextFile(const boost::filesystem::path & fname, int minimalVersion); //throws! diff --git a/lib/serializer/CTypeList.h b/lib/serializer/CTypeList.h index d1b5efa3a..640e643f3 100644 --- a/lib/serializer/CTypeList.h +++ b/lib/serializer/CTypeList.h @@ -17,6 +17,7 @@ struct IPointerCaster virtual boost::any castSharedPtr(const boost::any &ptr) const = 0; // takes std::shared_ptr, performs dynamic cast, returns std::shared_ptr virtual boost::any castWeakPtr(const boost::any &ptr) const = 0; // takes std::weak_ptr, performs dynamic cast, returns std::weak_ptr. The object under poitner must live. //virtual boost::any castUniquePtr(const boost::any &ptr) const = 0; // takes std::unique_ptr, performs dynamic cast, returns std::unique_ptr + virtual ~IPointerCaster() = default; }; template diff --git a/lib/serializer/JsonDeserializer.cpp b/lib/serializer/JsonDeserializer.cpp index 4fc2c9bbd..b658ba3da 100644 --- a/lib/serializer/JsonDeserializer.cpp +++ b/lib/serializer/JsonDeserializer.cpp @@ -63,7 +63,7 @@ void JsonDeserializer::serializeInternal(const std::string & fieldName, std::vec value.clear(); value.reserve(data.size()); - for(const JsonNode elem : data) + for(const JsonNode& elem : data) { si32 rawId = decoder(elem.String()); diff --git a/lib/spells/CSpellHandler.cpp b/lib/spells/CSpellHandler.cpp index c686b7d7a..82c1c7714 100644 --- a/lib/spells/CSpellHandler.cpp +++ b/lib/spells/CSpellHandler.cpp @@ -372,7 +372,7 @@ void CSpell::getEffects(std::vector & lst, const int level, const bool cu lst.reserve(lst.size() + effects.size()); - for(const auto b : effects) + for(const auto& b : effects) { Bonus nb(*b); diff --git a/lib/spells/TargetCondition.h b/lib/spells/TargetCondition.h index e527c469b..c5ab39b9e 100644 --- a/lib/spells/TargetCondition.h +++ b/lib/spells/TargetCondition.h @@ -43,6 +43,7 @@ public: using Object = std::shared_ptr; static const TargetConditionItemFactory * getDefault(); + virtual ~TargetConditionItemFactory() = default; virtual Object createAbsoluteLevel() const = 0; virtual Object createAbsoluteSpell() const = 0; diff --git a/server/CGameHandler.h b/server/CGameHandler.h index 2e0c061eb..98454cac5 100644 --- a/server/CGameHandler.h +++ b/server/CGameHandler.h @@ -242,7 +242,7 @@ public: //void lootArtifacts (TArtHolder source, TArtHolder dest, std::vector &arts); //after battle - move al arts to winer bool buySecSkill( const IMarket *m, const CGHeroInstance *h, SecondarySkill skill); bool garrisonSwap(ObjectInstanceID tid); - bool swapGarrisonOnSiege(ObjectInstanceID tid); + bool swapGarrisonOnSiege(ObjectInstanceID tid) override; bool upgradeCreature( ObjectInstanceID objid, SlotID pos, CreatureID upgID ); bool recruitCreatures(ObjectInstanceID objid, ObjectInstanceID dst, CreatureID crid, ui32 cram, si32 level); bool buildStructure(ObjectInstanceID tid, BuildingID bid, bool force=false);//force - for events: no cost, no checkings