From 4942cabab5ac60af46b5911b28e329f58c559c4a Mon Sep 17 00:00:00 2001 From: Stan Date: Thu, 31 Dec 2020 14:25:37 +0000 Subject: [PATCH] Fix most Clang 10 Warnings Refs: #5550, #5294 Remove dead code from f71be3c764 Fix buggy code from ff50b0b74c Comments by: @wraitii, @vladislavbelov Differential Revision: https://code.wildfiregames.com/D3177 This was SVN commit r24487. --- source/renderer/ModelRenderer.cpp | 5 +- source/renderer/PatchRData.cpp | 4 +- .../components/CCmpCinemaManager.cpp | 4 +- .../simulation2/components/CCmpPathfinder.cpp | 2 +- .../components/CCmpRangeManager.cpp | 5 +- .../components/CCmpTemplateManager.cpp | 12 +-- .../components/CCmpTerritoryManager.cpp | 4 +- .../helpers/HierarchicalPathfinder.cpp | 6 +- source/soundmanager/SoundManager.cpp | 2 +- .../jsonspirit/json_spirit_value.h | 86 +++++++++---------- .../ScenarioEditor/Sections/Map/Map.cpp | 20 ++--- .../GameInterface/Handlers/CinemaHandler.cpp | 6 +- .../GameInterface/Handlers/MapHandlers.cpp | 3 +- .../GameInterface/Handlers/ObjectHandlers.cpp | 8 +- source/tools/atlas/GameInterface/View.cpp | 2 +- 15 files changed, 88 insertions(+), 81 deletions(-) diff --git a/source/renderer/ModelRenderer.cpp b/source/renderer/ModelRenderer.cpp index 3a6ae6de3b..e233ea34f3 100644 --- a/source/renderer/ModelRenderer.cpp +++ b/source/renderer/ModelRenderer.cpp @@ -314,11 +314,14 @@ struct SMRCompareSortByDistItem } }; -struct SMRMaterialBucketKey +class SMRMaterialBucketKey { +public: SMRMaterialBucketKey(CStrIntern effect, const CShaderDefines& defines) : effect(effect), defines(defines) { } + SMRMaterialBucketKey(const SMRMaterialBucketKey& entity) = default; + CStrIntern effect; CShaderDefines defines; diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index 433bba4984..a683613f65 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -1131,7 +1131,7 @@ void CPatchRData::RenderStreams(const std::vector& patches, const ENSURE(!(streamflags & ~(STREAM_POS|STREAM_POSTOUV0|STREAM_POSTOUV1))); // Render each batch - for (const std::pair& streamBatch : batches) + for (const std::pair& streamBatch : batches) { GLsizei stride = sizeof(SBaseVertex); SBaseVertex *base = (SBaseVertex *)streamBatch.first->Bind(); @@ -1144,7 +1144,7 @@ void CPatchRData::RenderStreams(const std::vector& patches, const shader->AssertPointersBound(); - for (const std::pair& batchIndexBuffer : streamBatch.second) + for (const std::pair& batchIndexBuffer : streamBatch.second) { batchIndexBuffer.first->Bind(); diff --git a/source/simulation2/components/CCmpCinemaManager.cpp b/source/simulation2/components/CCmpCinemaManager.cpp index ad38e609cf..df0f818c94 100644 --- a/source/simulation2/components/CCmpCinemaManager.cpp +++ b/source/simulation2/components/CCmpCinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -65,7 +65,7 @@ public: serializer.Bool("MapRevealed", m_MapRevealed); serializer.NumberU32_Unbounded("NumberOfPaths", m_Paths.size()); - for (const std::pair& it : m_Paths) + for (const std::pair& it : m_Paths) SerializePath(it.second, serializer); serializer.NumberU32_Unbounded("NumberOfQueuedPaths", m_PathQueue.size()); diff --git a/source/simulation2/components/CCmpPathfinder.cpp b/source/simulation2/components/CCmpPathfinder.cpp index d5649cc178..1785607709 100644 --- a/source/simulation2/components/CCmpPathfinder.cpp +++ b/source/simulation2/components/CCmpPathfinder.cpp @@ -262,7 +262,7 @@ void CCmpPathfinder::GetPassabilityClasses(std::map& void CCmpPathfinder::GetPassabilityClasses(std::map& nonPathfindingPassClasses, std::map& pathfindingPassClasses) const { - for (const std::pair& pair : m_PassClassMasks) + for (const std::pair& pair : m_PassClassMasks) { if ((GetPassabilityFromMask(pair.second)->m_Obstructions == PathfinderPassability::PATHFINDING)) pathfindingPassClasses[pair.first] = pair.second; diff --git a/source/simulation2/components/CCmpRangeManager.cpp b/source/simulation2/components/CCmpRangeManager.cpp index 9d021a78da..f22d8e8c69 100644 --- a/source/simulation2/components/CCmpRangeManager.cpp +++ b/source/simulation2/components/CCmpRangeManager.cpp @@ -300,13 +300,16 @@ struct SerializeHelper * It must only be passed entities that are in 'entities' * and are currently in the world. */ -struct EntityDistanceOrdering +class EntityDistanceOrdering { +public: EntityDistanceOrdering(const EntityMap& entities, const CFixedVector2D& source) : m_EntityData(entities), m_Source(source) { } + EntityDistanceOrdering(const EntityDistanceOrdering& entity) = default; + bool operator()(entity_id_t a, entity_id_t b) const { const EntityData& da = m_EntityData.find(a)->second; diff --git a/source/simulation2/components/CCmpTemplateManager.cpp b/source/simulation2/components/CCmpTemplateManager.cpp index 47e550ab3a..5e867af05d 100644 --- a/source/simulation2/components/CCmpTemplateManager.cpp +++ b/source/simulation2/components/CCmpTemplateManager.cpp @@ -58,9 +58,9 @@ public: virtual void Serialize(ISerializer& serialize) { - std::map> templateMap; + std::map> templateMap; - for (const std::pair& templateEnt : m_LatestTemplates) + for (const std::pair& templateEnt : m_LatestTemplates) if (!ENTITY_IS_LOCAL(templateEnt.first)) templateMap[templateEnt.second].push_back(templateEnt.first); @@ -71,9 +71,9 @@ public: { Init(paramNode); - std::map> templateMap; + std::map> templateMap; Serializer(deserialize, "templates", templateMap); - for (const std::pair>& mapEl : templateMap) + for (const std::pair>& mapEl : templateMap) for (entity_id_t id : mapEl.second) m_LatestTemplates[id] = mapEl.first; } @@ -218,7 +218,7 @@ std::vector CCmpTemplateManager::FindAllTemplates(bool includeActor std::vector CCmpTemplateManager::FindUsedTemplates() const { std::vector usedTemplates; - for (const std::pair& p : m_LatestTemplates) + for (const std::pair& p : m_LatestTemplates) if (std::find(usedTemplates.begin(), usedTemplates.end(), p.second) == usedTemplates.end()) usedTemplates.push_back(p.second); return usedTemplates; @@ -230,7 +230,7 @@ std::vector CCmpTemplateManager::FindUsedTemplates() const std::vector CCmpTemplateManager::GetEntitiesUsingTemplate(const std::string& templateName) const { std::vector entities; - for (const std::pair& p : m_LatestTemplates) + for (const std::pair& p : m_LatestTemplates) if (p.second == templateName) entities.push_back(p.first); diff --git a/source/simulation2/components/CCmpTerritoryManager.cpp b/source/simulation2/components/CCmpTerritoryManager.cpp index ae5244061e..223f900833 100644 --- a/source/simulation2/components/CCmpTerritoryManager.cpp +++ b/source/simulation2/components/CCmpTerritoryManager.cpp @@ -459,14 +459,14 @@ void CCmpTerritoryManager::CalculateTerritories() // store the root influences to mark territory as connected std::vector rootInfluenceEntities; - for (const std::pair >& pair : influenceEntities) + for (const std::pair>& pair : influenceEntities) { // entityGrid stores the weight for a single entity, and is reset per entity Grid entityGrid(tilesW, tilesH); // playerGrid stores the combined weight of all entities for this player Grid playerGrid(tilesW, tilesH); - u8 owner = (u8)pair.first; + u8 owner = static_cast(pair.first); const std::vector& ents = pair.second; // With 2^16 entities, we're safe against overflows as the weight is also limited to 2^16 ENSURE(ents.size() < 1 << 16); diff --git a/source/simulation2/helpers/HierarchicalPathfinder.cpp b/source/simulation2/helpers/HierarchicalPathfinder.cpp index c54c00d048..9bb8b16a6e 100644 --- a/source/simulation2/helpers/HierarchicalPathfinder.cpp +++ b/source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -467,7 +467,7 @@ void HierarchicalPathfinder::Update(Grid* grid, const Grid& dir if (!dirtinessGrid.any_set_in_square(i0, j0, i1, j1)) continue; - for (const std::pair& passClassMask : m_PassClassMasks) + for (const std::pair& passClassMask : m_PassClassMasks) { pass_class_t passClass = passClassMask.second; Chunk& a = m_Chunks[passClass].at(ci + cj*m_ChunksW); @@ -627,7 +627,8 @@ void HierarchicalPathfinder::UpdateGlobalRegions(const std::map >& regionsInNeed : needNewGlobalRegionMap) + for (const std::pair>& regionsInNeed : needNewGlobalRegionMap) + { for (const RegionID& reg : regionsInNeed.second) { std::map& globalRegions = m_GlobalRegions[regionsInNeed.first]; @@ -643,6 +644,7 @@ void HierarchicalPathfinder::UpdateGlobalRegions(const std::map& p : m_SoundGroups) + for (const std::pair& p : m_SoundGroups) delete p.second; m_SoundGroups.clear(); diff --git a/source/third_party/jsonspirit/json_spirit_value.h b/source/third_party/jsonspirit/json_spirit_value.h index c26fa5d320..68d7aec827 100644 --- a/source/third_party/jsonspirit/json_spirit_value.h +++ b/source/third_party/jsonspirit/json_spirit_value.h @@ -17,10 +17,10 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include +#include // comment out the value types you don't need to reduce build times and intermediate file sizes #define JSON_SPIRIT_VALUE_ENABLED @@ -32,10 +32,10 @@ namespace json_spirit { enum Value_type{ obj_type, array_type, str_type, bool_type, int_type, real_type, null_type }; - static std::string value_type_to_string( Value_type vtype ); + static inline std::string value_type_to_string(const Value_type vtype ); struct Null{}; - + template< class Config > // Config determines whether the value uses std::string or std::wstring and // whether JSON Objects are represented as vectors or maps class Value_impl @@ -49,7 +49,7 @@ namespace json_spirit typedef typename String_type::const_pointer Const_str_ptr; // eg const char* Value_impl(); // creates null value - Value_impl( Const_str_ptr value ); + Value_impl( Const_str_ptr value ); Value_impl( const String_type& value ); Value_impl( const Object& value ); Value_impl( const Array& value ); @@ -97,28 +97,28 @@ namespace json_spirit void check_type( const Value_type vtype ) const; - typedef boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, + typedef boost::variant< boost::recursive_wrapper< Object >, boost::recursive_wrapper< Array >, String_type, bool, boost::int64_t, double, Null, boost::uint64_t > Variant; Variant v_; - class Variant_converter_visitor : public boost::static_visitor< Variant > + class Variant_converter_visitor : public boost::static_visitor< Variant > { public: - + template< typename T, typename A, template< typename, typename > class Cont > - Variant operator()( const Cont< T, A >& cont ) const + Variant operator()( const Cont< T, A >& cont ) const { return Array( cont.begin(), cont.end() ); } - - Variant operator()( int i ) const + + Variant operator()( int i ) const { return static_cast< boost::int64_t >( i ); } - + template - Variant operator()( const T& t ) const + Variant operator()( const T& t ) const { return t; } @@ -161,12 +161,12 @@ namespace json_spirit return obj.back().value_; } - + static const String_type& get_name( const Pair_type& pair ) { return pair.name_; } - + static const Value_type& get_value( const Pair_type& pair ) { return pair.value_; @@ -212,12 +212,12 @@ namespace json_spirit { return obj[ name ] = value; } - + static const String_type& get_name( const Pair_type& pair ) { return pair.first; } - + static const Value_type& get_value( const Pair_type& pair ) { return pair.second; @@ -354,7 +354,7 @@ namespace json_spirit if( type() != lhs.type() ) return false; - return v_ == lhs.v_; + return v_ == lhs.v_; } template< class Config > @@ -383,7 +383,7 @@ namespace json_spirit template< class Config > void Value_impl< Config >::check_type( const Value_type vtype ) const { - if( type() != vtype ) + if( type() != vtype ) { std::ostringstream os; @@ -408,7 +408,7 @@ namespace json_spirit return *boost::get< Object >( &v_ ); } - + template< class Config > const typename Value_impl< Config >::Array& Value_impl< Config >::get_array() const { @@ -416,7 +416,7 @@ namespace json_spirit return *boost::get< Array >( &v_ ); } - + template< class Config > bool Value_impl< Config >::get_bool() const { @@ -424,7 +424,7 @@ namespace json_spirit return boost::get< bool >( v_ ); } - + template< class Config > int Value_impl< Config >::get_int() const { @@ -432,7 +432,7 @@ namespace json_spirit return static_cast< int >( get_int64() ); } - + template< class Config > boost::int64_t Value_impl< Config >::get_int64() const { @@ -445,7 +445,7 @@ namespace json_spirit return boost::get< boost::int64_t >( v_ ); } - + template< class Config > boost::uint64_t Value_impl< Config >::get_uint64() const { @@ -528,49 +528,49 @@ namespace json_spirit { }; - template< class Value > + template< class Value > int get_value( const Value& value, Type_to_type< int > ) { return value.get_int(); } - - template< class Value > + + template< class Value > boost::int64_t get_value( const Value& value, Type_to_type< boost::int64_t > ) { return value.get_int64(); } - - template< class Value > + + template< class Value > boost::uint64_t get_value( const Value& value, Type_to_type< boost::uint64_t > ) { return value.get_uint64(); } - - template< class Value > + + template< class Value > double get_value( const Value& value, Type_to_type< double > ) { return value.get_real(); } - - template< class Value > + + template< class Value > typename Value::String_type get_value( const Value& value, Type_to_type< typename Value::String_type > ) { return value.get_str(); } - - template< class Value > + + template< class Value > typename Value::Array get_value( const Value& value, Type_to_type< typename Value::Array > ) { return value.get_array(); } - - template< class Value > + + template< class Value > typename Value::Object get_value( const Value& value, Type_to_type< typename Value::Object > ) { return value.get_obj(); } - - template< class Value > + + template< class Value > bool get_value( const Value& value, Type_to_type< bool > ) { return value.get_bool(); @@ -578,13 +578,13 @@ namespace json_spirit } template< class Config > - template< typename T > + template< typename T > T Value_impl< Config >::get_value() const { return internal_::get_value( *this, internal_::Type_to_type< T >() ); } - static std::string value_type_to_string( const Value_type vtype ) + static inline std::string value_type_to_string( const Value_type vtype ) { switch( vtype ) { diff --git a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp index 9cbc2b1178..6fce77f2bf 100644 --- a/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp +++ b/source/tools/atlas/AtlasUI/ScenarioEditor/Sections/Map/Map.cpp @@ -239,7 +239,7 @@ void MapSettingsControl::ReadFromEngine() m_MapSettingsVictoryConditions.insert(std::string(victoryCondition)); // Clear Checkboxes before loading data. We don't update victory condition just yet because it might reenable some of the checkboxes. - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { wxCheckBox* checkBox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); if (!checkBox) @@ -249,7 +249,7 @@ void MapSettingsControl::ReadFromEngine() checkBox->Enable(true); } - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); @@ -298,20 +298,20 @@ void MapSettingsControl::OnVictoryConditionChanged(long controlId) AtObj victoryCondition; wxCheckBox* modifiedCheckbox = wxDynamicCast(FindWindow(controlId), wxCheckBox); - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { - if(vc.first != controlId) + if (vc.first != controlId) continue; - victoryCondition = vc.second; + victoryCondition = vc.second; break; } - if(modifiedCheckbox->GetValue()) + if (modifiedCheckbox->GetValue()) { for (AtIter victoryConditionPair = victoryCondition["Data"]["ChangeOnChecked"]; victoryConditionPair.defined(); ++victoryConditionPair) { - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); @@ -325,7 +325,7 @@ void MapSettingsControl::OnVictoryConditionChanged(long controlId) } } - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { if (vc.first == controlId) continue; @@ -333,7 +333,7 @@ void MapSettingsControl::OnVictoryConditionChanged(long controlId) wxCheckBox* otherCheckbox = wxDynamicCast(FindWindow(vc.first), wxCheckBox); otherCheckbox->Enable(true); - for (const std::pair& vc2 : m_VictoryConditions) + for (const std::pair& vc2 : m_VictoryConditions) { for (AtIter victoryConditionTitle = vc2.second["Data"]["DisabledWhenChecked"]; victoryConditionTitle.defined(); ++victoryConditionTitle) { @@ -371,7 +371,7 @@ AtObj MapSettingsControl::UpdateSettingsObject() else \ m_MapSettingsVictoryConditions.erase(name); - for (const std::pair& vc : m_VictoryConditions) + for (const std::pair& vc : m_VictoryConditions) { std::string escapedTitle = wxString::FromUTF8(vc.second["Data"]["Title"]).Lower().ToStdString(); std::replace(escapedTitle.begin(), escapedTitle.end(), ' ', '_'); diff --git a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp index 9af2dc6996..069fa49f1f 100644 --- a/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp +++ b/source/tools/atlas/GameInterface/Handlers/CinemaHandler.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Wildfire Games. +/* Copyright (C) 2020 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -491,9 +491,9 @@ QUERYHANDLER(PickPathNode) CVector2D cursor; msg->pos->GetScreenSpace(cursor.X, cursor.Y); - for (const std::pair& p : cmpCinemaManager->GetPaths()) + for (const std::pair& p : cmpCinemaManager->GetPaths()) { - const CCinemaPath& path = p.second; + const CCinemaPath& path = p.second; if (isPathNodePicked(path, cursor, node, false) || isPathNodePicked(path.GetTargetSpline(), cursor, node, true)) { node.name = path.GetName(); diff --git a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp index d96d03c5ec..0c4417329d 100644 --- a/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/MapHandlers.cpp @@ -518,10 +518,9 @@ BEGIN_COMMAND(ResizeMap) const CFixedVector3D offset = CFixedVector3D(fixed::FromInt(offsetX), fixed::FromInt(0), fixed::FromInt(offsetZ)); const CSimulation2::InterfaceListUnordered& ents = sim.GetEntitiesWithInterfaceUnordered(IID_Selectable); - for (const std::pair& ent : ents) + for (const std::pair& ent : ents) { const entity_id_t entityId = ent.first; - CmpPtr cmpPosition(sim, entityId); if (cmpPosition && cmpPosition->IsInWorld() && Within(cmpPosition->GetPosition(), mapCenterX, mapCenterZ, radiusInTerrainUnits)) diff --git a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp index 3018f6dfb7..844a60b3cc 100644 --- a/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/ObjectHandlers.cpp @@ -767,7 +767,7 @@ BEGIN_COMMAND(MoveObjects) void SetPos(const std::map& map) { - for (const std::pair& p : map) + for (const std::pair& p : map) { CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); if (!cmpPosition) @@ -859,7 +859,7 @@ BEGIN_COMMAND(RotateObjectsFromCenterPoint) void SetPos(const std::map& position, const std::map& angle) { - for (const std::pair& p : position) + for (const std::pair& p : position) { CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); if (!cmpPosition) @@ -873,7 +873,7 @@ BEGIN_COMMAND(RotateObjectsFromCenterPoint) } - for (const std::pair& p: position) + for (const std::pair& p : position) CheckObstructionAndUpdateVisual(p.first); } @@ -963,7 +963,7 @@ BEGIN_COMMAND(RotateObject) void SetAngle(const std::map& angles) { - for (const std::pair& p : angles) + for (const std::pair& p : angles) { CmpPtr cmpPosition(*g_Game->GetSimulation2(), p.first); if (!cmpPosition) diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index 3d042f79bc..a15ac96991 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -179,7 +179,7 @@ AtlasViewGame::AtlasViewGame() AtlasViewGame::~AtlasViewGame() { - for (const std::pair& p : m_SavedStates) + for (const std::pair& p : m_SavedStates) delete p.second; }