浏览代码

Fixed all non-silenced gcc/clang warnings

Ivan Savenko 2 年之前
父节点
当前提交
3219e322ae

+ 0 - 1
AI/BattleAI/AttackPossibility.cpp

@@ -156,7 +156,6 @@ AttackPossibility AttackPossibility::evaluate(const BattleAttackInfo & attackInf
 
 				TDmgRange retaliation(0, 0);
 				auto attackDmg = state.battleEstimateDamage(ap.attack, &retaliation);
-				TDmgRange defenderDamageBeforeAttack = state.battleEstimateDamage(BattleAttackInfo(u, attacker, u->canShoot()));
 
 				vstd::amin(attackDmg.first, defenderState->getAvailableHealth());
 				vstd::amin(attackDmg.second, defenderState->getAvailableHealth());

+ 0 - 1
AI/BattleAI/BattleAI.cpp

@@ -186,7 +186,6 @@ BattleAction CBattleAI::activeStack( const CStack * stack )
 
 			if(evaluationResult.score > score)
 			{
-				auto & target = bestAttack;
 				score = evaluationResult.score;
 				std::string action;
 

+ 0 - 2
AI/BattleAI/BattleExchangeVariant.cpp

@@ -211,8 +211,6 @@ MoveTarget BattleExchangeEvaluator::findMoveTowardsUnreachable(const battle::Uni
 
 	for(const battle::Unit * enemy : targets.unreachableEnemies)
 	{
-		int64_t stackScore = EvaluationResult::INEFFECTIVE_SCORE;
-
 		std::vector<const battle::Unit *> adjacentStacks = getAdjacentUnits(enemy);
 		auto closestStack = *vstd::minElementByFun(adjacentStacks, [&](const battle::Unit * u) -> int64_t
 			{

+ 1 - 1
AI/Nullkiller/AIGateway.cpp

@@ -594,7 +594,7 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vector<C
 
 					logAi->trace("Guarded object query hook: %s by %s danger ratio %f", target.toString(), hero.name, ratio);
 
-					if(text.find("guarded") >= 0 && (dangerUnknown || dangerTooHigh))
+					if(text.find("guarded") != std::string::npos && (dangerUnknown || dangerTooHigh))
 						answer = 0; // no
 				}
 			}

+ 1 - 1
AI/Nullkiller/AIUtility.h

@@ -329,7 +329,7 @@ public:
 
 		if(!poolIsEmpty) pool.pop_back();
 
-		return std::move(tmp);
+		return tmp;
 	}
 
 	bool empty() const

+ 1 - 3
AI/Nullkiller/Engine/FuzzyHelper.cpp

@@ -122,10 +122,8 @@ ui64 FuzzyHelper::evaluateDanger(const CGObjectInstance * obj)
 	case Obj::RESOURCE:
 	{
 		if(!vstd::contains(ai->memory->alreadyVisited, obj))
-		{
 			return 0;
-		}
-		// passthrough
+		FALLTHROUGH;
 	}
 	case Obj::MONSTER:
 	case Obj::HERO:

+ 2 - 2
AI/Nullkiller/Goals/ExecuteHeroChain.cpp

@@ -127,7 +127,7 @@ void ExecuteHeroChain::accept(AIGateway * ai)
 							continue;
 						}
 					}
-					catch(cannotFulfillGoalException)
+					catch(const cannotFulfillGoalException &)
 					{
 						if(!heroPtr.validAndSet())
 						{
@@ -173,7 +173,7 @@ void ExecuteHeroChain::accept(AIGateway * ai)
 			ai->nullkiller->lockHero(hero, HeroLockedReason::HERO_CHAIN);
 			blockedIndexes.insert(node.parentIndex);
 		}
-		catch(goalFulfilledException)
+		catch(const goalFulfilledException &)
 		{
 			if(!heroPtr.validAndSet())
 			{

+ 7 - 6
Global.h

@@ -80,12 +80,13 @@ static_assert(sizeof(bool) == 1, "Bool needs to be 1 byte in size.");
 #  endif
 #else
 #  error "VCMI supports only Windows, OSX, Linux and Android targets"
-#endif
-
-// Each compiler uses own way to supress fall through warning. Try to find it.
-#ifdef __has_cpp_attribute
-#  if __has_cpp_attribute(fallthrough)
-#    define FALLTHROUGH [[fallthrough]];
+#endif
+
+// Each compiler uses own way to supress fall through warning. Try to find it.
+// TODO: replace with c++17 [[fallthrough]]
+#ifdef __has_cpp_attribute
+#  if __has_cpp_attribute(fallthrough)
+#    define FALLTHROUGH [[fallthrough]];
 #  elif __has_cpp_attribute(gnu::fallthrough)
 #    define FALLTHROUGH [[gnu::fallthrough]];
 #  elif __has_cpp_attribute(clang::fallthrough)

+ 2 - 0
launcher/lobby/lobby_moc.cpp

@@ -202,10 +202,12 @@ void Lobby::serverCommand(const ServerCommand & command) try
 				ui->playersList->addItem(new QListWidgetItem(QIcon("icons:mod-disabled.png"), args[tagPoint]));
 			
 			if(args[tagPoint] == username)
+			{
 				if(args[tagPoint + 1] == "True")
 					ui->buttonReady->setText("Not ready");
 				else
 					ui->buttonReady->setText("Ready");
+			}
 		}
 		break;
 

+ 3 - 2
launcher/modManager/cmodlist.cpp

@@ -18,7 +18,6 @@ namespace
 {
 bool isCompatible(const QString & verMin, const QString & verMax)
 {
-	const int maxSections = 3; // versions consist from up to 3 sections, major.minor.patch
 	QVersionNumber vcmiVersion(VCMI_VERSION_MAJOR,
 							   VCMI_VERSION_MINOR,
 							   VCMI_VERSION_PATCH);
@@ -26,8 +25,10 @@ bool isCompatible(const QString & verMin, const QString & verMax)
 	auto versionMin = QVersionNumber::fromString(verMin);
 	auto versionMax = QVersionNumber::fromString(verMax);
 	
-	auto buildVersion = [maxSections](QVersionNumber & ver)
+	auto buildVersion = [](QVersionNumber & ver)
 	{
+		const int maxSections = 3; // versions consist from up to 3 sections, major.minor.patch
+
 		if(ver.segmentCount() < maxSections)
 		{
 			auto segments = ver.segments();

+ 1 - 1
lib/CCreatureHandler.cpp

@@ -299,7 +299,7 @@ TerrainId CCreature::getNativeTerrain() const
 	//this code is used in the CreatureTerrainLimiter::limit to setup battle bonuses
 	//and in the CGHeroInstance::getNativeTerrain() to setup mevement bonuses or/and penalties.
 	return hasBonus(selectorNoTerrainPenalty, selectorNoTerrainPenalty)
-		? Terrain::ANY_TERRAIN
+		? TerrainId(Terrain::ANY_TERRAIN)
 		: (*VLC->townh)[faction]->nativeTerrain;
 }
 

+ 6 - 0
lib/JsonNode.cpp

@@ -1028,6 +1028,12 @@ void JsonUtils::merge(JsonNode & dest, JsonNode & source, bool ignoreOverride, b
 	bool destNumeric = dest.getType() == JsonNode::JsonType::DATA_FLOAT || dest.getType() == JsonNode::JsonType::DATA_INTEGER;
 	bool bothNumeric = sourceNumeric && destNumeric;
 
+	MAYBE_UNUSED(hasNull);
+	MAYBE_UNUSED(sameType);
+	MAYBE_UNUSED(sourceNumeric);
+	MAYBE_UNUSED(destNumeric);
+	MAYBE_UNUSED(bothNumeric);
+
 	assert( hasNull || sameType || bothNumeric );
 
 	switch (source.getType())

+ 2 - 2
lib/VCMIDirs.cpp

@@ -46,8 +46,8 @@ std::string IVCMIDirs::genHelpString() const
 		"  user cache:		" + userCachePath().string() + "\n"
 		"  user config:		" + userConfigPath().string() + "\n"
 		"  user logs:		" + userLogsPath().string() + "\n"
-		"  user saves:		" + userSavePath().string() + "\n";
-		"  user extracted:	" + userExtractedPath().string() + "\n"; // Should end without new-line?
+		"  user saves:		" + userSavePath().string() + "\n"
+		"  user extracted:	" + userExtractedPath().string() + "\n";
 }
 
 void IVCMIDirs::init()

+ 2 - 2
lib/rmg/CMapGenerator.cpp

@@ -331,12 +331,12 @@ void CMapGenerator::findZonesForQuestArts()
 		if (zoneA->getId() > zoneB->getId())
 		{
 			if(auto * m = zoneB->getModificator<TreasurePlacer>())
-				zoneB->getModificator<TreasurePlacer>()->setQuestArtZone(zoneA.get());
+				m->setQuestArtZone(zoneA.get());
 		}
 		else if (zoneA->getId() < zoneB->getId())
 		{
 			if(auto * m = zoneA->getModificator<TreasurePlacer>())
-				zoneA->getModificator<TreasurePlacer>()->setQuestArtZone(zoneB.get());
+				m->setQuestArtZone(zoneB.get());
 		}
 	}
 }

+ 1 - 1
mapeditor/mainwindow.cpp

@@ -906,7 +906,7 @@ void MainWindow::on_terrainFilterCombo_currentTextChanged(const QString &arg1)
 	if(!objectBrowser)
 		return;
 
-	objectBrowser->terrain = arg1.isEmpty() ? Terrain::ANY_TERRAIN : VLC->terrainTypeHandler->getInfoByName(arg1.toStdString())->id;
+	objectBrowser->terrain = arg1.isEmpty() ? TerrainId(Terrain::ANY_TERRAIN) : VLC->terrainTypeHandler->getInfoByName(arg1.toStdString())->id;
 	objectBrowser->invalidate();
 	objectBrowser->sort(0);
 }

+ 1 - 1
mapeditor/windownewmap.cpp

@@ -202,7 +202,7 @@ std::unique_ptr<CMap> generateEmptyMap(CMapGenOptions & options)
 	map->initTerrain();
 	map->getEditManager()->clearTerrain(&CRandomGenerator::getDefault());
 
-	return std::move(map);
+	return map;
 }
 
 void WindowNewMap::on_okButton_clicked()

+ 6 - 6
mapeditor/windownewmap.ui

@@ -46,7 +46,7 @@
    <property name="title">
     <string>Map size</string>
    </property>
-   <widget class="QWidget" name="layoutWidget">
+   <widget class="QWidget" name="layoutWidget1">
     <property name="geometry">
      <rect>
       <x>0</x>
@@ -204,7 +204,7 @@
     <property name="title">
      <string>Players</string>
     </property>
-    <widget class="QWidget" name="layoutWidget">
+    <widget class="QWidget" name="layoutWidget2">
      <property name="geometry">
       <rect>
        <x>10</x>
@@ -421,7 +421,7 @@
     <property name="title">
      <string>Monster strength</string>
     </property>
-    <widget class="QWidget" name="layoutWidget">
+    <widget class="QWidget" name="layoutWidget3">
      <property name="geometry">
       <rect>
        <x>0</x>
@@ -562,7 +562,7 @@
     <property name="title">
      <string>Water content</string>
     </property>
-    <widget class="QWidget" name="layoutWidget">
+    <widget class="QWidget" name="layoutWidget4">
      <property name="geometry">
       <rect>
        <x>0</x>
@@ -667,7 +667,7 @@
      </layout>
     </widget>
    </widget>
-   <widget class="QWidget" name="layoutWidget">
+   <widget class="QWidget" name="layoutWidget5">
     <property name="geometry">
      <rect>
       <x>10</x>
@@ -754,7 +754,7 @@
     <string>Generate random map</string>
    </property>
   </widget>
-  <widget class="QWidget" name="layoutWidget">
+  <widget class="QWidget" name="layoutWidget6">
    <property name="geometry">
     <rect>
      <x>310</x>