[colobot] 77/100: Fix all compiler warnings and enable -Werror (#955)

Didier Raboud odyx at moszumanska.debian.org
Thu Jun 1 18:10:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

odyx pushed a commit to branch debian/master
in repository colobot.

commit 11d950221b5868011644c256422f901ddcfb2bd8
Author: Abigail <AbigailBuccaneer at users.noreply.github.com>
Date:   Mon May 22 10:10:35 2017 +0100

    Fix all compiler warnings and enable -Werror (#955)
    
    This removes all compilation warnings on:
    * g++ 4.7.4, 4.8.5, 4.9.4, 5.4.1, 6.3.0, 7.0.1-svn246759
    * clang++ 3.9.1, 4.0.0, 5.0.0-svn303007
---
 CMakeLists.txt                      |  4 ++--
 src/CBot/CBotClass.cpp              |  3 ---
 src/CBot/CBotDefParam.cpp           |  1 -
 src/CBot/CBotInstr/CBotExprVar.h    |  2 ++
 src/CBot/CBotInstr/CBotFunction.h   |  4 ++++
 src/CBot/CBotInstr/CBotInstr.cpp    |  1 -
 src/CBot/CBotInstr/CBotLeftExpr.h   |  4 ++++
 src/CBot/CBotProgram.cpp            |  2 +-
 src/CBot/CBotStack.cpp              |  8 +++-----
 src/CBot/CBotToken.cpp              |  3 ---
 src/CBot/CBotVar/CBotVarString.h    |  4 ++--
 src/CBot/stdlib/StringFunctions.cpp | 10 ++++++++--
 src/app/app.h                       |  2 ++
 src/app/input.h                     |  2 ++
 src/app/pathman.h                   |  2 ++
 src/app/signal_handlers.cpp         |  2 +-
 src/common/config_file.h            |  2 ++
 src/common/logger.h                 |  2 ++
 src/common/settings.h               |  2 ++
 src/graphics/engine/engine.h        |  2 ++
 src/level/robotmain.h               |  2 ++
 src/object/object_manager.h         |  2 ++
 src/script/scriptfunc.cpp           |  8 ++++----
 23 files changed, 49 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bc28724..8f2ca84 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -132,7 +132,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
 
     message(STATUS "Detected GCC version 4.7+")
 
-    set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Wold-style-cast -pedantic-errors")
+    set(NORMAL_CXX_FLAGS "-std=gnu++11 -Wall -Werror -Wold-style-cast -pedantic-errors")
     set(RELEASE_CXX_FLAGS "-O2")
     set(DEBUG_CXX_FLAGS "-g -O0")
     set(TEST_CXX_FLAGS "-pthread")
@@ -144,7 +144,7 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
 
     message(STATUS "Detected Clang version 3.1+")
 
-    set(NORMAL_CXX_FLAGS "-std=c++11 -Wall -Wold-style-cast -pedantic-errors")
+    set(NORMAL_CXX_FLAGS "-std=c++11 -Wall -Werror -Wold-style-cast -pedantic-errors")
     set(RELEASE_CXX_FLAGS "-O2")
     set(DEBUG_CXX_FLAGS "-g -O0")
     set(TEST_CXX_FLAGS "-pthread")
diff --git a/src/CBot/CBotClass.cpp b/src/CBot/CBotClass.cpp
index d787eb7..ef22094 100644
--- a/src/CBot/CBotClass.cpp
+++ b/src/CBot/CBotClass.cpp
@@ -93,8 +93,6 @@ void CBotClass::ClearPublic()
 ////////////////////////////////////////////////////////////////////////////////
 void CBotClass::Purge()
 {
-    assert ( this != nullptr );
-
     delete      m_pVar;
     m_pVar      = nullptr;
     m_externalMethods->Clear();
@@ -202,7 +200,6 @@ std::string  CBotClass::GetName()
 ////////////////////////////////////////////////////////////////////////////////
 CBotClass*  CBotClass::GetParent()
 {
-    assert ( this != nullptr );
     return m_parent;
 }
 
diff --git a/src/CBot/CBotDefParam.cpp b/src/CBot/CBotDefParam.cpp
index b3a11a6..074f025 100644
--- a/src/CBot/CBotDefParam.cpp
+++ b/src/CBot/CBotDefParam.cpp
@@ -132,7 +132,6 @@ CBotDefParam* CBotDefParam::Compile(CBotToken* &p, CBotCStack* pStack)
 bool CBotDefParam::Execute(CBotVar** ppVars, CBotStack* &pj)
 {
     int             i = 0;
-    assert(this != nullptr);
     CBotDefParam*   p = this;
 
     bool useDefault = false;
diff --git a/src/CBot/CBotInstr/CBotExprVar.h b/src/CBot/CBotInstr/CBotExprVar.h
index 2f2e69a..d9b857c 100644
--- a/src/CBot/CBotInstr/CBotExprVar.h
+++ b/src/CBot/CBotInstr/CBotExprVar.h
@@ -80,6 +80,8 @@ public:
      */
     bool ExecuteVar(CBotVar* &pVar, CBotStack* &pile, CBotToken* prevToken, bool bStep);
 
+    using CBotInstr::ExecuteVar;
+
     /*!
      * \brief RestoreStateVar Fetch variable at runtime.
      * \param pj
diff --git a/src/CBot/CBotInstr/CBotFunction.h b/src/CBot/CBotInstr/CBotFunction.h
index a23e2fd..1f25474 100644
--- a/src/CBot/CBotInstr/CBotFunction.h
+++ b/src/CBot/CBotInstr/CBotFunction.h
@@ -86,6 +86,8 @@ public:
                  CBotStack* &pj,
                  CBotVar* pInstance = nullptr);
 
+    using CBotInstr::Execute;
+
     /*!
      * \brief RestoreState
      * \param ppVars
@@ -96,6 +98,8 @@ public:
                       CBotStack* &pj,
                       CBotVar* pInstance = nullptr);
 
+    using CBotInstr::RestoreState;
+
     /*!
      * \brief Compile a function call
      *
diff --git a/src/CBot/CBotInstr/CBotInstr.cpp b/src/CBot/CBotInstr/CBotInstr.cpp
index 1d30f67..69bb902 100644
--- a/src/CBot/CBotInstr/CBotInstr.cpp
+++ b/src/CBot/CBotInstr/CBotInstr.cpp
@@ -361,7 +361,6 @@ CBotInstr* CBotInstr::CompileArray(CBotToken* &p, CBotCStack* pStack, CBotTypRes
 
 bool CBotInstr::HasReturn()
 {
-    assert(this != nullptr);
     if (m_next != nullptr) return m_next->HasReturn();
     return false; // end of the list
 }
diff --git a/src/CBot/CBotInstr/CBotLeftExpr.h b/src/CBot/CBotInstr/CBotLeftExpr.h
index 7acea06..4cffe46 100644
--- a/src/CBot/CBotInstr/CBotLeftExpr.h
+++ b/src/CBot/CBotInstr/CBotLeftExpr.h
@@ -61,6 +61,8 @@ public:
      */
     bool Execute(CBotStack* &pStack, CBotStack* array);
 
+    using CBotInstr::Execute;
+
     /*!
      * \brief ExecuteVar Fetch a variable during compilation.
      * \param pVar
@@ -69,6 +71,8 @@ public:
      */
     bool ExecuteVar(CBotVar* &pVar, CBotCStack* &pile) override;
 
+    using CBotInstr::ExecuteVar;
+
     /*!
      * \brief ExecuteVar Fetch the variable at runtume.
      * \param pVar
diff --git a/src/CBot/CBotProgram.cpp b/src/CBot/CBotProgram.cpp
index 32813de..a3a216a 100644
--- a/src/CBot/CBotProgram.cpp
+++ b/src/CBot/CBotProgram.cpp
@@ -302,7 +302,7 @@ CBotTypResult cSizeOf( CBotVar* &pVar, void* pUser )
 
 bool rSizeOf( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
 {
-    if ( pVar == nullptr ) return CBotErrLowParam;
+    if ( pVar == nullptr ) { ex = CBotErrLowParam; return true; }
 
     int i = 0;
     pVar = pVar->GetItemList();
diff --git a/src/CBot/CBotStack.cpp b/src/CBot/CBotStack.cpp
index 70ec563..57aa429 100644
--- a/src/CBot/CBotStack.cpp
+++ b/src/CBot/CBotStack.cpp
@@ -82,8 +82,6 @@ CBotStack* CBotStack::AllocateStack()
 ////////////////////////////////////////////////////////////////////////////////
 void CBotStack::Delete()
 {
-    assert ( this != nullptr );
-
     if (m_next != nullptr) m_next->Delete();
     if (m_next2 != nullptr) m_next2->Delete();
 
@@ -270,7 +268,7 @@ bool CBotStack::IfStep()
 bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name)
 {
     if ( m_error>=0 ) return false;                // normal output
-    if ( m_error==-3 ) return false;            // normal output (return current)
+    if ( m_error==CBotError(-3) ) return false;            // normal output (return current)
 
     if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
         return false;                            // it's not for me
@@ -283,7 +281,7 @@ bool CBotStack::BreakReturn(CBotStack* pfils, const std::string& name)
 ////////////////////////////////////////////////////////////////////////////////
 bool CBotStack::IfContinue(int state, const std::string& name)
 {
-    if ( m_error != -2 ) return false;
+    if ( m_error != CBotError(-2) ) return false;
 
     if (!m_labelBreak.empty() && (name.empty() || m_labelBreak != name))
         return false;                            // it's not for me
@@ -311,7 +309,7 @@ void CBotStack::SetBreak(int val, const std::string& name)
 ////////////////////////////////////////////////////////////////////////////////
 bool CBotStack::GetRetVar(bool bRet)
 {
-    if (m_error == -3)
+    if (m_error == CBotError(-3))
     {
         if ( m_var ) delete m_var;
         m_var        = m_retvar;
diff --git a/src/CBot/CBotToken.cpp b/src/CBot/CBotToken.cpp
index e10901e..d9e33ff 100644
--- a/src/CBot/CBotToken.cpp
+++ b/src/CBot/CBotToken.cpp
@@ -199,7 +199,6 @@ const CBotToken& CBotToken::operator=(const CBotToken& src)
 ////////////////////////////////////////////////////////////////////////////////
 int CBotToken::GetType()
 {
-    assert(this != nullptr);
     if (m_type == TokenTypKeyWord) return m_keywordId;
     return m_type;
 }
@@ -225,14 +224,12 @@ void CBotToken::SetString(const std::string& name)
 ////////////////////////////////////////////////////////////////////////////////
 int CBotToken::GetStart()
 {
-    assert(this != nullptr);
     return m_start;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 int CBotToken::GetEnd()
 {
-    assert(this != nullptr);
     return m_end;
 }
 
diff --git a/src/CBot/CBotVar/CBotVarString.h b/src/CBot/CBotVar/CBotVarString.h
index 162264d..28d3018 100644
--- a/src/CBot/CBotVar/CBotVarString.h
+++ b/src/CBot/CBotVar/CBotVarString.h
@@ -48,12 +48,12 @@ public:
         SetValString(ToString(val));
     }
 
-    int GetValInt()
+    int GetValInt() override
     {
         return FromString<int>(GetValString());
     }
 
-    float GetValFloat()
+    float GetValFloat() override
     {
         return FromString<float>(GetValString());
     }
diff --git a/src/CBot/stdlib/StringFunctions.cpp b/src/CBot/stdlib/StringFunctions.cpp
index c50c39d..77a359c 100644
--- a/src/CBot/stdlib/StringFunctions.cpp
+++ b/src/CBot/stdlib/StringFunctions.cpp
@@ -225,8 +225,14 @@ bool rStrFind( CBotVar* pVar, CBotVar* pResult, int& ex, void* pUser )
 
     // puts the result on the stack
     std::size_t res = s.find(s2);
-    pResult->SetValInt( res != std::string::npos ? res : -1 );
-    if ( res < 0 ) pResult->SetInit( CBotVar::InitType::IS_NAN );
+    if (res != std::string::npos)
+    {
+        pResult->SetValInt(res);
+    }
+    else
+    {
+        pResult->SetInit(CBotVar::InitType::IS_NAN);
+    }
     return true;
 }
 
diff --git a/src/app/app.h b/src/app/app.h
index b670290..1b3b3a2 100644
--- a/src/app/app.h
+++ b/src/app/app.h
@@ -404,3 +404,5 @@ protected:
     //! Static buffer for putenv locale
     static char m_languageLocale[50];
 };
+
+template<> CApplication* CSingleton<CApplication>::m_instance;
diff --git a/src/app/input.h b/src/app/input.h
index 15cdc98..2b8617e 100644
--- a/src/app/input.h
+++ b/src/app/input.h
@@ -161,3 +161,5 @@ private:
 
     std::map<InputSlot, std::string> m_keyTable;
 };
+
+template<> CInput* CSingleton<CInput>::m_instance;
diff --git a/src/app/pathman.h b/src/app/pathman.h
index 059c81f..87fa449 100644
--- a/src/app/pathman.h
+++ b/src/app/pathman.h
@@ -67,3 +67,5 @@ private:
     //! Save path
     std::string m_savePath;
 };
+
+template<> CPathManager* CSingleton<CPathManager>::m_instance;
diff --git a/src/app/signal_handlers.cpp b/src/app/signal_handlers.cpp
index 223d7db..b08a0a2 100644
--- a/src/app/signal_handlers.cpp
+++ b/src/app/signal_handlers.cpp
@@ -46,7 +46,7 @@ void CSignalHandlers::Init(CSystemUtils* systemUtils)
 
 void CSignalHandlers::SignalHandler(int sig)
 {
-    std::string signalStr = StrUtils::ToString(signal);
+    std::string signalStr = StrUtils::ToString(sig);
     switch(sig)
     {
         case SIGSEGV: signalStr = "SIGSEGV, segmentation fault"; break;
diff --git a/src/common/config_file.h b/src/common/config_file.h
index 0ed8e19..9acc5ae 100644
--- a/src/common/config_file.h
+++ b/src/common/config_file.h
@@ -112,3 +112,5 @@ inline CConfigFile & GetConfigFile()
 {
     return CConfigFile::GetInstance();
 }
+
+template<> CConfigFile* CSingleton<CConfigFile>::m_instance;
diff --git a/src/common/logger.h b/src/common/logger.h
index e0a935d..e49fbd3 100644
--- a/src/common/logger.h
+++ b/src/common/logger.h
@@ -136,3 +136,5 @@ inline CLogger* GetLogger()
 {
     return CLogger::GetInstancePointer();
 }
+
+template<> CLogger* CSingleton<CLogger>::m_instance;
diff --git a/src/common/settings.h b/src/common/settings.h
index 4e9b762..cb23660 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -105,3 +105,5 @@ protected:
 
     Language m_language;
 };
+
+template<> CSettings* CSingleton<CSettings>::m_instance;
diff --git a/src/graphics/engine/engine.h b/src/graphics/engine/engine.h
index 834de1e..687bbaf 100644
--- a/src/graphics/engine/engine.h
+++ b/src/graphics/engine/engine.h
@@ -1490,3 +1490,5 @@ protected:
 
 
 } // namespace Gfx
+
+template<> Gfx::CEngine* CSingleton<Gfx::CEngine>::m_instance;
diff --git a/src/level/robotmain.h b/src/level/robotmain.h
index b1e69c9..a683e20 100644
--- a/src/level/robotmain.h
+++ b/src/level/robotmain.h
@@ -715,3 +715,5 @@ protected:
     //! Index of currently selected element in command history
     int             m_commandHistoryIndex;
 };
+
+template<> CRobotMain* CSingleton<CRobotMain>::m_instance;
diff --git a/src/object/object_manager.h b/src/object/object_manager.h
index 73ae001..2a02d24 100644
--- a/src/object/object_manager.h
+++ b/src/object/object_manager.h
@@ -311,3 +311,5 @@ private:
     int m_activeObjectIterators;
     bool m_shouldCleanRemovedObjects;
 };
+
+template<> CObjectManager* CSingleton<CObjectManager>::m_instance;
diff --git a/src/script/scriptfunc.cpp b/src/script/scriptfunc.cpp
index ee9bc30..6a264b0 100644
--- a/src/script/scriptfunc.cpp
+++ b/src/script/scriptfunc.cpp
@@ -413,7 +413,7 @@ bool CScriptFunctions::rDestroy(CBotVar* thisclass, CBotVar* var, CBotVar* resul
     else
         err = ERR_WRONG_OBJ;
 
-	result->SetValInt(err); // indicates the error or ok
+    result->SetValInt(err); // indicates the error or ok
     if ( err != ERR_OK )
     {
         if ( script->m_errMode == ERM_STOP )
@@ -506,7 +506,7 @@ bool CScriptFunctions::rFactory(CBotVar* thisclass, CBotVar* var, CBotVar* resul
     else
         err = ERR_WRONG_OBJ;
 
-	result->SetValInt(err); // indicates the error or ok
+    result->SetValInt(err); // indicates the error or ok
     if ( err != ERR_OK )
     {
         if ( script->m_errMode == ERM_STOP )
@@ -581,7 +581,7 @@ bool CScriptFunctions::rResearch(CBotVar* thisclass, CBotVar* var, CBotVar* resu
     else
         err = ERR_WRONG_OBJ;
 
-	result->SetValInt(err); // indicates the error or ok
+    result->SetValInt(err); // indicates the error or ok
     if ( err != ERR_OK )
     {
         if( script->m_errMode == ERM_STOP )
@@ -621,7 +621,7 @@ bool CScriptFunctions::rTakeOff(CBotVar* thisclass, CBotVar* var, CBotVar* resul
     else
         err = ERR_WRONG_OBJ;
 
-	result->SetValInt(err); // indicates the error or ok
+    result->SetValInt(err); // indicates the error or ok
     if ( err != ERR_OK )
     {
         if ( script->m_errMode == ERM_STOP )

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git



More information about the Pkg-games-commits mailing list