From: Ivan Maidanski Date: Thu, 30 Aug 2012 04:52:13 +0000 (+0400) Subject: Eliminate 'missing exception specification' warning in gc_cpp.cc (Clang) X-Git-Tag: gc7_4_0~224 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0ac46cc66eb2367c321362f32f63aa95f01d97f5;p=platform%2Fupstream%2Flibgc.git Eliminate 'missing exception specification' warning in gc_cpp.cc (Clang) * gc_cpp.cc (GC_NEW_DELETE_NEED_THROW): Define new macro (if not defined yet) for GCC v4.2+ (or clang). * gc_cpp.cc: Include new (for std::bad_alloc) if GC_NEW_DELETE_NEED_THROW. * gc_cpp.cc (GC_DECL_NEW_THROW, GC_DECL_DELETE_THROW): New macros (used to eliminate compiler "missing exception specification" warning for 'new' and 'delete' operators). * gc_cpp.cc (new, delete, new[], delete[]): Use GC_DECL_NEW/DELETE_THROW to define 'throw' clause properly. --- diff --git a/gc_cpp.cc b/gc_cpp.cc index 86792b0..9f64b74 100644 --- a/gc_cpp.cc +++ b/gc_cpp.cc @@ -29,22 +29,36 @@ built-in "new" and "delete". #include "gc_cpp.h" -void* operator new( size_t size ) { +#if !defined(GC_NEW_DELETE_NEED_THROW) && defined(__GNUC__) \ + && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)) +# define GC_NEW_DELETE_NEED_THROW +#endif + +#ifdef GC_NEW_DELETE_NEED_THROW +# include /* for std::bad_alloc */ +# define GC_DECL_NEW_THROW throw(std::bad_alloc) +# define GC_DECL_DELETE_THROW throw() +#else +# define GC_DECL_NEW_THROW /* empty */ +# define GC_DECL_DELETE_THROW /* empty */ +#endif /* !GC_NEW_DELETE_NEED_THROW */ + +void* operator new( size_t size ) GC_DECL_NEW_THROW { return GC_MALLOC_UNCOLLECTABLE(size); } #if !defined(__CYGWIN__) - void operator delete( void* obj ) { + void operator delete( void* obj ) GC_DECL_DELETE_THROW { GC_FREE(obj); } #endif /* !__CYGWIN__ */ #ifdef GC_OPERATOR_NEW_ARRAY - void* operator new[]( size_t size ) { + void* operator new[]( size_t size ) GC_DECL_NEW_THROW { return GC_MALLOC_UNCOLLECTABLE(size); } - void operator delete[]( void* obj ) { + void operator delete[]( void* obj ) GC_DECL_DELETE_THROW { GC_FREE(obj); } #endif /* GC_OPERATOR_NEW_ARRAY */ @@ -53,7 +67,7 @@ void* operator new( size_t size ) { // This new operator is used by VC++ in case of Debug builds! void* operator new( size_t size, int /* nBlockUse */, - const char * szFileName, int nLine ) + const char * szFileName, int nLine ) GC_DECL_NEW_THROW { # ifndef GC_DEBUG return GC_malloc_uncollectable(size); @@ -65,7 +79,7 @@ void* operator new( size_t size ) { # if _MSC_VER > 1020 // This new operator is used by VC++ 7.0 and later in Debug builds. void* operator new[]( size_t size, int nBlockUse, - const char* szFileName, int nLine ) + const char* szFileName, int nLine ) GC_DECL_NEW_THROW { return operator new(size, nBlockUse, szFileName, nLine); }