From 07aa70f27e146c02b39e941a30decbf64b747563 Mon Sep 17 00:00:00 2001 From: "Jeffrey N. Johnson" Date: Sun, 10 Nov 2019 12:33:53 -0800 Subject: [PATCH] These changes allow the use of C++11. --- neo/CMakeLists.txt | 20 ++++++++++---------- neo/framework/FileSystem.cpp | 8 ++++---- neo/idlib/Heap.h | 17 +---------------- neo/idlib/StrStatic.h | 2 +- neo/idlib/containers/StaticList.h | 2 +- neo/renderer/DXT/DXTEncoder.cpp | 2 +- neo/sys/common/localuser.h | 9 ++++++++- neo/sys/sys_profile.h | 11 +++++++---- neo/sys/sys_savegame.h | 2 +- neo/sys/sys_session_savegames.cpp | 4 ++-- 10 files changed, 36 insertions(+), 41 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index e19318d2..b8ef7fef 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -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() diff --git a/neo/framework/FileSystem.cpp b/neo/framework/FileSystem.cpp index 20c7d7d0..c066af9d 100644 --- a/neo/framework/FileSystem.cpp +++ b/neo/framework/FileSystem.cpp @@ -2754,13 +2754,13 @@ void idFileSystemLocal::GenerateResourceCRCs_f( const idCmdArgs& args ) { idLib::Printf( "Generating CRCs for resource files...\n" ); - std::auto_ptr baseResourceFileList( fileSystem->ListFiles( ".", ".resources" ) ); + std::unique_ptr baseResourceFileList( fileSystem->ListFiles( ".", ".resources" ) ); if( baseResourceFileList.get() != NULL ) { CreateCRCsForResourceFileList( *baseResourceFileList ); } - std::auto_ptr mapResourceFileList( fileSystem->ListFilesTree( "maps", ".resources" ) ); + std::unique_ptr 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 currentFile( static_cast( fileSystem->OpenFileReadMemory( list.GetFile( fileIndex ) ) ) ); + std::unique_ptr currentFile( static_cast( 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 crcOutputFile( fileSystem->OpenFileWrite( crcFilename, "fs_basepath" ) ); + std::unique_ptr 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 '...'" diff --git a/neo/idlib/Heap.h b/neo/idlib/Heap.h index f93a6273..6a29e15f 100644 --- a/neo/idlib/Heap.h +++ b/neo/idlib/Heap.h @@ -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 ); } diff --git a/neo/idlib/StrStatic.h b/neo/idlib/StrStatic.h index 0f1c9391..163bf5db 100644 --- a/neo/idlib/StrStatic.h +++ b/neo/idlib/StrStatic.h @@ -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. diff --git a/neo/idlib/containers/StaticList.h b/neo/idlib/containers/StaticList.h index 6837d170..4a2e334e 100644 --- a/neo/idlib/containers/StaticList.h +++ b/neo/idlib/containers/StaticList.h @@ -601,7 +601,7 @@ ID_INLINE bool idStaticList::RemoveIndex( int index ) num--; for( i = index; i < num; i++ ) { - list[ i ] = list[ i + 1 ]; + list[ i ] = std::move(list[ i + 1 ]); } return true; diff --git a/neo/renderer/DXT/DXTEncoder.cpp b/neo/renderer/DXT/DXTEncoder.cpp index 43f84391..9c195d3c 100644 --- a/neo/renderer/DXT/DXTEncoder.cpp +++ b/neo/renderer/DXT/DXTEncoder.cpp @@ -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 diff --git a/neo/sys/common/localuser.h b/neo/sys/common/localuser.h index 36ddd363..d7fa9f8a 100644 --- a/neo/sys/common/localuser.h +++ b/neo/sys/common/localuser.h @@ -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 //========================================================================================== diff --git a/neo/sys/sys_profile.h b/neo/sys/sys_profile.h index d5b8e0a9..2378ee5d 100644 --- a/neo/sys/sys_profile.h +++ b/neo/sys/sys_profile.h @@ -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 \ No newline at end of file +#endif diff --git a/neo/sys/sys_savegame.h b/neo/sys/sys_savegame.h index e32b81f5..dc797381 100644 --- a/neo/sys/sys_savegame.h +++ b/neo/sys/sys_savegame.h @@ -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; /* diff --git a/neo/sys/sys_session_savegames.cpp b/neo/sys/sys_session_savegames.cpp index a2d1733c..bde37af3 100644 --- a/neo/sys/sys_session_savegames.cpp +++ b/neo/sys/sys_session_savegames.cpp @@ -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 \ No newline at end of file +#pragma endregion