# HG changeset patch # User rubidium # Date 2009-11-11 21:15:58 # Node ID 8be3f02950fd67822011b658eee18a46d12a3f79 # Parent 26965d463394a3268e056635c319a3c78ce01f01 (svn r18045) -Fix: GCC 4.5@HEAD not compiling OpenTTD anymore because of a "non-placement deallocation function [is] selected for placement delete", or in other words delete(void *, size_t) is 'magic'. We implemented these delete(void *, size_t) operator functions because MSVC warned that "no matching operator delete found; memory will not be freed if initialization throws an exception" for new(size_t, size_t). This disables MSVC warning about this because we do not use exceptions in the (constructors that use the) overridden allocation functions, as such they will never be called; delete(void *) remains necessary though. diff --git a/src/core/pool_type.hpp b/src/core/pool_type.hpp --- a/src/core/pool_type.hpp +++ b/src/core/pool_type.hpp @@ -119,20 +119,6 @@ struct Pool { } /** - * Deletes item with given index. - * @param p Titem memory to release - * @param index index of item - * @note never use this! Only for internal use - * (called automatically when constructor of Titem uses throw()) - */ - FORCEINLINE void operator delete(void *p, size_t index) - { - assert(p == Tpool->Get(index)); - Tpool->FreeItem(index); - } - - - /** * Allocates space for new Titem at given memory address * @param size size of Titem * @param ptr where are we allocating the item? @@ -154,21 +140,6 @@ struct Pool { return ptr; } - /** - * Deletes item that was allocated by the function above - * @param p Titem memory to release - * @param ptr parameter given to operator new - * @note never use this! Only for internal use - * (called automatically when constructor of Titem uses throw()) - */ - FORCEINLINE void operator delete(void *p, void *ptr) - { - assert(p == ptr); - for (size_t i = 0; i < Tpool->first_unused; i++) { - assert(ptr != Tpool->data[i]); - } - } - /** Helper functions so we can use PoolItem::Function() instead of _poolitem_pool.Function() */ diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -125,24 +125,39 @@ public: return new (strlen(text) + 1) GRFText(langid, text); } + /** + * Helper allocation function to disallow something. + * Don't allow simple 'news'; they wouldn't have enough memory. + * @param size the amount of space not to allocate + */ + void *operator new(size_t size) + { + NOT_REACHED(); + } + + /** + * Free the memory we allocated + * @param p memory to free + */ + void operator delete(void *p) + { + free(p); + } private: GRFText(byte langid_, const char *text_) : next(NULL), langid(langid_) { strcpy(text, text_); } + /** + * Allocate memory for this class. + * @param size the size of the instance + * @param extra the extra memory for the text + * @return the requested amount of memory for both the instance and the text + */ void *operator new(size_t size, size_t extra) { - return ::operator new(size + extra); - } - -public: - /* dummy operator delete to silence VC8: - * 'void *GRFText::operator new(size_t,size_t)' : no matching operator delete found; - * memory will not be freed if initialization throws an exception */ - void operator delete(void *p, size_t extra) - { - return ::operator delete(p); + return MallocT(size + extra); } public: diff --git a/src/stdafx.h b/src/stdafx.h --- a/src/stdafx.h +++ b/src/stdafx.h @@ -162,6 +162,7 @@ #if (_MSC_VER < 1400) // MSVC 2005 safety checks #error "Only MSVC 2005 or higher are supported. MSVC 2003 and earlier are not! Upgrade your compiler." #endif /* (_MSC_VER < 1400) */ + #pragma warning(disable: 4291) // no matching operator delete found; memory will not be freed if initialization throws an exception (reason: our overloaded functions never throw an exception) #pragma warning(disable: 4996) // 'strdup' was declared deprecated #define _CRT_SECURE_NO_DEPRECATE // all deprecated 'unsafe string functions #pragma warning(disable: 6308) // code analyzer: 'realloc' might return null pointer: assigning null pointer to 't_ptr', which is passed as an argument to 'realloc', will cause the original memory block to be leaked diff --git a/src/window_gui.h b/src/window_gui.h --- a/src/window_gui.h +++ b/src/window_gui.h @@ -345,11 +345,26 @@ public: Window(); virtual ~Window(); - /* Don't allow arrays; arrays of Windows are pointless as you need - * to destruct them all at the same time too, which is kinda hard. */ - FORCEINLINE void *operator new[](size_t size) { NOT_REACHED(); } - /* Don't free the window directly; it corrupts the linked list when iterating */ - FORCEINLINE void operator delete(void *ptr) {} + + /** + * Helper allocation function to disallow something. + * Don't allow arrays; arrays of Windows are pointless as you need + * to destruct them all at the same time too, which is kinda hard. + * @param size the amount of space not to allocate + */ + FORCEINLINE void *operator new[](size_t size) + { + NOT_REACHED(); + } + + /** + * Helper allocation function to disallow something. + * Don't free the window directly; it corrupts the linked list when iterating + * @param ptr the pointer not to free + */ + FORCEINLINE void operator delete(void *ptr) + { + } uint16 flags4; ///< Window flags, @see WindowFlags WindowClass window_class; ///< Window class