These changes allow the use of C++11.

This commit is contained in:
Jeffrey N. Johnson 2019-11-10 12:33:53 -08:00
parent 880667da54
commit 07aa70f27e
10 changed files with 36 additions and 41 deletions

View file

@ -86,16 +86,16 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
#add_definitions(-Wall)
add_definitions(-Werror=format-security)
add_definitions(-Werror=format)
#include(CheckCXXCompilerFlag)
#CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
#CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
#if(COMPILER_SUPPORTS_CXX11)
# add_definitions(-std=c++11)
#elseif(COMPILER_SUPPORTS_CXX0X)
# add_definitions(-std=c++0x)
#else()
# message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
#endif()
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
add_definitions(-std=c++11)
elseif(COMPILER_SUPPORTS_CXX0X)
add_definitions(-std=c++0x)
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
if(CPU_TYPE)
add_definitions(-DCPUSTRING="${CPU_TYPE}")
endif()

View file

@ -2754,13 +2754,13 @@ void idFileSystemLocal::GenerateResourceCRCs_f( const idCmdArgs& args )
{
idLib::Printf( "Generating CRCs for resource files...\n" );
std::auto_ptr<idFileList> baseResourceFileList( fileSystem->ListFiles( ".", ".resources" ) );
std::unique_ptr<idFileList> baseResourceFileList( fileSystem->ListFiles( ".", ".resources" ) );
if( baseResourceFileList.get() != NULL )
{
CreateCRCsForResourceFileList( *baseResourceFileList );
}
std::auto_ptr<idFileList> mapResourceFileList( fileSystem->ListFilesTree( "maps", ".resources" ) );
std::unique_ptr<idFileList> mapResourceFileList( fileSystem->ListFilesTree( "maps", ".resources" ) );
if( mapResourceFileList.get() != NULL )
{
CreateCRCsForResourceFileList( *mapResourceFileList );
@ -2780,7 +2780,7 @@ void idFileSystemLocal::CreateCRCsForResourceFileList( const idFileList& list )
{
idLib::Printf( " Processing %s.\n", list.GetFile( fileIndex ) );
std::auto_ptr<idFile_Memory> currentFile( static_cast<idFile_Memory*>( fileSystem->OpenFileReadMemory( list.GetFile( fileIndex ) ) ) );
std::unique_ptr<idFile_Memory> currentFile( static_cast<idFile_Memory*>( fileSystem->OpenFileReadMemory( list.GetFile( fileIndex ) ) ) );
if( currentFile.get() == NULL )
{
@ -2832,7 +2832,7 @@ void idFileSystemLocal::CreateCRCsForResourceFileList( const idFileList& list )
// Write the .crc file corresponding to the .resources file.
idStr crcFilename = list.GetFile( fileIndex );
crcFilename.SetFileExtension( ".crc" );
std::auto_ptr<idFile> crcOutputFile( fileSystem->OpenFileWrite( crcFilename, "fs_basepath" ) );
std::unique_ptr<idFile> crcOutputFile( fileSystem->OpenFileWrite( crcFilename, "fs_basepath" ) );
if( crcOutputFile.get() == NULL )
{
// RB: fixed potential crash because of "cannot pass objects of non-trivially-copyable type 'class idStr' through '...'"

View file

@ -68,32 +68,20 @@ char* Mem_CopyString( const char* in );
// RB end
ID_INLINE void* operator new( size_t s )
#if !defined(_MSC_VER)
throw( std::bad_alloc ) // DG: standard signature seems to include throw(..)
#endif
{
return Mem_Alloc( s, TAG_NEW );
}
ID_INLINE void operator delete( void* p )
#if !defined(_MSC_VER)
throw() // DG: delete musn't throw
#endif
{
Mem_Free( p );
}
ID_INLINE void* operator new[]( size_t s )
#if !defined(_MSC_VER)
throw( std::bad_alloc ) // DG: standard signature seems to include throw(..)
#endif
{
return Mem_Alloc( s, TAG_NEW );
}
ID_INLINE void operator delete[]( void* p )
#if !defined(_MSC_VER)
throw() // DG: delete musn't throw
#endif
{
Mem_Free( p );
}
@ -104,9 +92,6 @@ ID_INLINE void* operator new( size_t s, memTag_t tag )
}
ID_INLINE void operator delete( void* p, memTag_t tag )
#if !defined(_MSC_VER)
throw() // DG: delete musn't throw
#endif
{
Mem_Free( p );
}
@ -116,7 +101,7 @@ ID_INLINE void* operator new[]( size_t s, memTag_t tag )
return Mem_Alloc( s, tag );
}
ID_INLINE void operator delete[]( void* p, memTag_t tag ) throw() // DG: delete musn't throw
ID_INLINE void operator delete[]( void* p, memTag_t tag )
{
Mem_Free( p );
}

View file

@ -43,7 +43,7 @@ public:
len = text.Length();
memcpy( data, text.data, len + 1 );
}
// all idStr operators are overloaded and the idStr default constructor is called so that the
// static buffer can be initialized in the body of the constructor before the data is ever
// copied.

View file

@ -601,7 +601,7 @@ ID_INLINE bool idStaticList<type, size>::RemoveIndex( int index )
num--;
for( i = index; i < num; i++ )
{
list[ i ] = list[ i + 1 ];
list[ i ] = std::move(list[ i + 1 ]);
}
return true;

View file

@ -47,7 +47,7 @@ typedef uint32 dword;
// macros required by gimp-dds code:
#ifndef MIN
# ifdef __GNUC__
# define MIN(a, b) ({typeof(a) _a=(a); typeof(b) _b=(b); _a < _b ? _a : _b;})
# define MIN(a, b) ({decltype(a) _a=(a); decltype(b) _b=(b); _a < _b ? _a : _b;})
# else
# define MIN(a, b) ((a) < (b) ? (a) : (b))
# endif

View file

@ -46,7 +46,14 @@ public:
static const int MAX_GAMERTAG_CHARS = 16; // max number of UTF-8 characters to show
idLocalUserWin() : inputDevice( 0 ) {}
idLocalUserWin& operator=(idLocalUserWin&& other)
{
gamertag = std::move(other.gamertag);
inputDevice = other.inputDevice;
return *this;
}
//==========================================================================================
// idLocalUser interface
//==========================================================================================

View file

@ -47,7 +47,10 @@ class idProfileMgr
public:
idProfileMgr();
~idProfileMgr();
// Not copyable because we use unique_ptrs.
idProfileMgr& operator=(const idProfileMgr&) = delete;
// Called the first time it's asked to load
void Init( idLocalUser* user );
@ -62,8 +65,8 @@ private:
void OnSaveSettingsCompleted( idSaveLoadParms* parms );
private:
std::auto_ptr< idSaveGameProcessorSaveProfile > profileSaveProcessor;
std::auto_ptr< idSaveGameProcessorLoadProfile > profileLoadProcessor;
std::unique_ptr< idSaveGameProcessorSaveProfile > profileSaveProcessor;
std::unique_ptr< idSaveGameProcessorLoadProfile > profileLoadProcessor;
idLocalUser* user; // reference passed in
idPlayerProfile* profile;
@ -117,4 +120,4 @@ private:
// Synchronous check, just checks if a profile exists within the savegame location
bool Sys_SaveGameProfileCheck();
#endif
#endif

View file

@ -209,7 +209,7 @@ public:
typedef idStaticList< idSaveGameDetails, MAX_SAVEGAMES > saveGameDetailsList_t;
// Making a auto_ptr to handle lifetime issues better
// Making a unique_ptr to handle lifetime issues better
typedef idList< idFile_SaveGame*, TAG_SAVEGAMES > saveFileEntryList_t;
/*

View file

@ -386,7 +386,7 @@ saveGameHandle_t idSessionLocal::LoadGameSync( const char* name, saveFileEntryLi
// Read the details file when loading games
saveFileEntryList_t filesWithDetails( files );
std::auto_ptr< idFile_SaveGame > gameDetailsFile( new( TAG_SAVEGAMES ) idFile_SaveGame( SAVEGAME_DETAILS_FILENAME, SAVEGAMEFILE_TEXT ) );
std::unique_ptr< idFile_SaveGame > gameDetailsFile( new( TAG_SAVEGAMES ) idFile_SaveGame( SAVEGAME_DETAILS_FILENAME, SAVEGAMEFILE_TEXT ) );
filesWithDetails.Append( gameDetailsFile.get() );
// Check the cached save details from the enumeration and make sure we don't load a save from a newer version of the game!
@ -972,4 +972,4 @@ CONSOLE_COMMAND( savegameSetErrorBit, "Allows you to set savegame_error by bit i
savegame_error.SetInteger( savegame_error.GetInteger() | ( 1 << bit ) );
}
#pragma endregion
#pragma endregion