From 1b541e3dd55ef72a70d38af8fb56aab00ecbb46c Mon Sep 17 00:00:00 2001 From: Jeff Law Date: Sep 03 2020 22:03:31 +0000 Subject: Fix dynamic casts to avoid gcc-11 diagnostics --- diff --git a/colobot-gcc11.patch b/colobot-gcc11.patch new file mode 100644 index 0000000..24c44c6 --- /dev/null +++ b/colobot-gcc11.patch @@ -0,0 +1,98 @@ +diff --git a/src/graphics/engine/camera.cpp b/src/graphics/engine/camera.cpp +index 461f46a..1244f7d 100644 +--- a/src/graphics/engine/camera.cpp ++++ b/src/graphics/engine/camera.cpp +@@ -59,14 +59,14 @@ static void SetTransparency(CObject* obj, float value) + + if (obj->Implements(ObjectInterfaceType::Carrier)) + { +- CObject* cargo = dynamic_cast(obj)->GetCargo(); ++ CObject* cargo = dynamic_cast(*obj).GetCargo(); + if (cargo != nullptr) + cargo->SetTransparency(value); + } + + if (obj->Implements(ObjectInterfaceType::Powered)) + { +- CObject* power = dynamic_cast(obj)->GetPower(); ++ CObject* power = dynamic_cast(*obj).GetPower(); + if (power != nullptr) + power->SetTransparency(value); + } +@@ -1233,7 +1233,7 @@ bool CCamera::EventFrameBack(const Event &event) + + bool ground = true; + if (m_cameraObj->Implements(ObjectInterfaceType::Movable)) +- ground = dynamic_cast(m_cameraObj)->GetPhysics()->GetLand(); ++ ground = dynamic_cast(*m_cameraObj).GetPhysics()->GetLand(); + if ( ground ) // ground? + { + Math::Vector pos = lookatPt + (lookatPt - m_eyePt); +@@ -1326,7 +1326,7 @@ bool CCamera::EventFrameOnBoard(const Event &event) + { + assert(m_cameraObj->Implements(ObjectInterfaceType::Controllable)); + Math::Vector lookatPt, upVec; +- dynamic_cast(m_cameraObj)->AdjustCamera(m_eyePt, m_directionH, m_directionV, lookatPt, upVec, m_type); ++ dynamic_cast(*m_cameraObj).AdjustCamera(m_eyePt, m_directionH, m_directionV, lookatPt, upVec, m_type); + Math::Vector eye = m_effectOffset * 0.3f + m_eyePt; + Math::Vector lookat = m_effectOffset * 0.3f + lookatPt; + +diff --git a/src/object/interface/carrier_object.h b/src/object/interface/carrier_object.h +index b534fd4..a8510b6 100644 +--- a/src/object/interface/carrier_object.h ++++ b/src/object/interface/carrier_object.h +@@ -51,5 +51,5 @@ public: + inline bool IsObjectCarryingCargo(CObject* obj) + { + return obj->Implements(ObjectInterfaceType::Carrier) && +- dynamic_cast(obj)->IsCarryingCargo(); ++ dynamic_cast(*obj).IsCarryingCargo(); + } +diff --git a/src/object/interface/powered_object.h b/src/object/interface/powered_object.h +index 54b6dd1..1216eda 100644 +--- a/src/object/interface/powered_object.h ++++ b/src/object/interface/powered_object.h +@@ -61,10 +61,10 @@ inline float GetObjectEnergy(CObject* object) + + if (object->Implements(ObjectInterfaceType::Powered)) + { +- CObject* power = dynamic_cast(object)->GetPower(); ++ CObject* power = dynamic_cast(*object).GetPower(); + if (power != nullptr && power->Implements(ObjectInterfaceType::PowerContainer)) + { +- energy = dynamic_cast(power)->GetEnergy(); ++ energy = dynamic_cast(*power).GetEnergy(); + } + } + +@@ -77,10 +77,10 @@ inline float GetObjectEnergyLevel(CObject* object) + + if (object->Implements(ObjectInterfaceType::Powered)) + { +- CObject* power = dynamic_cast(object)->GetPower(); ++ CObject* power = dynamic_cast(*object).GetPower(); + if (power != nullptr && power->Implements(ObjectInterfaceType::PowerContainer)) + { +- energy = dynamic_cast(power)->GetEnergyLevel(); ++ energy = dynamic_cast(*power).GetEnergyLevel(); + } + } + +@@ -90,5 +90,5 @@ inline float GetObjectEnergyLevel(CObject* object) + inline bool ObjectHasPowerCell(CObject* object) + { + return object->Implements(ObjectInterfaceType::Powered) && +- dynamic_cast(object)->GetPower() != nullptr; ++ dynamic_cast(*object).GetPower() != nullptr; + } +diff --git a/src/object/interface/transportable_object.h b/src/object/interface/transportable_object.h +index 2d0f90f..1ad95d0 100644 +--- a/src/object/interface/transportable_object.h ++++ b/src/object/interface/transportable_object.h +@@ -54,5 +54,5 @@ public: + inline bool IsObjectBeingTransported(CObject* obj) + { + return obj->Implements(ObjectInterfaceType::Transportable) && +- dynamic_cast(obj)->IsBeingTransported(); ++ dynamic_cast(*obj).IsBeingTransported(); + } diff --git a/colobot.spec b/colobot.spec index 85dd43f..22511fd 100644 --- a/colobot.spec +++ b/colobot.spec @@ -2,7 +2,7 @@ Name: colobot %global orgname info.colobot.Colobot Version: 0.1.12 -Release: 9%{?dist} +Release: 10%{?dist} Summary: A video game that teaches programming in a fun way License: GPLv3 @@ -50,6 +50,9 @@ Patch0: colobot--do-not-translate-default-player-name.patch # GCC10 complains about unknown identifiers Patch1: colobot--missing-includes.patch +# GCC11 complains about potential NULL from dynamic cast, fix them +Patch2: colobot-gcc11.patch + BuildRequires: boost-devel >= 1.51 BuildRequires: boost-filesystem >= 1.51 BuildRequires: boost-regex >= 1.51 @@ -103,6 +106,7 @@ Music files used by Colobot Gold. %setup -q -n colobot-%{gittag} %patch0 -p1 %patch1 -p1 +%patch2 -p1 rm -rf ./data cp %{SOURCE1} ./data.tgz @@ -187,6 +191,9 @@ appstream-util validate-relax --nonet %{buildroot}%{_metainfodir}/%{orgname}.app %changelog +* Thu Sep 03 2020 Jeff Law - 0.1.12-10 +- Fix dynamic casts to avoid gcc-11 diagnostics + * Tue Jul 28 2020 Artur Iwicki - 0.1.12-9 - Update spec to use the new cmake_build and cmake_install macros