From 459fce0758ff07a4afded2ceec2fef0afa32c514 Mon Sep 17 00:00:00 2001 From: Nicolas Hake Date: Tue, 19 Mar 2013 17:28:19 +0100 Subject: [PATCH] Replace std::auto_ptr with std::unique_ptr std::auto_ptr has awkward copy semantics and is deprecated in C++11. --- CMakeLists.txt | 2 ++ cmake/RequireCXXSourceCompiles.cmake | 20 ++++++++++++++++++++ src/c4group/C4Extra.cpp | 2 +- src/landscape/C4Landscape.cpp | 2 +- src/landscape/C4MapScript.cpp | 6 +++--- src/lib/StdCompiler.h | 8 ++++---- src/lib/StdMesh.cpp | 2 +- src/lib/StdMesh.h | 2 +- src/lib/StdMeshLoaderBinary.cpp | 4 ++-- src/lib/StdMeshLoaderBinaryChunks.cpp | 4 ++-- src/lib/StdMeshLoaderXml.cpp | 2 +- src/lib/StdMeshMaterial.cpp | 2 +- src/network/C4Network2UPnPLinux.cpp | 4 ++-- src/object/C4DefGraphics.cpp | 2 +- src/script/C4PropList.cpp | 2 +- 15 files changed, 43 insertions(+), 21 deletions(-) create mode 100644 cmake/RequireCXXSourceCompiles.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index ff15beeb6..d5e0e657a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,8 @@ endforeach() # out because it does not understand -std=gnu++0x set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(CMAKE_REQUIRED_FLAGS ${OC_REQUIRED_FLAGS}) +include(RequireCXXSourceCompiles) +REQUIRE_CXX_SOURCE_COMPILES("#include \nint main() { std::unique_ptr a; std::shared_ptr b; }" HAVE_C11_SMART_PTRS) CHECK_CXX_SOURCE_COMPILES("void f(struct D&&); int main() { return 0; }" HAVE_RVALUE_REF) CHECK_CXX_SOURCE_COMPILES("int main() { void *d = nullptr; }" HAVE_NULLPTR) CHECK_CXX_SOURCE_COMPILES("int main() { static_assert(true, \"\"); }" HAVE_STATIC_ASSERT) diff --git a/cmake/RequireCXXSourceCompiles.cmake b/cmake/RequireCXXSourceCompiles.cmake new file mode 100644 index 000000000..794661366 --- /dev/null +++ b/cmake/RequireCXXSourceCompiles.cmake @@ -0,0 +1,20 @@ +# OpenClonk, http://www.openclonk.org +# +# Copyright (c) 2013 Nicolas Hake +# +# Permission to use, copy, modify, and/or distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# See isc_license.txt for full license and disclaimer. +# +# "Clonk" is a registered trademark of Matthes Bender. +# See clonk_trademark_license.txt for full license. + +include(CheckCXXSourceCompiles) +macro(REQUIRE_CXX_SOURCE_COMPILES _code _var) + CHECK_CXX_SOURCE_COMPILES("${_code}" ${_var}) + if(NOT ${_var}) + unset(${_var} CACHE) + MESSAGE(FATAL_ERROR "${_var} is required for this project to build properly. Aborting.") + endif() +endmacro() diff --git a/src/c4group/C4Extra.cpp b/src/c4group/C4Extra.cpp index ec51d59a3..d269aaf5a 100644 --- a/src/c4group/C4Extra.cpp +++ b/src/c4group/C4Extra.cpp @@ -46,7 +46,7 @@ bool C4Extra::InitGroup() // register extra root into game group set for(C4Reloc::iterator iter = Reloc.begin(); iter != Reloc.end(); ++iter) { - std::auto_ptr pGroup(new C4Group); + std::unique_ptr pGroup(new C4Group); if(pGroup->Open( ((*iter).strBuf + DirSep + C4CFN_Extra).getData())) ExtraGroups.push_back(pGroup.release()); } diff --git a/src/landscape/C4Landscape.cpp b/src/landscape/C4Landscape.cpp index 30f0be0b0..c0a16de20 100644 --- a/src/landscape/C4Landscape.cpp +++ b/src/landscape/C4Landscape.cpp @@ -417,7 +417,7 @@ int32_t C4Landscape::DigFreeShape(int *vtcs, int length, C4Object *by_object, bo C4FindObjectLayer fo_layer(by_object ? by_object->Layer : NULL); C4FindObject *fo_list[] = {&fo_inrect, &fo_collectible, &fo_insolid, &fo_layer}; C4FindObjectAndStatic fo_srch(4, fo_list); - std::auto_ptr dig_objects(fo_srch.FindMany(::Objects, ::Objects.Sectors)); + std::unique_ptr dig_objects(fo_srch.FindMany(::Objects, ::Objects.Sectors)); if(by_object) { diff --git a/src/landscape/C4MapScript.cpp b/src/landscape/C4MapScript.cpp index b0db8e8c7..cf832ef2d 100644 --- a/src/landscape/C4MapScript.cpp +++ b/src/landscape/C4MapScript.cpp @@ -197,7 +197,7 @@ static bool FnLayerDraw(C4PropList * _this, C4String *mattex, C4PropList *mask_a if (!layer || icol<0) return false; C4Rect rcBounds; if (!FnParRect(layer, rect, &rcBounds)) return false; - std::auto_ptr algo(FnParAlgo(mask_algo)); + std::unique_ptr algo(FnParAlgo(mask_algo)); return layer->Fill(icol, rcBounds, algo.get()); } @@ -208,7 +208,7 @@ static bool FnLayerBlit(C4PropList * _this, C4PropList *mask_algo, C4ValueArray if (!layer) return false; C4Rect rcBounds; if (!FnParRect(layer, rect, &rcBounds)) return false; - std::auto_ptr algo(FnParAlgo(mask_algo)); + std::unique_ptr algo(FnParAlgo(mask_algo)); if (!algo.get()) return false; return layer->Blit(rcBounds, algo.get()); } @@ -579,7 +579,7 @@ bool C4MapScriptHost::InitializeMap(C4Group &group, CSurface8 **pmap_surface) if (!scen_proplist || !scen_proplist->GetFunc(PSF_InitializeMap)) return false; } // Create proplist as script context - std::auto_ptr map(CreateMap()); + std::unique_ptr map(CreateMap()); // Drawing on existing map or create new? if (*pmap_surface) { diff --git a/src/lib/StdCompiler.h b/src/lib/StdCompiler.h index 4127f01cf..fa20d4ee4 100644 --- a/src/lib/StdCompiler.h +++ b/src/lib/StdCompiler.h @@ -331,7 +331,7 @@ void CompileNewFunc(T *&pStruct, StdCompiler *pComp) // a) Define a standard constructor for T // b) Specialize this function to do whatever the correct // behaviour is to construct the object from compiler data - std::auto_ptr temp(new T); // exception-safety + std::unique_ptr temp(new T); // exception-safety // Compile pComp->Value(*temp); pStruct = temp.release(); @@ -345,7 +345,7 @@ void CompileNewFunc(T *&pStruct, StdCompiler *pComp, const P& rPar) // a) Define a standard constructor for T // b) Specialize this function to do whatever the correct // behaviour is to construct the object from compiler data - std::auto_ptr temp(new T); // exception-safety + std::unique_ptr temp(new T); // exception-safety // Compile //temp->CompileFunc(pComp, rPar); pComp->Value(mkParAdapt(*temp, rPar)); @@ -361,7 +361,7 @@ void CompileNewFuncCtx(T *&pStruct, StdCompiler *pComp, const ContextT& rCtx) // b) Specialize this function to do whatever the correct // behaviour is to construct the object from compiler data // and context - std::auto_ptr temp(new T(rCtx)); // exception-safety + std::unique_ptr temp(new T(rCtx)); // exception-safety // Compile pComp->Value(*temp); pStruct = temp.release(); @@ -376,7 +376,7 @@ void CompileNewFuncCtx(T *&pStruct, StdCompiler *pComp, const ContextT& rCtx, co // b) Specialize this function to do whatever the correct // behaviour is to construct the object from compiler data // and context - std::auto_ptr temp(new T(rCtx)); // exception-safety + std::unique_ptr temp(new T(rCtx)); // exception-safety // Compile //temp->CompileFunc(pComp, rPar); pComp->Value(mkParAdapt(*temp, rPar)); diff --git a/src/lib/StdMesh.cpp b/src/lib/StdMesh.cpp index 4c040dba0..a1efee4a5 100644 --- a/src/lib/StdMesh.cpp +++ b/src/lib/StdMesh.cpp @@ -1017,7 +1017,7 @@ StdMeshInstance::AttachedMesh* StdMeshInstance::AttachMesh(const StdMesh& mesh, StdMeshInstance::AttachedMesh* StdMeshInstance::AttachMesh(StdMeshInstance& instance, AttachedMesh::Denumerator* denumerator, const StdStrBuf& parent_bone, const StdStrBuf& child_bone, const StdMeshMatrix& transformation, uint32_t flags, bool own_child) { - std::auto_ptr auto_denumerator(denumerator); + std::unique_ptr auto_denumerator(denumerator); // We don't allow an instance to be attached to multiple parent instances for now if (instance.AttachParent) return NULL; diff --git a/src/lib/StdMesh.h b/src/lib/StdMesh.h index 9973d333b..ff2b55887 100644 --- a/src/lib/StdMesh.h +++ b/src/lib/StdMesh.h @@ -576,7 +576,7 @@ private: inline void CompileNewFuncCtx(StdMeshInstance::SerializableValueProvider *&pStruct, StdCompiler *pComp, const StdMeshInstance::SerializableValueProvider::IDBase& rID) { - std::auto_ptr temp(rID.newfunc()); + std::unique_ptr temp(rID.newfunc()); pComp->Value(*temp); pStruct = temp.release(); } diff --git a/src/lib/StdMeshLoaderBinary.cpp b/src/lib/StdMeshLoaderBinary.cpp index 218c92a0b..900200e2d 100644 --- a/src/lib/StdMeshLoaderBinary.cpp +++ b/src/lib/StdMeshLoaderBinary.cpp @@ -206,7 +206,7 @@ StdMesh *StdMeshLoader::LoadMeshBinary(const char *src, size_t length, const Std // Generate mesh from data Ogre::Mesh::ChunkMesh &cmesh = *static_cast(root.get()); - std::auto_ptr mesh(new StdMesh); + std::unique_ptr mesh(new StdMesh); mesh->BoundingBox = cmesh.bounds; mesh->BoundingRadius = cmesh.radius; @@ -298,7 +298,7 @@ void StdMeshLoader::LoadSkeletonBinary(StdMesh *mesh, const char *src, size_t si id = Ogre::Skeleton::Chunk::Peek(&stream) ) { - std::auto_ptr chunk(Ogre::Skeleton::Chunk::Read(&stream)); + std::unique_ptr chunk(Ogre::Skeleton::Chunk::Read(&stream)); switch (chunk->GetType()) { case Ogre::Skeleton::CID_BlendMode: diff --git a/src/lib/StdMeshLoaderBinaryChunks.cpp b/src/lib/StdMeshLoaderBinaryChunks.cpp index 526647a97..ffbb64d8f 100644 --- a/src/lib/StdMeshLoaderBinaryChunks.cpp +++ b/src/lib/StdMeshLoaderBinaryChunks.cpp @@ -55,7 +55,7 @@ namespace Ogre } // Create chunk - std::auto_ptr chunk; + std::unique_ptr chunk; switch (id) { case CID_Header: chunk.reset(new ChunkFileHeader()); break; @@ -361,7 +361,7 @@ namespace Ogre } // Create chunk - std::auto_ptr chunk; + std::unique_ptr chunk; switch (id) { case CID_Header: chunk.reset(new ChunkFileHeader()); break; diff --git a/src/lib/StdMeshLoaderXml.cpp b/src/lib/StdMeshLoaderXml.cpp index 4704a131a..84ac09919 100644 --- a/src/lib/StdMeshLoaderXml.cpp +++ b/src/lib/StdMeshLoaderXml.cpp @@ -244,7 +244,7 @@ StdMesh *StdMeshLoader::LoadMeshXml(const char* xml_data, size_t size, const Std { StdMeshXML xml(filename ? filename : "", xml_data); - std::auto_ptr mesh(new StdMesh); + std::unique_ptr mesh(new StdMesh); TiXmlElement* mesh_elem = xml.RequireFirstChild(NULL, "mesh"); diff --git a/src/lib/StdMeshMaterial.cpp b/src/lib/StdMeshMaterial.cpp index 7eba06bcf..f5a562f23 100644 --- a/src/lib/StdMeshMaterial.cpp +++ b/src/lib/StdMeshMaterial.cpp @@ -649,7 +649,7 @@ StdMeshMaterialTextureUnit::StdMeshMaterialTextureUnit(): void StdMeshMaterialTextureUnit::LoadTexture(StdMeshMaterialParserCtx& ctx, const char* texname) { - std::auto_ptr surface(ctx.TextureLoader.LoadTexture(texname)); // be exception-safe + std::unique_ptr surface(ctx.TextureLoader.LoadTexture(texname)); // be exception-safe if (!surface.get()) ctx.Error(StdCopyStrBuf("Could not load texture '") + texname + "'"); diff --git a/src/network/C4Network2UPnPLinux.cpp b/src/network/C4Network2UPnPLinux.cpp index ac2d1c9a7..4e5f5aa0f 100644 --- a/src/network/C4Network2UPnPLinux.cpp +++ b/src/network/C4Network2UPnPLinux.cpp @@ -242,7 +242,7 @@ int C4Network2UPnPP::Callback_Static(Upnp_EventType EventType, void* Event, void break; case UPNP_CONTROL_ACTION_COMPLETE: { - std::auto_ptr data(static_cast(Cookie)); + std::unique_ptr data(static_cast(Cookie)); Upnp_Action_Complete* complete = static_cast(Event); std::string action = ixmlNode_getNodeName(ixmlNode_getFirstChild(&complete->ActionRequest->n)); Application.InteractiveThread.PushEvent(Ev_UPNP_Response, new NotifyActionComplete(*data, action, complete->ErrCode)); @@ -258,7 +258,7 @@ int C4Network2UPnPP::Callback_Static(Upnp_EventType EventType, void* Event, void void C4Network2UPnPP::OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData) { - std::auto_ptr notify(static_cast(pEventData)); + std::unique_ptr notify(static_cast(pEventData)); // TODO: Should call a virtual method instead of dynamic_casting NotifySearchResult* notify_search_result = dynamic_cast(notify.get()); diff --git a/src/object/C4DefGraphics.cpp b/src/object/C4DefGraphics.cpp index e1651c898..31ea34063 100644 --- a/src/object/C4DefGraphics.cpp +++ b/src/object/C4DefGraphics.cpp @@ -325,7 +325,7 @@ void C4DefGraphics::Draw(C4Facet &cgo, DWORD iColor, C4Object *pObj, int32_t iPh break; case C4DefGraphics::TYPE_Mesh: // TODO: Allow rendering of a mesh directly, without instance (to render pose; no animation) - std::auto_ptr dummy; + std::unique_ptr dummy; StdMeshInstance* instance; C4Value value; diff --git a/src/script/C4PropList.cpp b/src/script/C4PropList.cpp index 41606c78b..91a20795f 100644 --- a/src/script/C4PropList.cpp +++ b/src/script/C4PropList.cpp @@ -251,7 +251,7 @@ void C4PropList::CompileFunc(StdCompiler *pComp, C4ValueNumbers * numbers) void CompileNewFunc(C4PropList *&pStruct, StdCompiler *pComp, C4ValueNumbers * const & rPar) { - std::auto_ptr temp(C4PropList::New()); // exception-safety + std::unique_ptr temp(C4PropList::New()); // exception-safety pComp->Value(mkParAdapt(*temp, rPar)); pStruct = temp.release(); }