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
master
Abigail 2017-05-22 10:10:35 +01:00 committed by krzys_h
parent 5055c5de11
commit 11d950221b
23 changed files with 49 additions and 25 deletions

View File

@ -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")

View File

@ -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;
}

View File

@ -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;

View File

@ -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

View File

@ -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
*

View File

@ -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
}

View File

@ -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

View File

@ -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();

View File

@ -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;

View File

@ -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;
}

View File

@ -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());
}

View File

@ -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;
}

View File

@ -404,3 +404,5 @@ protected:
//! Static buffer for putenv locale
static char m_languageLocale[50];
};
template<> CApplication* CSingleton<CApplication>::m_instance;

View File

@ -161,3 +161,5 @@ private:
std::map<InputSlot, std::string> m_keyTable;
};
template<> CInput* CSingleton<CInput>::m_instance;

View File

@ -67,3 +67,5 @@ private:
//! Save path
std::string m_savePath;
};
template<> CPathManager* CSingleton<CPathManager>::m_instance;

View File

@ -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;

View File

@ -112,3 +112,5 @@ inline CConfigFile & GetConfigFile()
{
return CConfigFile::GetInstance();
}
template<> CConfigFile* CSingleton<CConfigFile>::m_instance;

View File

@ -136,3 +136,5 @@ inline CLogger* GetLogger()
{
return CLogger::GetInstancePointer();
}
template<> CLogger* CSingleton<CLogger>::m_instance;

View File

@ -105,3 +105,5 @@ protected:
Language m_language;
};
template<> CSettings* CSingleton<CSettings>::m_instance;

View File

@ -1490,3 +1490,5 @@ protected:
} // namespace Gfx
template<> Gfx::CEngine* CSingleton<Gfx::CEngine>::m_instance;

View File

@ -715,3 +715,5 @@ protected:
//! Index of currently selected element in command history
int m_commandHistoryIndex;
};
template<> CRobotMain* CSingleton<CRobotMain>::m_instance;

View File

@ -311,3 +311,5 @@ private:
int m_activeObjectIterators;
bool m_shouldCleanRemovedObjects;
};
template<> CObjectManager* CSingleton<CObjectManager>::m_instance;